程序集 - mov 未初始化的变量?
assembly - mov unitialized variable?
我很难理解一段代码。
我看了xv6讲座at line 1054
这是代码 :
.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
我的问题是:
我们怎么可能 movl $(stack + KSTACKSIZE), %esp
当 stack
在项目中的任何地方定义时,但在第 1063 行作为 .comm 符号和在稍后调用并重新定义堆栈的函数中作为本地变量
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);
?
我可能错过了一个技巧,但我不知道它的地址是什么时候设置的。
在链接阶段,以便实际定义堆栈?
谢谢
是 .comm
在 .bss
部分中使用给定的 STACKSIZE
定义和分配 stack
。第一次执行时,代码按原样运行,并使用该堆栈。从 startothers
的函数名称来看,我假设这是一个多处理器启动。一旦启动了初始 cpu,它就会为每个其他处理器分配一个新堆栈,并修改代码本身,以便它使用新分配的堆栈。
在我看来,如果 entry
对这些事情使用变量,那么混乱会少很多。
我很难理解一段代码。 我看了xv6讲座at line 1054
这是代码 :
.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
我的问题是:
我们怎么可能 movl $(stack + KSTACKSIZE), %esp
当 stack
在项目中的任何地方定义时,但在第 1063 行作为 .comm 符号和在稍后调用并重新定义堆栈的函数中作为本地变量
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);
?
我可能错过了一个技巧,但我不知道它的地址是什么时候设置的。
在链接阶段,以便实际定义堆栈?
谢谢
是 .comm
在 .bss
部分中使用给定的 STACKSIZE
定义和分配 stack
。第一次执行时,代码按原样运行,并使用该堆栈。从 startothers
的函数名称来看,我假设这是一个多处理器启动。一旦启动了初始 cpu,它就会为每个其他处理器分配一个新堆栈,并修改代码本身,以便它使用新分配的堆栈。
在我看来,如果 entry
对这些事情使用变量,那么混乱会少很多。