【问题标题】:assembly - mov unitialized variable?程序集- mov 未初始化的变量?
【发布时间】:2015-03-12 11:03:08
【问题描述】:

我很难理解一段代码。 我看了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), %espstack 在项目中没有定义,而是在第 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);

?

我可能会错过一个技巧,但在设置地址时我不明白。

在链接阶段以便实际定义堆栈?

谢谢

【问题讨论】:

    标签: c assembly linker


    【解决方案1】:

    是的.comm 使用.bss 部分中的给定STACKSIZE 定义和分配stack。在第一次执行时,代码按原样运行,并使用该堆栈。从startothers 的函数名称来看,我假设这是一个多处理器启动。初始 CPU 启动后,它会为每个其他处理器分配一个新堆栈,并修改代码本身以使用新分配的堆栈。

    在我看来,如果 entry 使用变量来处理这些事情,那么混乱会少很多。

    【讨论】:

    • 谢谢小丑。我有点挣扎,但您的解释使我能够继续满足于确保理解。
    猜你喜欢
    • 1970-01-01
    • 2016-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-12
    • 1970-01-01
    • 2016-03-01
    • 2013-08-25
    相关资源
    最近更新 更多