Call Simple C 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.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Call Simple C Kernel

Post by neon »

But the intention by both people was to call main, whether from a boot sector or a boot loader you rarely if ever call main directly. Even the multiboot specification includes an asm stub.
The assembly stub defines the entry point that the boot application needs to call. In the case of multiboot, his software needs to scan to locate the header (E.g. the multiboot header structure.) and obtain the entry point to call.

For example, in the assembly stub provided by multiboot, it exports the symbols start and _start which is the entry point of the kernel or executive. The boot application must call this entry point by locating the multiboot header structure that which the kernel defines. I am sure you are already aware of this which is why I do not understand the confusion.

The point I was emphasizing was that the original poster still needs the code to call the stubs entry point. And he does not currently have that code as the provided boot record assumes a flat binary image which GCC does not output.

However his kernel is also not currently multiboot compliant.

For clarification, I used the symbol _main previously for example purposes only. I never claimed that you would call _main. Operating systems typically always have a custom named entry point that which provides operating system and boot loader specific parameters. I suspect this might be the confusion. It is also to avoid ambiguity with the standard C definitions of _main which may result in potential problems in some compiler environments.

If this is indeed where the confusion is, then I hope it clarifies it. To put simply, I agree with you.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: Call Simple C Kernel

Post by b.zaar »

@remy From your second example I recommend learning how the files are compiled and linked together and to learn about the executable format they are using.

I'm sure this line here wont produce a binary file.

Code: Select all

gcc -ffreestanding -m32 -c kernel32.c -o kernel.bin
The asm kernel is binary so you are jumping to the entry point where you load the kernel but with your C kernel there will be an executable header that you will need to read to find the entry point, the format is most likely ELF.

What is the file size of your compiled C kernel?

You might also want to learn about linker scripts so you can set the load/org address.

@neon My example was simply to explain there is something else between the boot loader and main inside the kernel, and yeah it's usually start.
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
remy
Posts: 23
Joined: Thu Nov 20, 2014 4:06 pm

Re: Call Simple C Kernel

Post by remy »

Ok, actually the command :

Code: Select all

$ file kernel.bin
outputs :

Code: Select all

kernel.bin: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
It seems to be ELF format. Ok, I'll read more on elf stuff.
Post Reply