Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
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?
Usually people don't use C in a bootsector because the available space is so cramped, there are no guarantees for the size of the compiler output (i.e. your current compiler might work but others might not), and you have to start with ASM anyway, so they don't bother with the bootsector being compiled from two languages.
I wouldn't go as far as saying you "should not". If you get it to work, fine. It's just a somewhat unusual decision.
Every good solution is obvious once you've found it.
I've got two functions. How can I tell linker to insert the second function code into a specific place in the program? Like parameter "-Ttext org" but for the .text segment of the second function.
Use a linker script. You can supply the name of the object files in desired order. An alternative is to locate the functions in different sections and merge the sections in desired order. However, for a boot sector this may be too much trouble.
So the 0xaa55 signature is inserted by linker. When you add some variables to a C - function the script will become more complicated because of more segments.
Command line: