在 2008-06-05四的 15:32 +0530，Chetan Nanda写道：
> Hi All,
> I was reading the boot code for MIPS.
> in head.S file before jumping to 'start_kernel' it calculate the stack
> pointer address as follow:
> PTR_LA $28, init_thread_union
> PTR_ADDIU sp, $28, _THREAD_SIZE - 32
make sp point to the stack top so that we can allocate stack space
later, -32 is a reserved area for local variable, saved GPR, arguments
(function stack frame).. due to the abi
> set_saved_sp sp, t0, t1
set_saved_sp is defined (as a assembler macro) in
include/asm-mips/stackframe.h (if you're using vim, I think it will be
easy to use vim with cscope..)
> PTR_SUBU sp, 4 * SZREG # init stack pointer
SZREG is defined to the general purpose register size, it is 32bit in
MIPS32 and 64bit in MIPS64, so the last line allocates 16/32 bytes to
build a stack frame.. You could refer to the MIPS ABI if you need
further information (the kernel don't follow the standard ABI all the
> Can anyone please explains me this 4 lines of code?
> Why ' _THREAD_SIZE - 32' is added in 'sp' ?
> What 'set_saved_sp' will do ?
> and then why we subtract '4 * SZREG' from 'sp' ?
> Please hep me to understand this code better.
> Chetan Nanda
Wang, Baojun Lanzhou University
Distributed & Embedded System Lab http://dslab.lzu.edu.cn
School of Information Science and Engeneering firstname.lastname@example.org
Tianshui South Road 222. Lanzhou 730000 .P.R.China
Tel: +86-931-8912025 Fax: +86-931-8912022
Description: =?gb2312?Q?=D5=E2=CA=C7=D0=C5=BC=FE=B5=C4=CA=FD=D7=D6=C7=A9?= =?gb2312?Q?=C3=FB=B2=BF=B7=D6?=