C 组件-mov单元化变量?
我很难理解一段代码。 我读了xv6的讲座 以下是代码:C 组件-mov单元化变量?,c,assembly,linker,C,Assembly,Linker,我很难理解一段代码。 我读了xv6的讲座 以下是代码: .globl entry entry: # Turn on page size extension for 4Mbyte pages movl %cr4, %eax orl $(CR4_PSE), %eax movl %eax, %cr4 # Set page directory movl $(V2P_WO(entrypgdir)), %eax movl %eax, %cr3
.globl entry
entry:
# Turn on page size extension for 4Mbyte pages
movl %cr4, %eax
orl $(CR4_PSE), %eax
movl %eax, %cr4
# Set page directory
movl $(V2P_WO(entrypgdir)), %eax
movl %eax, %cr3
# Turn on paging.
movl %cr0, %eax
orl $(CR0_PG|CR0_WP), %eax
movl %eax, %cr0
# Set up the stack pointer.
movl $(stack + KSTACKSIZE), %esp
# Jump to main(), and switch to executing at
# high addresses. The indirect call is needed because
# the assembler produces a PC-relative instruction
# for a direct jump.
mov $main, %eax
jmp *%eax
.comm stack, KSTACKSIZE
我的问题是:
当stack
在项目中没有定义,而是在第1063行定义为.comm符号,在稍后调用的函数中并将stack变量重新定义为本地变量时,我们怎么可能movl$(stack+KSTACKSIZE),%esp
static void
startothers(void)
{
char *stack; // THIS ONE IS A DIFFERENT BEAST, right ?
...
// Tell entryother.S what stack to use, where to enter, and what
// pgdir to use. We cannot use kpgdir yet, because the AP processor
// is running in low memory, so we use entrypgdir for the APs too.
stack = kalloc();
*(void**)(code-4) = stack + KSTACKSIZE;
*(void**)(code-8) = mpenter;
*(int**)(code-12) = (void *) v2p(entrypgdir);
?
我可能错过了一个把戏,但我不知道它的地址是什么时候设置的
在链接阶段,以便实际定义堆栈
谢谢Yes
。comm
使用.bss
部分中给定的STACKSIZE
定义并分配堆栈
。在第一次执行时,代码按原样运行,并使用该堆栈。从startothers
的函数名判断,我假设这是一个多处理器启动。启动初始cpu后,它会为每个处理器分配一个新堆栈,并修改代码本身,以便使用新分配的堆栈
在我看来,如果
条目
为这些东西使用变量,那么就不会那么混乱了。谢谢Jester。我有点挣扎,但你的解释使我能够继续下去,并确信我能理解。