GCC Kernel Issue

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
sds2017
Member
Member
Posts: 61
Joined: Tue Jul 05, 2011 10:05 am

GCC Kernel Issue

Post by sds2017 »

Hi I'm developing my own OS and I've come across I problem that I can't figure out. I've done research on this site and brokenthorn.com and there has been lots of posts but none of the build scripts work. I would like to build a EXE executable using C. I've got the point that you compile the C files into object files and link them together to make the executable but, I can't get it to load. I've built my own bootloader and it works if I compile a kernel into a bin file and I've added EXE code to it which I'm almost 100% sure it's right. It would help me alot if somebody could tell me how to compile the C code using gcc on linux into .o files and then linking them together to make a EXE or BIN file.

Thanks
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: GCC Kernel Issue

Post by gerryg400 »

sds2017 wrote:Hi I'm developing my own OS and I've come across I problem that I can't figure out. I've done research on this site and brokenthorn.com and there has been lots of posts but none of the build scripts work. I would like to build a EXE executable using C. I've got the point that you compile the C files into object files and link them together to make the executable but, I can't get it to load. I've built my own bootloader and it works if I compile a kernel into a bin file and I've added EXE code to it which I'm almost 100% sure it's right. It would help me alot if somebody could tell me how to compile the C code using gcc on linux into .o files and then linking them together to make a EXE or BIN file.

Thanks
Your post is a little unclear. You said you can "compile the C files into object files and link them together to make the executable but, I can't get it to load." That sounds like a loader problem.

But you also ask "how to compile the C code using gcc on linux into .o files and then linking them together to make a EXE or BIN file." That sounds like a compiling/linking problem.

Perhaps explain in more detail what the problem is.
If a trainstation is where trains stop, what is a workstation ?
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: GCC Kernel Issue

Post by Chandra »

And of course, it would help to know what kind of 'executables' you're attempting to create. Is it a custom one or a standard one? Did you try loading it with 'Grub'? May be unrelated but if Grub can load your standard executable, it is likely that your loader is broken (as gerryg400 mentioned).
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
Yargh
Member
Member
Posts: 56
Joined: Sat Jun 12, 2010 9:04 pm
Location: Somewhere else.

Re: GCC Kernel Issue

Post by Yargh »

From your post, it sounds like you created a bootloader to load PE (.exe) executables, however unless you have a GCC cross-compiler set up to target PE, then you're going to be creating ELF executables. From what I've seen, the brokenthorn tutorials assume you're using Visual C++.
Wait... What?
User avatar
mutex
Member
Member
Posts: 131
Joined: Sat Jul 07, 2007 7:49 pm

Re: GCC Kernel Issue

Post by mutex »

Hi,

For EXE (and ELF) files. Remember that first code section is not at offset 0x0 in the file/exe.

You can when linking exe files make sure you define what point you want to align sections (code&data) on. I use 0x1000 so that they start on each page. Also make sure file align and memory align are equal. That makes loading very simple from a bootloader perspective.

Be also sure that your page mapping is correct so that your virtual address pagedir/pagetables are matching the address map of the linked exe file.

I find using Visual C++ very good for producing kernel.exe's. If you need to build PE executables on linux i suggest using mingw.

Its always helpfull to also put out a map file from the linker. This tells you where things are put. Can also give some clues.

I suggest using bochs with the internal debugger and create some breakpoints and go from there to isolate what is happening.

If you like you can send me your floppy image and i can try debug it on bochs and tell you what i find out...

Also one more thing. You are sure you are up to the challenge right? Try to understand every step in the process and learn to debug using bochs.

best regards
Thomas
Yargh
Member
Member
Posts: 56
Joined: Sat Jun 12, 2010 9:04 pm
Location: Somewhere else.

Re: GCC Kernel Issue

Post by Yargh »

mutex wrote: I find using Visual C++ very good for producing kernel.exe's. If you need to build PE executables on linux i suggest using mingw.
Uhhh... MinGW is for Windows (it stands for Minimalist GNU for Windows). If you want to build PE executables on linux, you have to build a cross compiler.
Wait... What?
User avatar
mutex
Member
Member
Posts: 131
Joined: Sat Jul 07, 2007 7:49 pm

Re: GCC Kernel Issue

Post by mutex »

Don't know but atleast Ubuntu have mingw packages for compiling and linking output to PE executables...
sds2017
Member
Member
Posts: 61
Joined: Tue Jul 05, 2011 10:05 am

Re: GCC Kernel Issue

Post by sds2017 »

So what your saying is that I'll have to setup a cross-compiler like the one on the tutorial series.

Also one more question, couldn't you compile the kernel code into a binary file instead of building an EXE(PE)/ELF. I know that I'll need to later on but, I just want to test my kernel code.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: GCC Kernel Issue

Post by gerryg400 »

Because you are developing your own operating system you can choose any executable format that you like. Think about your requirements (familiarity, ease of use, debugging, compatibility, tool availability, documentation etc.), the options (let's say ELF, PE, flat binary, your own etc.) and then make your decision. It's not too hard.
If a trainstation is where trains stop, what is a workstation ?
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: GCC Kernel Issue

Post by Chandra »

sds2017 wrote:Also one more question, couldn't you compile the kernel code into a binary file instead of building an EXE(PE)/ELF.
Of course, you can. What are GNU tool-chains for?
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
sds2017
Member
Member
Posts: 61
Joined: Tue Jul 05, 2011 10:05 am

Re: GCC Kernel Issue

Post by sds2017 »

Hi I'm just letting all of you know thank you for your help to the os development community. It has helped me a lot and after reading a lot of articles on this wiki and several other sources I've coded my bootloader and a C kernel that can print strings and do some other simple things(coded it by myself didn't copy and paste or look through the tutorials while I coded it like a lot a of other people do). Right now I'm setting up the IVT and later I'm going to remap the PIC timer and get keyboard input.

Thanks.
Post Reply