HDINT = 3
.global ReadPSector
.global WritePSector
#===========================================================
# %rdi = address to load to
# %esi = sector number
#===========================================================
HD_PORT=0x1F0
ReadPSector:
mov $HD_PORT+7, %dx
.again2:
in %dx, %al
test $0x80, %al
jnz .again2
mov $HD_PORT+2, %dx # 0x1F2 - sector count
mov $1, %al
out %al, %dx
inc %dx # 0x1F3
mov %esi, %eax
and $0xFF, %al
out %al, %dx # lba lo
inc %dx # 0x1F4
mov %esi, %eax
and $0xFF, %ah
mov %ah, %al
out %al, %dx # lba mid
inc %dx # 0x1F5
mov %esi, %eax
shr $16, %eax
and $0xFF, %al
out %al, %dx # lba hi
inc %dx # 0x1F6
and $0xF, %ah
mov %ah, %al
add $0x40, %al # lba mode/drive /lba top
out %al, %dx
inc %dx # 0x1F7
mov $0x20, %ax # HDC_READ
out %al, %dx
.again3:
in %dx, %al
test $0x80, %al
jnz .again3
mov $HD_PORT, %dx
mov $0, %eax
mov $256, %rcx
cld
rep
insw
ret
WritePSector:
mov $HD_PORT+7, %dx
.again4:
in %dx, %al
test $0x80, %al
jnz .again4
mov $HD_PORT+2, %dx # 0x1F2 - sector count
mov $1, %al
out %al, %dx
inc %dx # 0x1F3
mov %esi, %eax
and $0xFF, %al
out %al, %dx # lba lo
inc %dx # 0x1F4
mov %esi, %eax
and $0xFF, %ah
mov %ah, %al
out %al, %dx # lba mid
inc %dx # 0x1F5
mov %esi, %eax
shr $16, %eax
and $0xFF, %al
out %al, %dx # lba hi
inc %dx # 0x1F6
and $0xF, %ah
mov %ah, %al
add $0x40, %al # lba mode/drive /lba top
out %al, %dx
inc %dx # 0x1F7
mov $0x30, %ax # HDC_WRITE
out %al, %dx
.again5:
in %dx, %al
test $0x80, %al
jnz .again5
mov $HD_PORT, %dx
mov $0, %eax
mov $256, %rcx
mov %rdi, %rsi
cld
rep
outsw
ret