head_32.S中的“stack_start”的定义是不是有问题?

本帖最后由 JackyBsh 于 2011-02-27 22:58 编辑

(内核版本:2.6.35.4)

文件 arch/x86/kernel/head_32.S 中,设置0号进程的堆栈时,有如下相关语句:

----------------------------------------------------
lss stack_start,%esp
......
ENTRY(stack_start)
    .long init_thread_union+THREAD_SIZE
    .long __BOOT_DS
----------------------------------------------------

针对汇编指令 lss, 根据Intel的手册“Software Developer’s Manual,Volume 2A:Instruction Set Reference, A-M”,其中有说明如下:

------------------------------------------------------------------------------------------------------------
Loads a far pointer (segment selector and offset) from the second operand (source
operand) into a segment register and the first operand (destination operand). The
source operand specifies a 48-bit or a 32-bit pointer in memory depending on the
current setting of the operand-size attribute (32 bits or 16 bits, respectively). The
instruction opcode and the destination operand specify a segment register/general-
purpose register pair. The 16-bit segment selector from the source operand is loaded
into the segment register specified with the opcode (DS, SS, ES, FS, or GS). The
32-bit or 16-bit offset is loaded into the register specified with the destination
operand.
------------------------------------------------------------------------------------------------------------

根据上面的说明,源操作数 stack_start 是否应该定义为48位的:

--------------------------------------------
ENTRY(stack_start)
    .long init_thread_union+THREAD_SIZE
    .word __BOOT_DS
--------------------------------------------

但是现在内核中定义为2个long,是64位的,是否有问题?

作者: JackyBsh   发布时间: 2011-02-27

回复 JackyBsh


    难道是地址对齐?

作者: cluter   发布时间: 2011-02-28

回复 JackyBsh
lss 只会取用stack_start地址向后48bit,并且x86是little-endian, 所以第二个.long的高16bit没被用到
看下内核extern出的stack_start
42 /* Static state in head.S used to set up a CPU */
43 extern struct {
44         void *sp;
45         unsigned short ss;
46 } stack_start;

作者: chobit_s   发布时间: 2011-02-28