Can't boot 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
Tom

Can't boot kernel

Post by Tom »

I'm using gcc 2.96 and ld on Linux.
I link the assembly language booter & my OS's C kernel together and use dd if=kernel.bin of=/dev/fd0 to put it on a floppy. When the floppy boots, the assembly part works, but when it calls main and then the computer freezes. Here is the command line i'm using to link the kernel with the assembly language booter:

nasm -f aout k_entry.asm -o k_entry.o
gcc -c kernel.c
ld -o kernel.bin -oformat binary -Ttext=0x100000 kernel.o k_entry.o
dd if=kernel.bin of=/dev/fd0

Is there something i'm doing wrong?
Tom
gedeon

Re:Can't boot kernel

Post by gedeon »

May be you can give more information ?
For instance the boot action , does it goes in protected mode , description of the kernel loading, etc ...
Tom

Re:Can't boot kernel

Post by Tom »

The assembly language file just loads another assembly program, and then loads the kernel like this:

Assembly program:
jmp 1000h:0000

Second Assemly booter that calles C kernel:
extern main ; my gcc does not use '_'
call main ; where the computer freezes

C Kernel:
int main()
{ return 0; }

My C Kernel just does nothing, but when 'call main' happens the computer freezes.

Tom
gedeon

Re:Can't boot kernel

Post by gedeon »

ok
- how are you sure that the computer hang when you call the main proc ?
- gcc produce 32 bits code, do you jump in protected mode ?
- can you post your code ?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Can't boot kernel

Post by Pype.Clicker »

- if your boot loader don't switch in pmode (32 bits), then for sure it will fail executing your C code (or at least you'll get weird results)

- if your boot loader do switch in pmode, then jmp 1000:0000 is certainly wrong, as you're certainly not having a valid GDT entry #1000! instead (provided that your kernel is loaded at 0x10000), try to have a code segment with base=0 and do a jump KERNEL_CODE_SELECTOR:0 :)

- your kernel do just return, but as you do nothing special after call main, ip goes on incrementing and execute anything it finds ... What did you expect but a freeze, as you have no ouptut code of any kind ;)
Tom

Re:Can't boot kernel

Post by Tom »

Well, I'll try Protected Mode. After the assembly calls main, then it sets graphics mode 13h by:

call main

mov ax, 13h
int 10h

to see if it freezes.

Tom
Tom

Re:Can't boot kernel

Post by Tom »

If someone has NASM code to switch to Protected Mode ( PMode ) and turn on the A20, just enough for GCC, I would be happy to have it. I've been searching for the code and found some, but the code i've found was too much. All I would like to do is use as little assembly in my floppy booter, then load my 32-bit C kernel.

Tom
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Can't boot kernel

Post by Pype.Clicker »

http://prdownloads.sourceforge.net/clic ... 8-0.tar.gz

here's my own piece of code: the Small Operating System. It will load a flat binary in memory, setup a few tables (see this docs for more infos), switch to protected mode and call your kernel at 0008:00000000 (the place where it has been loaded).

Moreover, it provides a reduced API for display output, files mapping from a ramdisk (loaded together with the kernel) and provide regular and emergency exit to real mode.

You can have your own kernel started either from a DOS session (using SOS.EXE) or from a floppy (using sosflppy) disk.

The pmode switch is derivated from Tran Start32 tutorial.
Tom

Re:Can't boot kernel

Post by Tom »

Thank you for the help. Sorry for not replying before. ;D
Post Reply