1
votes

I'm writing a minimal OS from scratch. I enabled paging and long mode but when I want to set up the stack I have a few questions.

  1. Does the stack pointer contain a virtual address automatically translated to physical address by the MMU when using PUSH, POP instructions?

  2. Is the position of the stack mentionned in and ELF file?

1
When paging is enabled, all addresses are virtual. If your page tables aren't identity-mapped (so virt = phys), you'll have to modify RSP to point to the right virtual address. - Peter Cordes

1 Answers

2
votes

The stack pointer must be a virtual address once paging is enabled.

The standard x86-64 psABI does not specify the initial value for the stack pointer, so it does not show up in ELF files. The most common program loader (Linux) randomizes the stack address by default.