still working on ata :(

This commit is contained in:
2026-06-21 16:57:16 -05:00
parent 0f84acde30
commit a82a7aa1a4
5 changed files with 353 additions and 28 deletions

View File

@@ -2,18 +2,15 @@
.code32
.extern selected_drive_primary
.extern selected_drive_secondary
.global ident_device
ident_device:
push %ebp
mov %esp, %ebp
push %ebx
push %ecx
push %edx
push $0
push %esi
push %edi
push $0
mov 8(%ebp), %ebx # ebx = bus base address
mov 12(%ebp), %ecx # ecx = drive select mask
@@ -24,6 +21,12 @@ ident_device:
mov %cl, %al
outb %al, (%dx)
mov %ebx, %edx
add $IO_STATUS_REG, %edx
.rept 15
inb (%dx), %al
.endr
xor %eax, %eax
# clear sector count and LBA
mov %ebx, %edx
@@ -65,6 +68,7 @@ poll_status:
test $STATUS_REG_BSY, %al
jnz poll_status
# first check if this is an ATA device
check_ata:
mov %ebx, %edx
add $IO_LBA_MID_REG, %edx
@@ -77,7 +81,7 @@ check_ata:
inb (%dx), %al
test %al, %al
jnz check_atapi
is_ata:
mov $0x01, (%esp)
jmp poll_drq
@@ -118,6 +122,9 @@ poll_drq:
add $IO_STATUS_REG, %edx
inb (%dx), %al
test $STATUS_REG_BSY, %al
jnz poll_drq
test $STATUS_REG_ERR, %al
jnz error
@@ -130,12 +137,12 @@ drq_set:
mov 16(%ebp), %edi
mov $256, %ecx
cld
read_data:
inw (%dx), %ax
mov %ax, (%edi)
add $2, %edi
loop read_data
jmp done
not_found:
@@ -143,8 +150,78 @@ error:
mov $0x0, (%esp)
done:
pop %eax
pop %edx
pop %ecx
pop %edi
pop %esi
pop %ebx
leave
ret
.global atapi_wait
atapi_wait:
push %ebp
mov %esp, %ebp
# 8(%ebp) bus
mov 8(%ebp), %edx
add $IO_STATUS_REG, %edx
inb (%dx), %al
inb (%dx), %al
inb (%dx), %al
inb (%dx), %al
pop %edx
leave
ret
.global send_scsi_packet
send_scsi_packet:
push %ebp
mov %esp, %ebp
push %esi
push %ecx
push %edx
# 8(%ebp) bus
# 12(%ebp) cmd
# 16(%ebp) sz
mov 8(%ebp), %edx
add $IO_DATA_REG, %edx
mov 12(%ebp), %esi
mov 16(%ebp), %ecx
cld
rep outsw
pop %edx
pop %ecx
pop %esi
leave
ret
.global read_data_words
read_data_words:
push %ebp
mov %esp, %ebp
push %edi
push %ecx
push %edx
# 8(%ebp) bus
# 12(%ebp) buf
# 16(%ebp) sz
mov 8(%ebp), %edx
add $IO_DATA_REG, %edx
mov 12(%ebp), %edi
mov 16(%ebp), %ecx
cld
rep insw
pop %edx
pop %ecx
pop %edi
leave
ret