Writing bootloader with includes... [Solved. Mostly...]
Posted: Wed May 19, 2021 3:13 pm
Hi there, I've been trying to replace GRUB (because of its limitations and for proprietary reasons) and I was wondering how I could theoretically include say a c header from GAS assembly.
As a preface, I am building my bootloader/kernel in Linux Mint 20 in VirtualBox and I am using the Bare Bones corss compiler (i686-elf) to compile most of my sources. Every once in a while switching to NASM as it seems to have more resources on the internet. My problem is this:
I want to be able to do this
The problem is, I don't know how to compile the .S file with the C header. I found no resources on it. It seems to compile the .o when I do i686-elf-gcc -c -m32 boot.S -o boot.o, but how do I turn it into a binary that QEMU can run? Is there special magic? I tried following (to a point) from this https://www.codeproject.com/Articles/66 ... and-C-Part. It basically uses aAS and LD, but when I use LD it says: ld: i386 architecture of input file `boot.o' is incompatible with i386:x86-64 output.
I understand this means the .o file might not have been compiled with the right format, but what can I do to fix this?
As a preface, I am building my bootloader/kernel in Linux Mint 20 in VirtualBox and I am using the Bare Bones corss compiler (i686-elf) to compile most of my sources. Every once in a while switching to NASM as it seems to have more resources on the internet. My problem is this:
I want to be able to do this
Code: Select all
#include "boot.h"
.code16
.section .text
.globl _start
_start:
...
. = _start + 510
.word 0xAA55
The problem is, I don't know how to compile the .S file with the C header. I found no resources on it. It seems to compile the .o when I do i686-elf-gcc -c -m32 boot.S -o boot.o, but how do I turn it into a binary that QEMU can run? Is there special magic? I tried following (to a point) from this https://www.codeproject.com/Articles/66 ... and-C-Part. It basically uses aAS and LD, but when I use LD it says: ld: i386 architecture of input file `boot.o' is incompatible with i386:x86-64 output.
I understand this means the .o file might not have been compiled with the right format, but what can I do to fix this?