Page 2 of 2

Posted: Fri Jul 14, 2006 10:43 pm
by rexlunae
yonami wrote:Can you make it run?

I do not know, what is wrong. I check other tutorials, and kernels examples. Tah should works :[
In all the suggestions and responses, I'm getting lost following this thread, and I don't know which suggestions you have implemented or how. Could you either update the code you posted above or post your current code.

This is what appears to be wrong to me:
-I think you want your fPrint function to explicitly clear the direction flag (DF), to make sure si is being incremented not decremented.
-You aren't consistently using the same address for your second stage. In the org statement, it is at 0x7e00, but you jump to 0x7e00:0x0000, and since you never set ds, it's probably also in the wrong place.

Those seems like the most likely issues. Waiting on current code to know see if there's something else.

Posted: Sat Jul 15, 2006 7:48 pm
by yonami
Step by step... :wink:

For first here is stack problem for me, cose:
1. Extended Bootloader fClrScr function is working
2. Bootloader jumping correctly to 0x7E00
3. Jump to another address returning Bochs error message "Not allocated memory".

Secod:
1. 'SI' points to incorrect address (Data Segment, Offset or both).
2. If Data Segment 'DS' is eq 0x7E00 or 0x0000 than still not works in Extanded Bootloader.
3. Something wrong with Data Segment

Third:
1. Why you counting StackAddress * 0x10 ?
2. Push and Pop with no result.

Fourth:
1. Primary MBR Bootloader source code [boot.asm]:

Code: Select all

[BITS 16]      
[ORG 0x00007C00]  

BOOT_MAIN:
	cli
	xor bx,bx      ;BX = 0
  	mov ss,bx      ;Stack Segment = 0
  	mov sp,0x7C00  ;Stack Pointer = 0x7C00
  	sti            ;Enable Interrupts
	call fClrScr
	mov si, [ DB_MSG_BOOTSTART ]
	call fPrint
	call fReadFloppy
	call fExecExtendBoot
	jmp $

fPrint:
	mov ah,0x0E
 	mov bh,0x00
 	mov bl,0x07    ; Normal text attribute
	.fPrintChar:       
 		lodsb
 		or al,al
 		jz .fPrintReturn
 		int 0x10
 		jmp .fPrintChar
	.fPrintReturn:
 		ret

fClrScr:
	mov ax,	3
	int 10h
	ret		
	
fReadFloppy:
	mov ah,0x02	  ;Read disk sectors
	mov al,0x01       ;Read ONE sector
  	mov ch,0x00       ;Track 0
  	mov cl,0x02       ;Sector 2
	mov dh,0x00	  ;Head 0
	mov dl,0x00	  ;Drive 0
  	mov bx,0x7E00     ;Set BX offset to our desired load location 
  	mov es,bx         ;Set Head Offset to 0, Set Drive Number to 0 
	mov bx,0x0000;
  	int 0x13          ;Execute BIOS Interrupt:
	mov ax, 0x7E00;
	mov ds, ax;
	ret
	
fExecExtendBoot:
	jmp 0x7E00:0x0000
	ret
		
DB_MSG_BOOTSTART	db	13, 10, ' Booting MBR... ', 0
DB_MSG_OK		db	'[OK]', 13, 10, 0
DB_MSG_FAILURE		db	'[FAILURE]', 13, 10, 0	
DB_MSG_ERROR		db	13, 10, '   **** [ERROR]: ', 0	

times 510-($-$$) db 0   ; Fill the rest with zeros
dw 0xAA55               ; Boot loader signature
2. Extanded Bootloader source code [boot-ext.asm]:

Code: Select all

[BITS 16] 
[ORG 0x7E00]

 EBOOT_MAIN:
	cli
	xor bx,bx      ;BX = 0
  	mov ss,bx      ;Stack Segment = 0
  	mov sp,0x7E00  ;Stack Pointer = 0x7C00
	mov ax,0x0000
	mov ds,ax
	mov ax,0x0000
	mov es,ax
	sti
	;call fClrScr
	;mov si, [ DB_Message_Starting ]
	mov si, 0x0010 
	call fPrint
	jmp $

 fPrint:
 	mov ah,0x0E    ; The function to display a chacter (teletype)
 	mov bh,0x00    ; Page number
 	mov bl,0x07    ; Normal text attribute
	.fPrintChar:    
 		lodsb
 		or al,al
 		jz .fPrintReturn
 		int 0x10
 		jmp .fPrintChar
	.fPrintReturn:
 		ret

fClrScr:
	mov ax,	3
	int 10h
	ret	
	
DB_Message_Starting	db	'OK',13,10,0 
I have no idea.

By the way - Thanks for your time :)

