I am currently writing a simple bootloader as a personal project. I have a working prototype that was built using NASM as my assembler. However I would like to get more familiar with GNU tools, and so I am attempting to rewrite my work using them.
There is this small sample online ‘Hello World’ Bootloader that demonstrates the use of several tools for writing and building the ‘Bootloader’. However, after some reading, it is to my understanding that ‘gas’ is a backend to gcc, and that it should not be directly invoked. I came across this information when I was trying to write expressions inside my assembly file that used symbols to caclulate the size of the program so I would know how many 0 bytes I would have to write before writing 0x55, and 0xAA, which can be accomplished using this bit of NASM code:
;---------------------------------------------
; Write Zeros up to end of program - 2 then boot signature
;---------------------------------------------
size equ $ - entry
times (512 - size - 2) db 0
db 0x55, 0xAA ;2 byte boot signature
Is there a way to write this equivalent set of expressions using the syntax natively read by GAS? My attempts have failed, for example:
.size len, ( 512 - ( (message + 12) - _start) )
Using this expression and passing it to as gives me the following error:
./gasbootloader.asm:24: Error: invalid sections for operation on `message' and `_start'
Do I need to pass my program through gcc so the symbols can get resolved?
The GNU assembler has a
.orgdirective which makes the math you had to do in NASM unnecessary. Here’s an example source file:And a dump of the object file after building:
As you can see, the
0x55 0xAAends up where you want it to without any special effort.