标签:
经过前面的几篇介绍,已经搭建了基本的界面,和实现对应的键盘操作功能,接下来我们开始实现各具体的功能.本文先介绍Memory的相关知识,阐述内存空间的概念,然后介绍如何访问内存空间,并在XU中如何实现memory dump部分。




| linear address range | real-mode address range | memory type | use |
|---|---|---|---|
| 0- 3FF | 0000:0000-0000:03FF | RAM | real-mode interrupt vector table (IVT) |
| 400- 4FF | 0040:0000-0040:00FF | BIOS data area (BDA) | |
| 500- 9FBFF | 0050:0000-9000:FBFF | free conventional memory (below 1 meg) | |
| 9FC00- 9FFFF | 9000:FC00-9000:FFFF | extended BIOS data area (EBDA) | |
| A0000- BFFFF | A000:0000-B000:FFFF | video RAM | VGA framebuffers |
| C0000- C7FFF | C000:0000-C000:7FFF | ROM | video BIOS (32K is typical size) |
| C8000- EFFFF | C800:0000-E000:FFFF | NOTHING | |
| F0000- FFFFF | F000:0000-F000:FFFF | ROM | motherboard BIOS (64K is typical size) |
| 100000- FEBFFFFF | RAM | free extended memory (1 meg and above) | |
| FEC00000- FFFFFFFF | various |
motherboard BIOS, PnP NVRAM, ACPI, etc. |

; use the INT 0x15, eax= 0xE820 BIOS function to get a memory map; inputs: es:di -> destination buffer for 24 byte entries; outputs: bp = entry count, trashes all registers except esido_e820:xor ebx, ebx ; ebx must be 0 to startxor bp, bp ; keep an entry count in bpmov edx, 0x0534D4150 ; Place "SMAP" into edxmov eax, 0xe820mov [es:di + 20], dword 1 ; force a valid ACPI 3.X entrymov ecx, 24 ; ask for 24 bytesint 0x15jc short .failed ; carry set on first call means "unsupported function"mov edx, 0x0534D4150 ; Some BIOSes apparently trash this register?cmp eax, edx ; on success, eax must have been reset to "SMAP"jne short .failedtest ebx, ebx ; ebx = 0 implies list is only 1 entry long (worthless)je short .failedjmp short .jmpin.e820lp:mov eax, 0xe820 ; eax, ecx get trashed on every int 0x15 callmov [es:di + 20], dword 1 ; force a valid ACPI 3.X entrymov ecx, 24 ; ask for 24 bytes againint 0x15jc short .e820f ; carry set means "end of list already reached"mov edx, 0x0534D4150 ; repair potentially trashed register.jmpin:jcxz .skipent ; skip any 0 length entriescmp cl, 20 ; got a 24 byte ACPI 3.X response?jbe short .notexttest byte [es:di + 20], 1 ; if so: is the "ignore this data" bit clear?je short .skipent.notext:mov ecx, [es:di + 8] ; get lower uint32_t of memory region lengthor ecx, [es:di + 12] ; "or" it with upper uint32_t to test for zerojz .skipent ; if length uint64_t is 0, skip entryinc bp ; got a good entry: ++count, move to next storage spotadd di, 24.skipent:test ebx, ebx ; if ebx resets to 0, list is completejne short .e820lp.e820f:mov [mmap_ent], bp ; store the entry countclc ; there is "jc" on end of list to this point, so the carry must be clearedret.failed:stc ; "function unsupported" error exitret

union point_tag {unsigned char *pb;unsigned short *pw;unsigned long *pd;unsigned long d;} pmem;
标签:
原文地址:http://blog.csdn.net/kevinhugh163/article/details/51264926