Page 1 of 1

Problem with boot code

Posted: Fri Jan 23, 2009 10:55 pm
by abachler
The boot code is copying the image to the hard drive as expected, but it copies it to LBA 54, rather than LBA 0 as I was expecting. Since I only use the LBA packet when I write, I dont think it is becoming corrupted, and it is otherwise doign the copy correctly. here is teh code

Code: Select all

; HiP-OS Bootstrap by Anthony Q. Bachler copyright 2009, released under the GPL v3

section .text 

[bits 16]
	jmp 0x07c0:start
start:
	mov WORD [transfer_size] , 0x0080	; set transfer size
	
	mov ax , 0x07c0
	mov ds , ax
	
	mov ax , 0x2000					; set up the stack
	mov ss , ax						
	mov sp , 0xfffc
	
	mov [boot_drive] , dl			; save the boot drive info
	cmp dl , 0x7f					; is it floppy?
	jle floppy_handler
	mov ah , 0x42					; function 0x42
	mov si , packet					; pointer to predefined packet
	int 0x13						; int 0x13 / 0x42 EXTENDED READ
	jnc continue
	
floppy_handler:
	; reset the floppy
	mov ah , 0x00
	int 0x13
	
	; copy 32k image into memory
	mov ax , 0x1000
	mov es , ax
	xor bx , bx
	mov cx , 0x0001
	mov dh , 0x00
	mov ax , 0x0240
	int 0x13
	jc  floppy_handler
	
	; copy the 32k image to the hard drive
	mov ax , packet
	mov si , ax
	mov ax , 0x4301
	mov dl , 0x80
	int 0x13
	
	;hlt
	jmp 0xffff:0x0000				; reset the system
	
	

continue:	
	mov ax , 0x1000
	mov ds , ax
	mov dl , [boot_drive]
	mov [ds:boot_drive] , dl
	jmp 0x1000:loaded
	
loaded:
	mov ax , 0xb000
	mov es , ax
	mov ax , 0x4100
	mov [es:0x0000] , ax
	
	hlt
	
	
	
	




installer_check	db 0xff								; set to 0xff for the install disk 0x00 otherwise
boot_drive		db 0x00								; the drive number this booted from

packet			db 0x10								; size of packet	
				db 0x00								; reserved
transfer_size	dw 0x0040							; number of blocks to transfer - 64 = 32k
transfer_buffer	dw 0x1000 , 0x0000					; destination buffer
block_start		db 0x00 , 0x00 , 0x00 , 0x00		; LBA block to load
				db 0x00 , 0x00 , 0x00 , 0x00
				


				times 446-($-$$) db 0
boot_indicator	db 0x80 
starting_head	db 0x00 
start_sector	db 0x01 
start_cylinder	db 0x00 
system_id		db 0x7f
end_head		db 0x01
end_sector		db 0x12
end_cylinder	db 0x4f
relative_sector	db 0x01 , 0x00 , 0x00 , 0x00
total_sectors	db 0x40 , 0x0b , 0x00 , 0x00 
	
	times 48 db 0
	
	db 0x55
	db 0xAA
	times 1474560-($-$$) db 0
   
section .data 

    ; put data items here

	
section .bss 

        ; put uninitialised data here

and I attached the images of the floppy and the hard drive. Warning, run it in an emulator, the floppy doesnt prompt you for verification when it writes to the hard drive yet, it just does it.

Re: Problem with boot code

Posted: Sat Jan 24, 2009 3:58 am
by djmauretto
You must set DS before to copy 0x0080 to memory location [Transfer_size]

Code: Select all

start:
   mov WORD [transfer_size] , 0x0080   ; set transfer size
   
   mov ax , 0x07c0
   mov ds , ax

Code: Select all

transfer_buffer   dw 0x1000 , 0x0000               ; destination buffer
Did you mean :

Code: Select all

transfer_buffer   dw 0x0000 , 0x1000               ; destination buffer
Little Indian Please :wink:

Re: Problem with boot code

Posted: Sat Jan 24, 2009 6:46 am
by abachler
djmauretto wrote:You must set DS before to copy 0x0080 to memory location [Transfer_size]

Code: Select all

start:
   mov WORD [transfer_size] , 0x0080   ; set transfer size
   
   mov ax , 0x07c0
   mov ds , ax
<foreheadsmack>

Code: Select all

transfer_buffer   dw 0x1000 , 0x0000               ; destination buffer
Did you mean :

Code: Select all

transfer_buffer   dw 0x0000 , 0x1000               ; destination buffer
Little Indian Please :wink:
hmm, I guess I assumed it was in segment:offset order, does INT 0x13h/0x42h take an absolute address?

<edit>

Yep that fixed it, thank you :) Ill make a note that its offset:segment order.

Re: Problem with boot code

Posted: Sat Jan 24, 2009 7:25 am
by Love4Boobies
abachler wrote:hmm, I guess I assumed it was in segment:offset order, does INT 0x13h/0x42h take an absolute address?
It is, therefore, the segment gets popped first.