Page 1 of 1

BootLoader Problem with INT13h

Posted: Sun Jun 01, 2008 1:38 pm
by DoS
First, I don't know if its a problem with my code, or how my program is ligned up. But I am developing a simple bootloader... No don't want to use GRUB... My problem is that the code executes correctly but when I jump to my kernel it just hangs.

This is my LoadSectors Command

Code: Select all

LoadSectors:
	mov ax, 0x7E00
	mov es, ax
	mov si, es
	call PrintString
	xor bx, bx
	mov si, bx
	call PrintString

	mov ah, 0x02
	mov al, 1
	mov ch, 0
	mov cl, 02h
	mov dh, 0x00
	mov dl, 0x00
	int 0x13
	ret
and here is the bootloader

http://pastebin.com/m5fc26067

I would really appreciate the help, I have been trying to figure this out for a while, the kernel is a simple loop that allows you to press a key and it prints it, 5 lines, and i have verified that the kernel works...

The very last line of my bootlaoder (the pastebin) link has the %include "kernel.asm" file after the 512 byte mark, would this put kernel at the next sector? maybe this is my problem?

Im sry I edited the bootcode, there is a Jmp 0x7E00 before the Jmp $

Posted: Sun Jun 01, 2008 2:15 pm
by svdmeer
I don't know why you put your bootsector full of strings. You need the space when you want to develop a serious bootloader loading from a real filesystem and offering support for both int 13h legacy functions and int 13h extensions.


Do the messages from the bootsector print?
I can't find any initialization of DS.
Your stack initialization: You don't initialize SS but you initialize SP. That's not safe. Never initialize one of the two stack-registers without knowing the value of the other. And it's more safe to turn off interrupts, so CLI; MOV SS,AX; MOV SP,0x7C00; STI.

This one is weird:

Code: Select all

 mov ax, 0x7E00 
   mov es, ax 
   mov si, es 
   call PrintString
You want to load sectors at 0000:7E00 but before you do you print a string from that address?

Where do you want to load the two sectors?
The address will be es:bx. When you wan to load it to 0000:7E00 you need to set
- segment 7E0 and offset 0
OR
- segment 0 and offset 7E00.

Segment 7E00 and offset 0000 will let your sectors load to linear address 7E000. I don't think this is want you want.

You say you jump to your kernel, but you don't.
"jmp $" means jump to current location, so let the system hang.

Posted: Sun Jun 01, 2008 2:18 pm
by kmtdk
when i looks at your code, i see one major problem:
the es register!
you have set it to 0x7e00
and bx is set to 0x0
that means that you are copying the secound sector to :
0x0000:7e00 in memory
so if you try jumps to 0x0000:0x1000 you wont hit the right memory place
set es just before you set the ah register

Posted: Sun Jun 01, 2008 2:20 pm
by DoS
Thanx for the responce, I have added at the bottom of my previous post that i have edited the code on accident before posting, there is a

Code: Select all

 jmp 0x7E00 
the reason why I do mov si, es is Im trying to print to the screen where its going but, Im obviously doing something wrong.

My Print messages do work, all the way upto the jump but the print message from the kernel itself never gets displayed.

Posted: Sun Jun 01, 2008 2:21 pm
by DoS
Here, just a little cleaner

Code: Select all

LoadSectors:
	mov ax, 0x7E00
	mov es, ax
	xor bx, bx
	mov ah, 0x02
	mov al, 1
	mov ch, 0
	mov cl, 02h
	mov dh, 0x00
	mov dl, 0x00
	int 0x13
	ret

Code: Select all

[ORG 0x7C00]					; BIOS looks in this area for BootLoader
[BITS 16]					; Tell the processor we are in 16 bits

;===============================================
; Boot Loader
;===============================================

	jmp main				; Jump over the include files

	%include "video.asm"			; Load Video.asm which includes multiple
						; functions such as PrintString
	%include "disk.asm"			; Load Disk.asm which includes functions
						; that control the disk
main:

	xor ax, ax				; Setting up the stack
	mov es, ax				
	mov sp, ax

	mov si, welcome_message			; Load our Welcome Message into memory
	call PrintString			; Print the message to screen

;===============================================
; Reset Disk
;===============================================
reset:
	mov si, reset_disk			; Load our Reset Disk Message into Memory
	call PrintString			; Print the message to screen
	call ResetDisk
	jnc reset_success
	mov si, reset_fail
	call PrintString
	jmp reset	

