Page 1 of 1

Problems executing C code

Posted: Tue Sep 09, 2008 4:16 pm
by InsightSoft
Hi,

Please I need help...

I wrote:
1) Boot.asm
called by BIOS.POST
(16 Bits Code)
->load code from disk to...
7000:0000 - cpu.asm
7000:0200 - library.asm (with some functions like ShowMessage, LoadCode, etc)
7000:0400 - kernel32.asm
7000:0600 - kernel32.c

2) cpu.asm
loaded to (7000:0000) and jumped from boot.asm (1)
->Check the actual cpu that is running the code...
->If it support PM, then call next piece of code
-> them jumps to 7000:0400 (kernel32.asm)

3) kernel32.asm
just call C function
Kernel32.c
just write "Hello world" directly to the memory address


It seem simple, but is where all my problems start!!!!!

Here is my problem
This is 32bits asm code that is attached to a 32 bit C code (DGJPP) - No problem here!

When I call the C function the result is not what expect...

I'm using the bochs emulator to test the code...

It seems that I need to set up some registers... is this the case?

For example what kind o preparation the GRUB boot loader perform???


Please help me!
I want to start using C code without any boot loader...
I want make my own BL....

Re: Problems executing C code

Posted: Tue Sep 09, 2008 5:11 pm
by suthers
Well you need to have a stack setup, so you need a GDT selector in ss and an address within that segment in esp.
Also you jump to 7000:0400 to jump to your 32bit code, offset:address is something you do in real mode not protected mode...
Does your code actually cause a triple fault (i.e. does the emulator reset) or does it just loop?
Jules

Re: Problems executing C code

Posted: Tue Sep 09, 2008 9:31 pm
by cr2

Code: Select all

_asm
{
     mov ax, 10h
     mov ds, ax
     mov es, ax
     mov fs, ax
     mov gs, ax
}

Re: Problems executing C code

Posted: Wed Sep 10, 2008 2:13 am
by Combuster
That code won't even run when the cpu mode is something other than protected mode.

Its like, if(this == null) error();

Re: Problems executing C code

Posted: Wed Sep 10, 2008 2:16 pm
by InsightSoft
Thanks for your reply,

...and I will back!


-----------------------------------
Think it, build it, bit by bit...

Re: Problems executing C code

Posted: Wed Sep 10, 2008 5:09 pm
by InsightSoft
Another question,

Relating to the "Bran's Kernel Dev Tut", he sets up the GDT from C code... and I don't see any code changing CPU to the PM... I presume that it was the GRUB job, right?

Thus, the GRUB start in 16Bit, prepare a GDT, goto PM, and load our 32 Bit asm code that was previous linked to the c 32 bit, right???
then, that C code, prepare again (????) a new GDT, etc... and uala, your kernel is running.... is it correct?

Please, I really need to understand this first 'BIG BANG' moment, then ...a lot of thing will coming a live...



Miguel Esteves (InsightSoft)
-------------------------------------
Think it, build it, bit by bit...

Re: Problems executing C code

Posted: Sat Sep 13, 2008 10:57 am
by raevin
Thus, the GRUB start in 16Bit, prepare a GDT, goto PM, and load our 32 Bit asm code that was previous linked to the c 32 bit, right???
then, that C code, prepare again (????) a new GDT, etc... and uala, your kernel is running.... is it correct?
Yes, GRUB sets up the A20 Gate and all that good stuff so you automatically get jump-started into PM.