Page 1 of 1

BIOS HDD write not working (help)

Posted: Sat May 05, 2007 12:02 pm
by R2_
Why doesn't this piece of code work ?

Code: Select all

 install:
  mov si, yes
  call print
  mov ah, 0Bh
  mov AL, 01h
  mov ch, 01h
  mov cl, 02h
  mov dh, 00h
  mov dl, 80h
  mov bx, 6Eh
  mov es, bx
  int 0x13
  jmp $
Im trying to write 6Eh to the hard drive using the BIOS function
AH = 0Bh
AL = number of sectors (01h may be only value supported)
CH = low eight bits of cylinder number
CL = sector number (bits 5-0)
high two bits of cylinder number (bits 7-6)
DH = head number
DL = drive number (80h = first, 81h = second)
ES:BX -> data buffer

I've tried
AH = 03h
AL = number of sectors to write (must be nonzero)
CH = low eight bits of cylinder number
CL = sector number 1-63 (bits 0-5)
high two bits of cylinder (bits 6-7, hard disk only)
DH = head number
DL = drive number (bit 7 set for hard disk)
ES:BX -> data buffer

but when I set the drive number to something other than the floppy drive it doesn't work

any help will be greatly appreciated.

Edit: I got it to work with write disk sectors function... However it doesnt write the byte i specified on BX. I know it accessed the hard drive because my VM tells me but I need to know how to specify that ES:BX so I can tell it what to write.

Posted: Sat May 05, 2007 1:00 pm
by frank
ES:BX points to the location in memory that will be written to the hard disk. Are you sure you are putting data in the location specified by ES:BX?

Posted: Sat May 05, 2007 1:06 pm
by R2_
i tried passing bx a name variable which to my understanding points to a place in memory and that didn't work

Code: Select all

 install:
  mov si, yes
  call print
  mov ah, 03h
  mov AL, 01h
  mov ch, 01h
  mov cl, 02h
  mov dh, 00h
  mov dl, 80h
  mov bx, message
  mov es, bx
  int 0x13
  jmp $
the variable message is defined in my actual file.

Posted: Sat May 05, 2007 1:28 pm
by xsix
No no. ES is segment, and BX is offset here. you're putting your message's offset into segment register(ES). Do this "MOV ES, DS", cause message is stored as data in memory, and for data accesses DS is used

Posted: Sat May 05, 2007 2:11 pm
by R2_
when i do mov es, ds it tells me "/Users/HD/Desktop/boot2.asm:58: error: invalid combination of opcode and operands"
As you can see im just barely learning assembly =p

Code: Select all

 install:
  mov si, yes
  call print
  mov ah, 03h
  mov AL, 01h
  mov ch, 01h
  mov cl, 02h
  mov dh, 00h
  mov dl, 80h
  mov bx, message
  mov es, ds
  int 0x13
  jmp $

Posted: Sat May 05, 2007 2:16 pm
by xsix
****. sorry. MOV AX, DS and then MOV ES, AX . Dummy me =\

Posted: Sat May 05, 2007 3:32 pm
by R2_
for some weird reason now that doesn't even show that its attempting to access the HDD nor its writing the data in message or anything at all to sector 2

Code: Select all

[BITS 16]
[ORG 0x7C00]
main:
 
 mov si, message
 call print
 mov si, version
 call print
 mov si, boot
 call print
 call keypress_wait
 call putchar
 jmp $


putchar: 
mov cx, 1
mov ah, 0Ah
mov bh, 00h
mov bl, 0x07
int 0x10
cmp al, 79h
je install
cmp al, 6Eh
je cancel
jne error
ret

print:
 mov ah,0x0E
 mov bh,0x00
 mov bl,0x07
 .continue
 lodsb
 or al,al
 jz .finish	
 int 0x10	
 jmp .continue
 .finish
 ret
 
 keypress_wait:
 mov ah, 00h
 int 0x16
 ret
 
 install:
  mov si, yes
  call print
  mov ah, 03h
  mov AL, 01h
  mov ch, 01h
  mov cl, 02h
  mov dh, 00h
  mov dl, 80h
  mov bx, message
  mov ax, ds
  mov es, ax
  int 0x13
  jmp $
  
  error:
  mov si, error201
  call print
  
  ok:
  mov si, okk
  call print
  
  cancel:
   mov si, no
  call print
 
message db 'Welcome to the Xtreme Operating System (XOS)',13,10,0
version db 'Version: b0.01 - build 1 - build 05/05/07',13,10,0
boot db 'Do you want to start the installation now ? (Y/N)',13,10,0
yes db 'Installing...',13,10,0
error201 db 'keypress_error201: You entered an invalid value. Please restart and try again.',13,10,0
no db 'Installation cancelled', 13, 10, 0
okk db 'yup',13,10,0
times 510-($-$$) db 0
dw 0xAA55
Thanks for all the people who have tried to help so far really appreciate it =p This code is just to what will eventually become a bootloader to my OS... Im just attempting to write to HDD so I can write the OS and loader there.

Posted: Sun May 06, 2007 2:34 pm
by R2_
Anyone have any idea of whats wrong ?