Page 1 of 1

Can't boot kernel

Posted: Tue Jul 16, 2002 1:57 pm
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

Re:Can't boot kernel

Posted: Wed Jul 17, 2002 1:49 am
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 ...

Re:Can't boot kernel

Posted: Wed Jul 17, 2002 8:19 am
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

Re:Can't boot kernel

Posted: Wed Jul 17, 2002 9:33 am
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 ?

Re:Can't boot kernel

Posted: Wed Jul 17, 2002 9:41 am
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 ;)

Re:Can't boot kernel

Posted: Wed Jul 17, 2002 9:46 am
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

Re:Can't boot kernel

Posted: Wed Jul 17, 2002 11:31 am
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

Re:Can't boot kernel

Posted: Thu Jul 18, 2002 1:13 am
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.

Re:Can't boot kernel

Posted: Wed Jul 24, 2002 7:28 pm
by Tom
Thank you for the help. Sorry for not replying before. ;D