【发布时间】:2014-07-26 13:20:14
【问题描述】:
我正在尝试理解 Pintos 引导加载程序的代码,但在某行中有些东西让我觉得很奇怪。
addr32 movl %eax, init_ram_pages - LOADER_PHYS_BASE - 0x20000
这里的这一行应该是把4K页数放在头文件中定义的变量init_ram_pages中为:extern uint32_t init_ram_pages;
我不明白为什么我们要从init_ram_pages 中减去这些值?在mov 的目标操作数中进行减法运算是什么意思?
更多详情:
在 %eax 中设置内存大小(以 4K 页为单位)的代码如下:
(如果我的理解是正确的)
movb $0x88, %ah
int $0x15
addl $1024, %eax # Total kB memory
cmp $0x10000, %eax # Cap at 64 MB
jbe 1f
mov $0x10000, %eax
1: shrl $2, %eax # (shift right by two = divide by 4)
# now eax contains the number of 4K pages I guess?
常量定义为:
/* Kernel virtual address at which all physical memory is mapped.
Must be aligned on a 4 MB boundary. */
#define LOADER_PHYS_BASE 0xc0000000 /* 3 GB. */
编辑
变量本身在同一文件中定义如下:(在 .code32 之后的文件部分中)
#### Physical memory size in 4 kB pages. This is exported to the rest
#### of the kernel.d
.globl init_ram_pages
init_ram_pages:
.long 0
【问题讨论】:
标签: memory assembly x86 cpu bootloader