GNU linker bootcode from 16bit up to 64bit is a no-no?
Posted: Tue Feb 05, 2013 2:08 pm
Hello!
I've been surfing this site for about 3 months now, and this is the first time I've stumbled on something I can not find answer for anywhere. I'm writing a bootcode for x86 that starts in real mode (16bit), then does protected mode (32bit) jump, prepares interrupts and stuff, then does a jump to long mode (64bit).
and link it:
Where $(OBJECTS) are mixed 16bit, 32bit and 64bit code objects and in bbp.ld I've specified to output binary file. The linker says:
Now if I change linker attributes to:
The linker says:
Simply put, it does not allow me to mix i386 with x86_64 code in a single binary file. I've only found one small paragraph in gnu toolchain documents, that you can't (and I've lost the URL for now).
Is there any other solution, or maybe somebody could point me in the right direction? My idea is to keep this 16bit, 32bit and 64bit bootcode in a single build, so that I can refer to some data structures defined earlier and not to worry about memory locations other than my entry point.
Thank you in advance!
PS. I've also tried to embed binary stabs in NASM, but I run in to relocation problems.
I've been surfing this site for about 3 months now, and this is the first time I've stumbled on something I can not find answer for anywhere. I'm writing a bootcode for x86 that starts in real mode (16bit), then does protected mode (32bit) jump, prepares interrupts and stuff, then does a jump to long mode (64bit).
- The source
- I'm working on windows with MinGW
- I've build myself x86_64 GNU toolchain (binutils 2.23, gcc 4.72)
- I'm using NASM for assembly
- Intermediate object formats: elf and elf64
- Output format: binary - to be written in BIOS Boot partition
Code: Select all
x86_64-pc-elf-gcc -nostdlib -fno-builtin -nostartfiles -nodefaultlibs
Code: Select all
x86_64-pc-elf-ld -melf_i386 -T bbp.ld $(OBJECTS) -o ../Release/bbp.img
Code: Select all
i386:x86-64 architecture of input file `boot64/main64.c.o' is incompatible with i386 output
Code: Select all
x86_64-pc-elf-ld -melf_x86_64 -T bbp.ld $(OBJECTS) -o ../Release/bbp.img
Code: Select all
i386 architecture of input file `boot32/main32.c.o' is incompatible with i386:x86-64 output
Is there any other solution, or maybe somebody could point me in the right direction? My idea is to keep this 16bit, 32bit and 64bit bootcode in a single build, so that I can refer to some data structures defined earlier and not to worry about memory locations other than my entry point.
Thank you in advance!
PS. I've also tried to embed binary stabs in NASM, but I run in to relocation problems.