Friday, 2 November 2018

Memory Layout

In our previous example we have seen that, MBR (Master Boot Record or first sector) is loaded at the memory location 0x7C00. To understand the reason behind loading MBR at 0x7C00 we need to understand the memory layout of the x86 architecture.

Minimum requirement for DOS version 1.0 was 32KB (0x0000 to 0x7FFF). when we subtract 1KB (1024 bytes) from 32KB we will ge the value 0x7C00. Even though the length of MBR is 512 bytes, the reason for keeping 1024 bytes for MBR is to have extra memory for Stack/Data area of MBR. For more details on memory location 0x7C00 please check the link: https://www.glamenv-septzen.net/en/view/6

Now let us understand the memory architecture after boot.

Early version of x86 has the memory architecture was like below:



In the modern system memory architecture has little modification. As many peripherals are added and more memory is available, the memory architecture will look like below:



0xXXXXXX is the last memory address in a given microprocessor. It depends on the size of the memory in any given microprocessor.

An example demonstrating the initial address of the Boot Sector can be found here: https://github.com/bvbasavaraju/os_dev/blob/dev/src/boot_sector/3_boot_sector_memory.asm

In the modern CPUs just to make sure that MBR is loaded in the correct memory location 0x7C00, developer can make use of the Assembly Keyword "org" in the beginning of the Boot Sector program like below:
[org 0x7C00]

Note: Try to add the [org 0x7C00] at the beginning of the program and check the difference in output.