-
Notifications
You must be signed in to change notification settings - Fork 110
Memory Organization
Douglas Thain edited this page Dec 14, 2017
·
2 revisions
The following memory organization is used throughout the code. To the extent possible, these definitions have been collected in memorylayout.h, but changing any of them may require some some significant code surgery.
0000 0000 Reserved area for initial interrupt vector and BIOS data.
0000 7C00 (BOOTBLOCK_START) 512 bytes where bootblock.S is initially loaded.
0000 fff0 (INTERUPT_STACK_TOP) Initial location of kernel/interrupt stack
until paging and user processes allocate their own stacks.
0001 0000 (KERNEL_START) Start of kernel code and data in kernelcore.S
0010 0000 (KMALLOC_START) Start of kernel memory managed by kmalloc().
0020 0000 (MAIN_MEMORY_START) Start of memory pages managed by memory.c
???? ???? Location of the video buffer, determined by video BIOS at runtime.
Care must be taken in memory allocation and pagetable setup
to avoid stomping on this area.
0000 0000 First 2GB of VM space for all processes is directly mapped to
physical memory in kernel mode. That way, kernel space is
inaccessible in user mode, but kernel code can run correctly
with paging activated.
8000 0000 (PROCESS_ENTRY_POINT) The upper 2GB of VM space for all processes
is private to that process. Each page of VM here is mapped to
physical page allocated by memory.c.
ffff fff0 (PROCESS_STACK_INIT) The high end of the user space is designated
for the user level stack, which grows down towards the middle
of memory.
Start Length Type Privilege
Segment 1 0 4GB CODE SUPERVISOR
Segment 2 0 4GB DATA SUPERVISOR
Segment 3 0 4GB CODE USER
Segment 4 0 4GB DATA USER
Segment 5 tss sizeof(tss) TSS SUPERVISOR
For technical reasons, the X86 requires that segmentation be turned on whenever paging is used. A few key places in interrupt handling and system startup require the use of segments. So, we set up four segments that span all of memory, and use the one with the desired privilege wherever a segment is required. The fifth segement identifies the Task State Structure (TSS) which is where the initial setup information for entering protected mode is stored.