Hi everyone,
As you may have already guessed, yes I'm wanting to get into hobby kernel development however I'm not liking the difficulty in getting to the stage of actually having an easily compilable and testable C kernel binary (even with just a simple main function .c file).
I've recently decided to scrap learning how to make a bootloader and use GRUB to load my kernel however a nudge in the right direction would be great right now.
I want to use Bochs (2.3.7) to test my kernel binary on and hope that I can come to a point where I can simply do a gcc/ld of my kernel code, run a bochs script and have GRUB auto load my kernel binary in long mode (as I intend to develop only a 64-bit protected mode kernel).
I have gotten a pre-made GRUB floppy image loading and can navigate the various screens and demos in the GRUB floppy (its got some demos like FreeDOS and GRUB Invaders).
Can anyone point out some clues as to what I'd need?
I understand I will need a cross-compiler version of gcc/ld etc as I'm having trouble with gcc on windows adding some extra crap to the object files (like __main and __alloca) whereas I want to simply compile flat generic C code.
Also, what configuration for GRUB in relation to the Bochs configuration would I need to have my boot floppy load my kernel binary off an emulated disk?
I'm probably asking a lot which I could probably find myself but haven't had much luck and merely setting up an kernel coding and emulation environment seems to be full of configuration files, compiling source code I have never compiled before and whatnot.
As much code as I've written and compiled all kinds of languages and programs before, all this linux style compiling of existing libraries and tools via command lines is a bit over my head as theres all kinds of linux related things I'm not up on given my Windows/Visual Studio background.
Once I can do a compile of my C code, run Bochs and 5 seconds later be running a simple main loop then its full steam ahead and I can actually focus on making my kernel instead of scratching my head with how the hell to just load the damn thing. Haha.
UPDATE*** Is Linux an easier environment to develop and test a kernel on (disregarding the actual kernel coding part)?
Thanks for your help.
Setting up the development of your kernel
Re: Setting up the development of your kernel
I use a cross compiler, and just use standard make to build and 'install' the kernel. The kernel is made out of a bunch of cpp files and a linker script. I use Bochs, which boots a GRUB image, which boots my kernel. The configuration for GRUB depends on how your kernel is loaded. I use a 10 MB HD image with FAT12, so GRUB can just pick the kernel file right off the filesystem. Whenever I want to build my kernel, I just type 'make'. The 'make install' command uses a custom-made program along with Filedisk to copy the kernel file into the HD image. It works pretty much like other programs.
Re: Setting up the development of your kernel
I would not get too worked up over the complexity of just getting to the 'coding' stage as you will just set yourself up for future anger issues as the complexity increases exponentially. Also, once you get a simple main loop going through grub, I found it extremely helpful to go back and write a bootloader to boot your main loop instead of grub, and then later, once you understand how the computer boots and what it takes to get to the kernel, then you should decide whether or not to use grub (as it is perfectly fine to).
I found development in Windows somewhat sketchy as there needed to be some sort of emulation layer for gcc/binutils (although some people here use MSVS/C's compiler/linker). DJGPP was what I used, and it got my by, although it was a fairly outdated GCC.
When I switched to Ubuntu, I found 90+% of the stuff to make an OS was already installed and good to go. NASM and GCC needed to be updated, but besides that, everything was set.
I'd recommend to just stick to the OS that you are most comfortable in as you will have an easier time debugging without having to baby-step through host OS commands.
I found development in Windows somewhat sketchy as there needed to be some sort of emulation layer for gcc/binutils (although some people here use MSVS/C's compiler/linker). DJGPP was what I used, and it got my by, although it was a fairly outdated GCC.
When I switched to Ubuntu, I found 90+% of the stuff to make an OS was already installed and good to go. NASM and GCC needed to be updated, but besides that, everything was set.
I'd recommend to just stick to the OS that you are most comfortable in as you will have an easier time debugging without having to baby-step through host OS commands.
Website: https://joscor.com
Re: Setting up the development of your kernel
Thanks.01000101 wrote:I would not get too worked up over the complexity of just getting to the 'coding' stage as you will just set yourself up for future anger issues as the complexity increases exponentially. Also, once you get a simple main loop going through grub, I found it extremely helpful to go back and write a bootloader to boot your main loop instead of grub, and then later, once you understand how the computer boots and what it takes to get to the kernel, then you should decide whether or not to use grub (as it is perfectly fine to).
I found development in Windows somewhat sketchy as there needed to be some sort of emulation layer for gcc/binutils (although some people here use MSVS/C's compiler/linker). DJGPP was what I used, and it got my by, although it was a fairly outdated GCC.
When I switched to Ubuntu, I found 90+% of the stuff to make an OS was already installed and good to go. NASM and GCC needed to be updated, but besides that, everything was set.
I'd recommend to just stick to the OS that you are most comfortable in as you will have an easier time debugging without having to baby-step through host OS commands.
I do realise that the kernel itself is going to be the most difficult part, but that being said, if I can simply use GRUB to handle the boot sequence (which I've been testing and googling and there doesn't seem to be any decent documentation on exactly what is needed in the right order in an assembly bootstrap/loader so I decided to just go with GRUB as it takes the pain out of the boot process and I can focus on learning how to write a simple kernel. What I mean is, I know its a good learning exercise to do a bootloader and while I do understand the process of the bootsequence, its been a little over my head trying to find out exactly what things I need to do in my boot sequence code.
I might install Ubuntu as it does seem to take the guess work out of things like utilities and compilers being compatible etc.
Re: Setting up the development of your kernel
The wiki has an excellent bootloader tutorial and is very easy to follow.
Also, you need to read the GRUB article (for setting up and just getting familiar with it in general) and also the Bare Bones tutorial to piece your kernel with the GRUB boot loader. These two should get you up and running a kernel in no time with GRUB, the first is for you to examine a boot loader and boot operations in step-by-step detail so that you don't get overwhelmed by an entire boot loader slab.
Also, you need to read the GRUB article (for setting up and just getting familiar with it in general) and also the Bare Bones tutorial to piece your kernel with the GRUB boot loader. These two should get you up and running a kernel in no time with GRUB, the first is for you to examine a boot loader and boot operations in step-by-step detail so that you don't get overwhelmed by an entire boot loader slab.
Website: https://joscor.com
Re: Setting up the development of your kernel
Thanks 01000101. Those two articles were exactly what I needed. Now to finish installing Ubuntu01000101 wrote:The wiki has an excellent bootloader tutorial and is very easy to follow.
Also, you need to read the GRUB article (for setting up and just getting familiar with it in general) and also the Bare Bones tutorial to piece your kernel with the GRUB boot loader. These two should get you up and running a kernel in no time with GRUB, the first is for you to examine a boot loader and boot operations in step-by-step detail so that you don't get overwhelmed by an entire boot loader slab.
I'll have to brush up on my lack of make skills too...
Re: Setting up the development of your kernel
Can I recommend Solar's excellent Makefile tutorial on the wiki. If you're unfamiliar with makefiles, it will take a bit of getting your head around, but I now use it as a template for all my makefiles.thre3dee wrote:I'll have to brush up on my lack of make skills too...
Cheers,
Adam


