Linking floppy bootloader
Posted: Wed Mar 21, 2012 4:28 am
Hi!
I'm writing a floppy bootloader but I've got a problem. The bootloader consists of two parts: the assembler main function and a C - function. The linked binary file must be 512 bytes long with a 0xAA55 signature at the end, so I use this part of source:
I use AT&T syntax and gas assembler.
When I link program the linker inserts C function after 0xAA55 signature so the binary file becomes larger then 512 bytes. How can I tell linker to insert the compiled C - function to the appointed address, not after the assembler main?
Command line:
The part of linker output:
I'm writing a floppy bootloader but I've got a problem. The bootloader consists of two parts: the assembler main function and a C - function. The linked binary file must be 512 bytes long with a 0xAA55 signature at the end, so I use this part of source:
Code: Select all
.fill 510-(.-start), 1, 0
.word 0xaa55
When I link program the linker inserts C function after 0xAA55 signature so the binary file becomes larger then 512 bytes. How can I tell linker to insert the compiled C - function to the appointed address, not after the assembler main?
Command line:
Code: Select all
gcc -m32 -c Cfunc.c
as --32 -o ASMfunc.o ASMfunc.s
ld -m elf_i386 -M -Ttext 0x7c00 --oformat binary -o bootloader.bin ASMfunc.o Cfunc.o
.text 0x0000000000007c00 0x200 ASMfunc.o
0x0000000000007c00 ASMfunc
.text 0x0000000000007e00 0x5 Cfunc.o
0x0000000000007e00 Cfunc