ATA reading stuff '-'

This commit is contained in:
Adrien Bourmault 2019-01-15 12:28:53 +01:00
parent 35c71e4b24
commit bf6e59eb06
5 changed files with 137 additions and 2 deletions

View File

@ -264,7 +264,7 @@ main32:
Init db "Booting OS/K !", 0x0D, 0x0A, 0x0D, 0x0A, 0x09, " Checking CPUID...",0
CPUIDD db 0x09, " Checking CPUID...", 0
EnA20 db 0x09, " Enabling A20 line...", 0
KernSearch db 0x09, " Loading the Kernel in RAM...", 0
ReadAttempt db 0x09, " Attempt to read a sector with ATA commands...", 0x0A, 0x0D, 0x0A, 0x0D,0
txt db 0x09, " Switching to Long Mode... ", 0
Reinit db "Booting OS/K !", 0x0D, 0x0A, 0x0D, 0x0A, 0
Pass db " OK", 0x0A, 0x0D, 0
@ -337,6 +337,18 @@ main64:
mov esi, msg
call write
mov bl, 0x0F
mov esi, ReadAttempt
call write
mov rcx, 2
.looping:
nop
nop
nop
loop .looping ; Temporized because the ATA drive must be ready
call ata_read
jmp Die

View File

@ -71,6 +71,129 @@ write:
pop rax
jmp .pLoop
.scroll:
; XXX ;
; XXX I don't think I'll implement this, but never know...;
jmp .pLoop
dump:
;-----------------------------------------------------------------------;
; x64/LM Dump Printing Functions ;
; bl : color code ;
; esi : string address ;
;-----------------------------------------------------------------------;
mov edi, [NextTRAM] ; TRAM ADDRESS
push rsi
push rdi
push rcx
mov rcx, 512
.pLoop:
lodsb
stosb ; text subpixel
mov al, bl
stosb ; color subpixel
add qword [NextTRAM], 0x2 ; Cursor moving
add qword [VGA_X], 0x2 ; coord + 2 because 2 subpixels
loop .pLoop
pop rcx
pop rdi
pop rsi
ret
ata_read:
;-----------------------------------------------------------------------;
; x64/LM ATA Reading function ;
; ;
; ;
;-----------------------------------------------------------------------;
; Technical infos about the ports (Intel Doc):
;
; Port Access Mode Misc
;
; 1f0 r/w Data register, the bytes of the disk itself
; 1f1 r Error register that can be handled
; 1f2 r/w Sector count, how many sectors to read
; 1f3 r/w Sector number, the actual sector wanted
; 1f4 r/w Cylinder low, cylinders is 0-1024
; 1f5 r/w Cylinder high, this makes up the rest of the 1024
; 1f6 r/w Drive/head
; bit 7 = 1
; bit 6 = 0
; bit 5 = 1
; bit 4 = 0 drive 0 select
; = 1 drive 1 select
; bit 3-0 head select bits
; 1f7 r Status register
; bit 7 = 1 controller is executing a command
; bit 6 = 1 drive is ready
; bit 5 = 1 write fault
; bit 4 = 1 seek complete
; bit 3 = 1 sector buffer requires servicing
; bit 2 = 1 disk data read corrected
; bit 1 = 1 index - set to 1 each revolution
; bit 0 = 1 previous command ended in an error
; 1f7 w Command register
; commands:
; 50h format track
; 20h read sectors with retry
; 21h read sectors without retry
; 22h read long with retry
; 23h read long without retry
; 30h write sectors with retry
; 31h write sectors without retry
; 32h write long with retry
; 33h write long without retry
;
push rax
push rbx
push rdx
push rcx
push rdi
mov dx,1f6h ;Drive and head port
mov al,0a0h ;Drive 0, head 0
out dx,al
mov dx,1f2h ;Sector count port
mov al,1 ;Read one sector
out dx,al
mov dx,1f3h ;Sector number port
mov al,1 ;Read sector one
out dx,al
mov dx,1f4h ;Cylinder low port
mov al,0 ;Cylinder 0
out dx,al
mov dx,1f5h ;Cylinder high port
mov al,0 ;The rest of the cylinder 0
out dx,al
mov dx,1f7h ;Command port
mov al,20h ;Read with retry.
out dx,al
still_going:
in al,dx
test al,8 ;This means the sector buffer requires
;servicing.
jz still_going ;Don't continue until the sector buffer
;is ready.
mov cx,512/2 ;One sector /2
mov rdi,buffer
mov dx,1f0h ;Data port - data comes in and out of here.
rep insw
pop rdi
pop rcx
pop rdx
pop rbx
pop rax
mov bl, 0x0F
mov esi, buffer
call dump
mov bl, 0x0A
mov esi, end
call write
ret
buffer: times 512 db "_"
end: db "[End of Sector]", 0x0

Binary file not shown.

Binary file not shown.

Binary file not shown.