I have been using a linker script for a simple kernel I made, and although the linking process always confused me a bit, it has been working fine.
Now that I started working on a simple bootloader for the kernel, I found that many examples use org 0x7C00 when assembling with nasm -f bin .... I found this question, which I think helped me understand (along with nasm's documentation) what it's used for: Specifying where the program is going to be loaded, so nasm can calculate addresses correctly.
From this, I started to wonder if using:
org 0x7C00
section .text
global _start
_start:
...
Is the same as not using that org directive and linking with the following linker script.
ENTRY(_start)
SECTIONS {
. = 0x7C00;
.text : AT(0x7C00) {
*(.text)
}
.rodata : {
*(.rodata*)
}
.data : {
*(.data)
}
.bss : {
*(.bss)
}
}
I can immediately see that the second binary is 4040 bytes instead of 512. If I open the resulting binaries with rizin, I can see that the address on the prompt is 0x0 for the first one, and 0x7C00 for the second one. Why does this happen?
I tried running both versions, and the second doesn't seem to work, probably because the magic 0xAA55 value is not even on the right place.