I am aware of this. The goal is to call macros in c header from my GAS assembly bootloader.
foliagecanine:
Yes. Exactly. But generating a .bin (or linking them) is an entirely different thing. Say I generate the .o file. Great. Now how do I test it? See my problem? I already generated the object files.
This is how I did it (follow these steps to see what I mean):
- Create a file called boot.S
- Fill it in with this code:
Code: Select all
.code16
.text
.globl _start
_start:
. = _start + 510
.word 0xAA55
- Then this: ld -Ttext 0x7C00 --oformat=binary boot.o -o boot.bin
- You should see boot.bin and boot.o
Phase 2:
- Add .include "boot.h" under .text
- Create boot.h and put in the following:
Code: Select all
#ifnedef __ASSEMBLER__
#define BOOT_MAGIC 0xAA55
#else
// ...
#endif
Output: ld: boot.o: in function `_start':
(.text+0x1fe): undefined reference to `BOOT_MAGIC'
Calling functions into assembly is a goal, but I like to take it in steps. That'll likely be the next topic .
As far as the -m32 is concerned, no you're right. That should be ommitted, but it just proves my point that I've tried everything. That's left over from when I was trying to do this before my attempts at using my i686-elf.
And I know. I'm just trying to get a functional 16 bit real mode bootloader up and running, then switch to protected mode and run some tests.This isn't planned to be a two minute endeavor.
I tried what you said with i686-elf-ld:
And once again I got the same result .
Edit:
I realized something: I was doing .include. That only works if I compile it using GAS. Realizing that I followed your advice and lo and behold it worked. Thank you.
For future readers:
If you're running into the same issue, it might be worth looking into the way you're doing things. A simple symbol (chanhing a '.' to a '#') could be your problem. And if you're using your own cross compiler or following with the "Building your own cross compiler" tutorial, don't use i686-elf-gcc then use the standard LD. They're apparently incompatible.
I was even able to test with a C file (to avoid conflict with boot.o). It doesn't do anything yet (just a simple test function), but we'll see how it goes.