http://www.koders.com/c/fid974AC861F70F340977C6516BAD1DE02BBD9B48DC.aspx?s=bios32+

1 view
Skip to first unread message

my12...@gmail.com

unread,
Oct 28, 2005, 1:53:28 AM10/28/05
to java home
section .text
global raw_write

;; Calling format:
;; void raw_write (u8 *buf, u32 off, u32 drive, u8 sector)
raw_write:
push ebp
mov ebp, esp
push ebx
push esi

mov ebx, [ebp+16] ; al will be written to 1F6
and ebx, 0x1
shl ebx, 0x4
or ebx, 0x40

mov dx, 0x1F2 ; get sector number
mov al, 1
out dx, al

mov eax, [ebp+12] ; eax = offset
inc dx
out dx, al ; LBA low
shr eax, 8
inc dx
out dx, al ; LBA mid
shr eax, 8
inc dx
out dx, al ; LBA high
shr eax, 8
and eax, 0xF
; or al, bl
or al, 0xE0
mov dx, 0x1F6
out dx, al ; bl calculated above, plus LBA veryhigh

mov al, 0x30 ; WRITE
inc dx
out dx, al

.chkstat:
mov ecx, 1000000 ; Timeout of about one second (I/O usually takes one
usec)
in al, dx ; Status
and al, 0x88
jz .return
cmp al, 0x80
jnz .next
loop .chkstat

;; print a message saying we timed out
jmp .return

.next:
mov dx, 0x1F0
mov ecx, 256 ; write 256 * number of sectors words
mov esi, [ebp + 8] ; buffer pointer
rep outsw

;; print a message saying we're done

.return:
pop esi
pop ebx
mov esp, ebp
pop ebp
ret

global raw_read

;; Calling format:
;; void raw_read (u8 *buf, u32 off, u32 drive)
raw_read:
push ebp
mov ebp, esp
push ebx
push edi

mov ebx, [ebp+16] ; al will be written to 1F6
and ebx, 0x1
shl ebx, 0x4
or ebx, 0x40

mov dx, 0x1F2 ; get sector number
mov al, 1
out dx, al

mov eax, [ebp+12] ; eax = offset
inc dx
out dx, al ; LBA low
shr eax, 8
inc dx
out dx, al ; LBA mid
shr eax, 8
inc dx
out dx, al ; LBA high
shr eax, 8
and eax, 0xF
; or al, bl
or al, 0xE0
mov dx, 0x1F6
out dx, al ; bl calculated above, plus LBA veryhigh

mov al, 0x20 ; READ
inc dx
out dx, al

.chkstat:
mov ecx, 1000000 ; Timeout of about one second (I/O usually takes one
usec)
in al, dx ; Status
and al, 0x88
jz .return
cmp al, 0x80
jnz .next
loop .chkstat

;; print a message saying we timed out
jmp .return

.next:
mov dx, 0x1f0
mov ecx, 256 ; read 256 * number of sectors words
mov edi, [ebp + 8] ; buffer pointer
rep insw

;; print a message saying we're done

.return:
pop edi
pop ebx
mov esp, ebp
pop ebp
ret

my12...@gmail.com

unread,
Oct 30, 2005, 4:52:13 AM10/30/05
to java home

my12...@gmail.com

unread,
Oct 30, 2005, 5:02:08 AM10/30/05
to java home
Reply all
Reply to author
Forward
0 new messages