Really Thanks a Lot
~ Marcel

Posted: Sat Jul 15, 2006 8:24 pm
by chase
All of you segment address are wrong, your aren't loading the 2nd sector to the memory location you are trying to, and you've got some odd assembly going on - like doing calls instead of jumps when you'll never return. I'd suggest reading the Art of Assembly, you might want to start with the section on segmentation http://webster.cs.ucr.edu/AoA/DOS/ch04/ ... EADING1-64 You don't have a stack problem, the only odd thing you are doing with your stack is having your extended sectors stack write on top your original boot sector for no reason but since you never return that doesn't matter.

Posted: Sat Jul 15, 2006 9:23 pm
by dave
There is nothing wrong with your stack. Not the best placement for it because as chase pointer out you will over write you original boot sector making a return to that code impossible because you have just obliterated it.

Secondly, you are not jumping to your extended boot code. As I pointed out earlier your jump 0x7E00:0x000 != 0x0000:0x7E00 (these are not equalivalent addresses) your jump should be 0x07E0:0x0000 ( if you want to write it that way) or 0x0000:0x7E00. If the code does not work when you correct this then there is a problem with you main boot loader.

I said nothing about multipling the stack address by 0x10. I was talking about segment offset addressing. If you do not understand how segmented addressing works I strongly suggest reading a tutorial.

DS and CS should equal 0x07E0 should you want to point to the 64KB block from 0x0000 7E00 - 0x0001 7DFF. If you set DS (or CS for that matter) to 0x7E00 then you are pointing to the 64KB from 0x0007 E000 - 0x0008 DFFF this is not where your loading your code.

To point out the problem directly

1. Main Boot Code

Code: Select all

fReadFloppy: 
   mov ah,0x02      
   mov al,0x01       
     mov ch,0x00        
     mov cl,0x02        
   mov dh,0x00     
   mov dl,0x00    
     mov bx,0x7E00   <- this equals ORG 0x7E000 not ORG 0x7E00
     mov es,bx         
   mov bx,0x0000; 
     int 0x13          
   mov ax, 0x7E00; <- this equals ORG 0x7E000 not ORG 0x7E00
   mov ds, ax; 
   ret 

...

fExecExtendBoot: 
   jmp 0x7E00:0x0000  <- this equals ORG 0x7E000 not ORG 0x7E00
   ret 
So your ORG statement sets all addresses to be relative to 0x7E00 not 0x7 E000 which is where you have loaded your code.

You really should read up on memory addressing modes or your going to have a very difficult time programming anything in assembly.

Dave

Posted: Sun Jul 16, 2006 1:44 am
by yonami
OK. Thanks.

jmp tutorial :twisted:

Posted: Sun Jul 16, 2006 9:48 am
by JAAman
question...
do you have the intel manuals?

if you dont, get them, all this is explained there very well (read volume 3a chapter 15 -- particularly 15.1.1 -- i dont know why people dont ever recommend the intel manuals for understanding RMode addressing)

even once youve gotten this, the intel manuals will be an invaluable resource (particularly when setting up PMode, and paging)

there is a link to them in my signature, where you can download PDFs of them, and a link to where you can order hard-copies (they are free, including shipping, and highly recommended)