Bona Fide OS Development
http://forums.osdever.net/

Multiple main()s
http://forums.osdever.net/viewtopic.php?f=5&t=52
Page 1 of 3

Author:  Michael [ Sun Oct 18, 2009 11:24 am ]
Post subject:  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?

Author:  ctimko [ Sun Oct 18, 2009 12:13 pm ]
Post subject:  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

Author:  Michael [ Sun Oct 18, 2009 12:16 pm ]
Post subject:  Re: Multiple main()s

So in my loader.c file I could do:

Code:
extern void main();

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

Author:  ctimko [ Sun Oct 18, 2009 12:17 pm ]
Post subject:  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

Author:  Michael [ Sun Oct 18, 2009 12:18 pm ]
Post subject:  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:

Author:  ctimko [ Sun Oct 18, 2009 12:21 pm ]
Post subject:  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)).

Author:  Michael [ Sun Oct 18, 2009 12:22 pm ]
Post subject:  Re: Multiple main()s

Actually, I use Windows. I don't use PE/COFF or ELF. :)

Author:  ctimko [ Sun Oct 18, 2009 12:24 pm ]
Post subject:  Re: Multiple main()s

Windows apps are PE/COFF format. I are you running your kernel inside of windows without a VM?

Charles

Author:  Michael [ Sun Oct 18, 2009 12:28 pm ]
Post subject:  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.

Author:  ctimko [ Sun Oct 18, 2009 12:53 pm ]
Post subject:  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

Page 1 of 3 All times are UTC - 6 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/