Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 组件-mov单元化变量?_C_Assembly_Linker - Fatal编程技术网

C 组件-mov单元化变量?

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

我很难理解一段代码。 我读了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
  # 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。我有点挣扎,但你的解释使我能够继续下去,并确信我能理解。