1. Kernel memory at the top (this memory mapping would always be fixed). Let's call this KERNEL_BASE_ADDR.
2. User stack growing down
3. Heap growing up
4. Data
5. Userland code
The purpose of this question is how to get the kernel up there. In particular, how to set up linker scripts and the assembly files, so that generated code is made relative to the correct address where it's going to sit (virtual address that is).
In principle it's all very easy and I would need GRUB to load things up as follows:
1. Multiboot header + initial code which sets up page table and switches to long mode.
2. Followed by code with .code64 specifier aligned to a 4KB page boundary.
Essentially,. I would just like to map the virtual address KERNEL_BASE_ADDR to the physical address where (2) sits and then jump to that code to get myself up and running. I can easily have a linker.ld like:
Code: Select all
ENTRY(start)
SECTIONS {
. = 1M;
.text :
{
/* ensure that the multiboot header is at the beginning */
*(.multiboot_header)
*(.text)
}
}
I'm using the GNU assembler.