Problems executing C code

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
InsightSoft
Member
Member
Posts: 76
Joined: Mon Aug 18, 2008 6:17 am

Problems executing C code

Post 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....
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: Problems executing C code

Post 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
User avatar
cr2
Member
Member
Posts: 162
Joined: Fri Jun 27, 2008 8:05 pm
Location: ND, USA

Re: Problems executing C code

Post by cr2 »

Code: Select all

_asm
{
     mov ax, 10h
     mov ds, ax
     mov es, ax
     mov fs, ax
     mov gs, ax
}
Last edited by cr2 on Sat Sep 13, 2008 9:20 pm, edited 1 time in total.
OS-LUX V0.0
Working on...
Memory management: the Pool
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Problems executing C code

Post by Combuster »

That code won't even run when the cpu mode is something other than protected mode.

Its like, if(this == null) error();
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
InsightSoft
Member
Member
Posts: 76
Joined: Mon Aug 18, 2008 6:17 am

Re: Problems executing C code

Post by InsightSoft »

Thanks for your reply,

...and I will back!


-----------------------------------
Think it, build it, bit by bit...
InsightSoft
Member
Member
Posts: 76
Joined: Mon Aug 18, 2008 6:17 am

Re: Problems executing C code

Post 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...
raevin
Member
Member
Posts: 33
Joined: Tue Dec 28, 2004 12:00 am

Re: Problems executing C code

Post 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.
Post Reply