Boot Sector won't load Kernel

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
Rune Hunter
Posts: 2
Joined: Sat Aug 05, 2006 8:09 pm

Boot Sector won't load Kernel

Post by Rune Hunter »

Hey first time posting here, friend refered me.

My situation is this: I have a boot sector, it seems to have loaded anouther simple asm bin file perfectly, but now that I introduced my kernel to the boot sector it doesn't seem to work.

Here is my boot sector code:

Code: Select all

[ORG 0x7C00]
[BITS 16]

jmp start

start: 

mov si,Print_loading	;Prints "Loading" to the screen
call printstring	;And returns twice


reset_drive:
mov ah, 0           ;RESET-command
int 13h             ;Call interrupt 13h
or ah, ah           ;Check for error code
jnz reset_drive     ;Try again if ah != 0


mov ax,0x08	;Location to load code
mov es,ax
mov bx,0x7E00

mov ah,02h      ;When ah=02h, int13 reads a disk sector
mov al,8	;Al is how many sectors to read
mov ch,0	;The track to read from
mov cl,2	;Sector Id
mov dh,0	;Head
mov dl,0	;Drive (0 is floppy)
int 13h
or ah, ah               ;Check for error code
jnz reset_drive         ;Try again if ah != 0


mov ax,0x08	;Not sure about this code
mov ds,ax	;Doesn't seem to make a difference

jmp 0x08:0x7E00



printstring:	;Print string routine.
mov ah,0eh	;Mov ah into 0, so int 10 prints
stringloop:	;The following code loads each seperate charcter so it can be printed
lodsb
cmp al,00	;If al =0, then the string has all been loaded
je endstring
int 10h		;When int 10 is called, and ah=0eh, it prints
jmp stringloop
endstring:
ret

Print_loading db 13,10,'Loading',13,10,13,10,0
My kernel loading code is this:

Code: Select all

[BITS 32]	;protected mode

[global start] 
[extern _main]	;this is in our C++ code

start:


call _main 	;call int main(void) from our C++ code
cli 		;interrupts could disturb the halt
hlt 		;halt the CPU
It loads main wich is defined in my C++ code and that prints some text alerting me it loaded and ran. I as well tried anouther kernel that I know works in the same way but also nothing. It just prints loading, returns twice like it should but than sits there until I manualy restart it.

Any help is welcome, and thanks in advance!
Mikae
Member
Member
Posts: 94
Joined: Sun Jul 30, 2006 1:08 pm

Post by Mikae »

I think, that your situation looks like in this topic: http://osdev.org/phpBB2/viewtopic.php?t=2795 :).

Also, it seems to me that directive BITS32 in your kernel placed too 'early'. I mean, that you direct assembler to generate 32bit code, but processor still works in R-mode (until PE bit is not set). I dont know what is going on in your C++ kernel, but I think that this is 'dangerous way'.
Rune Hunter
Posts: 2
Joined: Sat Aug 05, 2006 8:09 pm

Post by Rune Hunter »

Thanks for that link, that topic helped me out alot. I also looked at anouther example about GDT and now I got that working as well. So now I safely entered Protected mode. And the best part is the other kernel loads perfectly, now I just have a problem with my kernel but that is my problem so thanks alot!
Post Reply