Bona Fide OS Developer
View unanswered posts | View active topics It is currently Mon Dec 09, 2019 1:38 pm



Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2, 3  Next
 Multiple main()s 
Author Message

Joined: Sat Jul 25, 2009 6:10 am
Posts: 112
Location: United Kingdom
Post Multiple main()s
Let's assume I have two files:

loader.c
kernel.c

OK. Both of these contain the following line:

int main(void)

My kernel entry assembly file jumps to _main. I have yet to try this, but I think it may cause a few problems:

1) How will it know what main(void) to jump to?
2) I want it to start with the loader.c main, and then have loader.c go to the kernel.c main. How would i be able to implement this?

_________________
Thanks,
Michael Sammels

OS Developing is 10% luck, 20% skill, 15% concentrated power of will. 5% pleasure, 50% pain, and a 100% reason continue the game.


Sun Oct 18, 2009 11:24 am
Profile

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post Re: Multiple main()s
I would then rename your Kernel's main to "kmain" or something like that. In ASM _main == main and _kmain == kmain. That way you can launch your loader and have your loader launch your kernel. Or, since you want your loader to be first, name the loader's main to "lmain" or "entry" and then leave your kernel's main to main so that you can also use the loader to load other things with the main func. ((I feel that other loaders may use "start" as their entry function, but I could be wrong on that)).

~Charles

_________________
Charles Timko
push %esp ;Musings of a computer addict


Sun Oct 18, 2009 12:13 pm
Profile WWW

Joined: Sat Jul 25, 2009 6:10 am
Posts: 112
Location: United Kingdom
Post Re: Multiple main()s
So in my loader.c file I could do:

Code:
extern void main();

int lmain()
{
  // Code goes here
  call main();
}

_________________
Thanks,
Michael Sammels

OS Developing is 10% luck, 20% skill, 15% concentrated power of will. 5% pleasure, 50% pain, and a 100% reason continue the game.


Sun Oct 18, 2009 12:16 pm
Profile

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post Re: Multiple main()s
Exactly. If you need a sample loader for ELF, I have code that I wrote for my OS Class when we had to make our own.

~Charles

_________________
Charles Timko
push %esp ;Musings of a computer addict


Sun Oct 18, 2009 12:17 pm
Profile WWW

Joined: Sat Jul 25, 2009 6:10 am
Posts: 112
Location: United Kingdom
Post Re: Multiple main()s
Well, ELF loading will happen when I find a way to get user input, so I can actually enter commands to run programs :lol:

_________________
Thanks,
Michael Sammels

OS Developing is 10% luck, 20% skill, 15% concentrated power of will. 5% pleasure, 50% pain, and a 100% reason continue the game.


Sun Oct 18, 2009 12:18 pm
Profile

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post Re: Multiple main()s
MMk, I didn't know if you were compiling your kernel in elf or something else (i am assuming ELF since you are prolly going Linux like and there is poor documentation on PE/COFF. ((There will be a post later on with an overview of PE/COFF and ELF for anyone that wants it)).

_________________
Charles Timko
push %esp ;Musings of a computer addict


Sun Oct 18, 2009 12:21 pm
Profile WWW

Joined: Sat Jul 25, 2009 6:10 am
Posts: 112
Location: United Kingdom
Post Re: Multiple main()s
Actually, I use Windows. I don't use PE/COFF or ELF. :)

_________________
Thanks,
Michael Sammels

OS Developing is 10% luck, 20% skill, 15% concentrated power of will. 5% pleasure, 50% pain, and a 100% reason continue the game.


Sun Oct 18, 2009 12:22 pm
Profile

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post Re: Multiple main()s
Windows apps are PE/COFF format. I are you running your kernel inside of windows without a VM?

Charles

_________________
Charles Timko
push %esp ;Musings of a computer addict


Sun Oct 18, 2009 12:24 pm
Profile WWW

Joined: Sat Jul 25, 2009 6:10 am
Posts: 112
Location: United Kingdom
Post Re: Multiple main()s
I know what format Windows Apps are. I'm a Microsoft Geek. :P No - I use a custom coded VM Software, based on Bochs.

_________________
Thanks,
Michael Sammels

OS Developing is 10% luck, 20% skill, 15% concentrated power of will. 5% pleasure, 50% pain, and a 100% reason continue the game.


Sun Oct 18, 2009 12:28 pm
Profile

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post Re: Multiple main()s
Oh, neato. So then you are just using the loader as the first position on the "primary disk" to load ur kernel..so no grub. interesting. let me know how that works out, but I feel as though the file should be outputting into some format...

Charles

_________________
Charles Timko
push %esp ;Musings of a computer addict


Sun Oct 18, 2009 12:53 pm
Profile WWW
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2, 3  Next


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin and tweaked by the BF Team.