News for hackers. Stuff that matters.
Re:Writing kernels that boot with Qemu and Grub – a tutorial by exDM69 on Friday July 29, 2016 @04:07AM (#12185541)
Nice but very incomplete article. Some observations below...

You will need to build a cross compiler toolchain (binutils and GCC). I.e. i686-pc-elf-gcc for 32 bit or x86_64-pc-elf-gcc for 64 bit. The compiler that comes with your OS is built for a different target and may have downstream patches, esp. if you're on Ubuntu. Things may seem to work initially but you will encounter strange bugs sooner or later.

Build a bootable and debuggable ELF file, not a flat binary. All it takes is a slightly different linker script. You won't get very far without a debugger on bare metal projects.

You need to zero fill .bss section in the boot code before jumping to C code.

I recommend using gas instead of nasm. You might like Intel syntax but you'll need inline (at&t) assembly in C code anyway. Nicer to have just one syntax. It's just an assembler syntax, you will get used to it in a matter of hours

Use a makefile. Fancy build systems (e.g. cmake) aren't nice with kernel images.

See below for examples. The first one isn't my project but I contributed the linker script, Makefile and README for making bootable ELFs. The latter is my x86_64 toy kernel project from years ago.

https://github.com/Overv/MineAssemble

https://github.com/rikusalminen/danjeros

Re:Writing kernels that boot with Qemu and Grub – a tutorial by grahamedgecombe on Friday July 29, 2016 @06:44AM (#12185937)
> You need to zero fill .bss section in the boot code before jumping to C code.

GRUB does this for you. See this thread from a few years ago: https://news.ycombinator.com/item?id=7590790

Re:Writing kernels that boot with Qemu and Grub – a tutorial by exDM69 on Friday July 29, 2016 @02:20PM (#12188775)
Hah, it was a response to my comment back then too.

Either that applies only to multiboot v2 or there was a bug in qemu loader since I had a non-zero value in .bss.

Re:Writing kernels that boot with Qemu and Grub – a tutorial by adrianN on Friday July 29, 2016 @08:09AM (#12186287)
What problems do you have with cmake and kernel images?
Re:Writing kernels that boot with Qemu and Grub – a tutorial by exDM69 on Saturday July 30, 2016 @07:13AM (#12192506)
Using a linker script was more painful than it should have been. Pre-processed assembly files (.S) didn't work (they should run through C pre processor). Writing toolchain file for cross compiling wasn't easy.

CMake works great for user space apps, and cross compiling works very well for them. But bare metal projects, kernel modules, etc just are not great.

Re:Writing kernels that boot with Qemu and Grub – a tutorial by SixSigma on Friday July 29, 2016 @08:28PM (#12191031)
> You will need to build a cross compiler toolchain (binutils and GCC). I.e. i686-pc-elf-gcc for 32 bit or x86_64-pc-elf-gcc for 64 bit.

Then a good idea would be to bootstrap it with a build environment on the emulator