No emulation CD bootloader

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
metallevel
Posts: 18
Joined: Thu May 17, 2012 12:43 pm
Location: in front of a computer

No emulation CD bootloader

Post by metallevel »

Sorry if this has been asked a dozen times, but I couldn't find quite what I needed by searching.

Anyway, I'm writing a no-emulation El-Torito bootloader and while it boots as expected, I can't seem to load additional sectors. I've tried (in Bochs) different variations of the Int 13h extensions and the (perhaps non-standard) Int 2Fh CD-ROM commands. The carry flag is never set afterward, and there is every indication that the operation was successful, except that the data isn't loaded. I've tried waiting a few seconds for the virtual read to take place, but still nothing.


I know you want code, so here it is ATM:

Code: Select all

[ORG 0x7C00]
use16

;I just like 0:7C00 more than 7C0:0
jmp word 0:DEFINED_ADDRESS

DEFINED_ADDRESS:	
	
	;zero registers & save boot drive number
	xor ax,ax
	mov ds,ax
	mov ss,ax
	mov es,ax
	
	mov [boot_drv],dl
	
	xor bx,bx
	xor cx,cx
	xor dx,dx
	xor si,si
	xor di,di
	xor bp,bp
	
	;clear screen
		mov ah,0Fh
	int 10h
		
		mov ah,0
	int 10h
	
	;set sp & test for old machine (sp method)
		mov sp,0x600
		push sp
		pop sp
		cmp sp,0x600
	jne pre_268
	
	;test for old machine (invalid opcode method)
	cli
		mov word[ds:(6*4)  ],pre_386		;Offset
		mov word[ds:(6*4)+2],0				;Segment
	sti
	
	xor eax,eax
	
	;output: cpu is good
		mov di,cpu_good
	call print
	
	;A20 enable
	call test_A20
	jnc A20_good
	
		mov ax,0x2401
	int 15h
	cmp ah,0
	je A20_good
	
	call enable_A20	
	
	call test_A20
	jnc A20_good
	
	call A20_FAIL
	A20_good:
	
	;read CD volume descriptors (incomplete)
	mov [0x600],byte 10h
	mov [0x601],byte 0
	mov [0x602],word 1
	mov [0x604],word 0
	mov [0x606],word 0x500
	mov [0x608],dword 10h
	mov [0x60C],dword 0
	
		mov ah,42h
		mov dl,[boot_drv]
		mov si,0x600
	int 13h
	
jmp $



;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;fatal error
A20_FAIL:
		mov di,a20_failed
	call print
jmp $



;from OS Dev site
;consumes: al
enable_A20:
	cli
 
	call .a20wait
	
		mov al,0xAD
	out 0x64,al
	call .a20wait
	
		mov al,0xD0
	out 0x64,al
	call .a20wait2
	
	in al,0x60
	push ax
	call .a20wait
	
		mov al,0xD1
	out 0x64,al
	call .a20wait
	
		pop ax
		or al,2
	out 0x60,al
	call .a20wait
	
		mov al,0xAE
	out 0x64,al
	call .a20wait
	
	sti
ret
	
	.a20wait:
		in al,0x64
		test al,2
	jnz .a20wait
	ret

	.a20wait2:
		in al,0x64
		test al,1
	jz .a20wait2
	ret



;consumes: ax, bx, [0x7C00]
test_A20:
	mov bx,0xFFFF
	mov es,bx
	mov ax,[ds:0x7C00]
	mov bx,[es:0x7C10]
	
		cmp ax,bx
	jne .enabled
	
	xor [ds:0x7C00],word 0xFFFF
	
	mov ax,[ds:0x7C00]
	mov bx,[es:0x7C10]
	
		cmp ax,bx
	jne .enabled
	
	stc
ret

	.enabled:
		clc
	ret



;called if old machine is detected
pre_268:
pre_386:
		mov di,cpu_bad
	call print
jmp $



;di=string
;consumes: ax, di
print:
	.loop1:
		mov al,[di]
		cmp al,0
		je .break1
		mov ah,0Eh
		int 10h
		inc di
	jmp .loop1
	.break1:
ret



cpu_good:	db	'Supported CPU',13,10,0
cpu_bad:	db	'Unsupported CPU',0
a20_failed:	db	"A20 line couldn't be enabled",0

boot_drv:	db	0
Last edited by JamesM on Sat Aug 11, 2012 3:02 pm, edited 1 time in total.
Reason: "BL" -> "Bootloader". That's not a well-known abbreviation.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: No emulation CD bootloader

Post by JamesM »

Just to clarify: we generally want relevant, debugged code that relates in some way to the problem. Not a code dump of the entire file in which the problem occurs.
metallevel
Posts: 18
Joined: Thu May 17, 2012 12:43 pm
Location: in front of a computer

Re: No emulation CD bootloader

Post by metallevel »

Sorry, I wasn't sure if anyone wanted to try running it or not. Here's the part that's giving me trouble (using the Int 13h extensions in this iteration):

Code: Select all

   ;read CD volume descriptors (incomplete)
   mov [0x600],byte 10h
   mov [0x601],byte 0
   mov [0x602],word 1
   mov [0x604],word 0
   mov [0x606],word 0x500
   mov [0x608],dword 10h
   mov [0x60C],dword 0
   
      mov ah,42h
      mov dl,[boot_drv]
      mov si,0x600
   int 13h
Where [boot_drv] is the contents of DL immediately after the BIOS hands over control to the bootloader.

AH and the carry flag indicate success, but the data just isn't loaded for some reason.
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: No emulation CD bootloader

Post by Kazinsal »

test_A20 destroys ES.
metallevel
Posts: 18
Joined: Thu May 17, 2012 12:43 pm
Location: in front of a computer

Re: No emulation CD bootloader

Post by metallevel »

Fixed it! I was giving the buffer address in the packet as a segment:offset pair in the wrong order. So it did read the disk, it just didn't put the data where I expected.

BTW thanks Blacklight, I hadn't caught that. *adds 'es' to consumed resources list*.
Post Reply