reset_success:
	mov si, disk_success
	call PrintString
reset_success_retry:
	mov si, LoadingSectors
	call PrintString
	call LoadSectors
	jc reset_success_retry
	mov si, es
	call PrintString
	mov si, bx
	call PrintString
	mov si, load_sectors_success
	call PrintString
	jmp 0x7E00
	jmp $
;===============================================
; Data
;===============================================

	load_sectors_success	db "Successfully loading Sector 2",13,10,0
	LoadingSectors	db "Loading Sector 2",13,10,0
	welcome_message	db "Initilizing Boot Loader",13,10,0
	reset_disk	db "Resetting Disk",13,10,0
	reset_fail	db "Im sry, reset failed trying again",13,10,0
	disk_success	db "Reset Successful, attempting to load sector 2",13,10,0
	TIMES 510-($-$$) db 0
	dw 0xAA55
	%include "kernel.asm"
;	TIMES 1474558-($-$$) db 0

[/code]

Posted: Sun Jun 01, 2008 2:23 pm
by svdmeer
I don't know your print routine, but I assumes it prints a string pointed by DS:SI using int 0x10 functions (probably function 0x0E).

You want to load code to 0000:7E00. It's senseless to print binary data with string printing-functions. It's the wrong way to debug it, because some ASCII-codes do special things on the screen when used with some BIOS-functions.

And you are loading your sectors at the wrong place!

You jump to 7E00 but you are loading to 7E000. Of course it goes wrong!

Best way to solve that:
Initialize DS, ES and SS to zero in the beginning of the bootsector.
Don't touch that registers again, so don't set ES to another value when calling int 13h. Set BX to 7E00 before calling function 2 int 13h.

Posted: Sun Jun 01, 2008 2:33 pm
by DoS
Omg, I knew it was going to be simple. I sure do appreciate your help I was able to successfully get into my kernel. I was jumping to 7E00:0000 instead of 0000:7E00

I am very gratefull for all of your help

Posted: Sun Jun 01, 2008 4:31 pm
by suthers
By the way its a bad idea to load your kernel into memory at 0x7E00, because eventually when your kernel gets big enough, you'll right on video memory (0xb8000), though if you intend to stay in protected mode this doesn't apply.
Personally I load at 1MB.
Jules
edit: if you're planning on a large project long term, 704.5Kb isn't that much.

Posted: Mon Jun 02, 2008 7:18 am
by Zenith
Well, it depends if he's going to stay in real mode or not.

Anyway, I load my 64-bit kernel at 1 MB since I use GRUB2... But, he also has the option of loading his kernel at 0x500 and use the lower memory space to 0x9F2FF, then keep userspace stuff in higher memory.

And ~ 700kB is a fair amount of space. My monolithic kernel only takes up 57kB (32-bit) and 90kB (64-bit) with all the basic stuff.

Posted: Mon Jun 02, 2008 11:41 am
by suthers
karekare0 wrote:Well, it depends if he's going to stay in real mode or not.
Good point... (sorry for some reason I automatically assumed that he would switch to Pmode as most people here do (I think), and so do I...)
karekare0 wrote: Anyway, I load my 64-bit kernel at 1 MB since I use GRUB2... But, he also has the option of loading his kernel at 0x500 and use the lower memory space to 0x9F2FF, then keep userspace stuff in higher memory.
Again good point, the main reason I mentioned 1Mb is because thats were GRUB loads it and it is a semi convention (sought of...) and also I used that for my custom bootloader....
karekare0 wrote: And ~ 700kB is a fair amount of space. My monolithic kernel only takes up 57kB (32-bit) and 90kB (64-bit) with all the basic stuff.
I was talking long term (I mean VERY long term, by which time most people quit their project...), when your that far though you probably have you probably have your video mem loaded at 0xA0000000L so yah, its actually irrelevant...

Jules

Posted: Tue Jun 03, 2008 6:20 am
by jal
suthers wrote:(sought of...)
Ah, you rhoticless Brits...


JAL

P.S. Sorry for getting off-topic

Posted: Tue Jun 03, 2008 7:00 am
by AJ
You wouldn't expect a northerner to be able to spell, would you? :twisted: