bootloader icon indicating copy to clipboard operation
bootloader copied to clipboard

Documentation on initial state

Open mark-i-m opened this issue 5 years ago • 5 comments

Is there any documentation about the state of the system when _start function is invoked by the bootloader? For example, what features are enabled, what is the layout of memory, what state are the processors in?

mark-i-m avatar Dec 31 '19 18:12 mark-i-m

Not yet. I'm currently working on rewriting the first stages of the bootloader in Rust and plan to add more documentation in the process.

Do you have questions about a specific feature/processor register? Maybe I can answer them here.

phil-opp avatar Jan 02 '20 13:01 phil-opp

Thanks for the response. I was able to figure out the following for the recursive mapping mode, but perhaps it would be good to document:

  • (I believe) only the main processor is initialized. If you want to turn on SMP, you need to do it in your kernel.
  • Long mode is on
  • The bootloader loads itself at the beginning of virtual and physical memory (the first 16kb iirc)
  • The vga buffer is direct mapped 0xb8000
  • The kernel is mapped at Virtual address 0x200000 but it's backed by dynamically choose physical memory.
  • Page tables are recursively mapped at a dynamic entry, and the recursive index can be extracted from the address in BootInfo.
  • The BootInfo memory map gives all the physical regions used, including ones allocated by the bootloader.

mark-i-m avatar Jan 02 '20 15:01 mark-i-m

Seems correct to me, except for:

The kernel is mapped at Virtual address 0x200000 but it's backed by dynamically choose physical memory.

The kernel is mapped by the virtual address specified by the ELF file. By default, the linker uses address 0x200000 for executables, but you can change that address using linker flags or a linker script.

perhaps it would be good to document

Absolutely! A good start would be to create an doc/environment.md (or initial_state.md) file with your bullet points.

phil-opp avatar Jan 27 '20 14:01 phil-opp

@phil-opp , couple of questions

  • How much of the actual physical memory is mapped when using offset mode? It is exactly 100% or more? (For example, what happens if i access offset + 100GB when I don't have 100GB of memory?
  • By default, some areas of the memory are dedicated to memory mapped registers. (Higher regions of memory) How do you want to represent that in the memory map provided?

vinaychandra avatar Feb 09 '20 08:02 vinaychandra

The memory map is a E820 memory map created by the BIOS. The bootloader crate just removes any used memory from it, otherwise it is passed to the kernel with no modifications. From the top of my head, I'm not sure whether memory mapped registers are listed in it, but I don't think so.

The code for mapping physical memory is quite simple: It linearly maps all physical pages starting from 0 up to the largest physical address reported in the memory map.

I hope this answers your questions!

phil-opp avatar Feb 10 '20 10:02 phil-opp