GCC Kernel Issue
GCC Kernel Issue
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
Thanks
Re: GCC Kernel Issue
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.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
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 ?
Re: GCC Kernel Issue
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 !
Re: GCC Kernel Issue
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?
Re: GCC Kernel Issue
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
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
Re: GCC Kernel Issue
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.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.
Wait... What?
Re: GCC Kernel Issue
Don't know but atleast Ubuntu have mingw packages for compiling and linking output to PE executables...
Re: GCC Kernel Issue
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.
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.
Re: GCC Kernel Issue
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 ?
Re: GCC Kernel Issue
Of course, you can. What are GNU tool-chains for?sds2017 wrote:Also one more question, couldn't you compile the kernel code into a binary file instead of building an EXE(PE)/ELF.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
Re: GCC Kernel Issue
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.
Thanks.