/sys/i386/i386/locore.s分析笔记

2009-05-13 14:46:14来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

kernel的入口地址是/sys/i386/i386/locore.s中定义的btext:
200  /**********************************************************************
201   *
202   * This is where the bootblocks start us, set the ball rolling...
203   *
204   */
205  NON_GPROF_ENTRY(btext)
从/boot/kernel/kernel中可以读出btext的链接地址:
# readelf -a /boot/kernel/kernel | grep btext
  6870: c0458a30     0 FUNC    GLOBAL DEFAULT    5 btext
26381: c0458a30     0 FUNC    GLOBAL DEFAULT    5 btext
因此,在物理地址0x458a30处设置断点,单步跟踪locore.s中的初始化代码。程序运行至此
的cpu主要寄存器的内容如下:
rax: 0x00000000:00458a30 rcx: 0x00000000:a0200000
rdx: 0x00000000:000488a0 rbx: 0x00000000:00458a30
rsp: 0x00000000:0009e844 rbp: 0x00000000:00094884
rsi: 0x00000000:000610e4 rdi: 0x00000000:0005b9cc
r8 : 0x00000000:00000000 r9 : 0x00000000:00000000
r10: 0x00000000:00000000 r11: 0x00000000:00000000
r12: 0x00000000:00000000 r13: 0x00000000:00000000
r14: 0x00000000:00000000 r15: 0x00000000:00000000
rip: 0x00000000:00458a30
eflags 0x00000002
首先是向0x472写入0x1234,告知bios下次为热引导:
216  /* Tell the bios to warmboot next time */
217          movw    $0x1234,0x472
构建一个新的栈帧:
220  /* Set up a real frame in case the double return in newboot is executed. */
221          pushl   %ebp
222          movl    %esp, %ebp
此时cpu主要寄存器的内容如下:
rax: 0x00000000:00458a30 rcx: 0x00000000:a0200000
rdx: 0x00000000:000488a0 rbx: 0x00000000:00458a30
rsp: 0x00000000:0009e840 rbp: 0x00000000:0009e840
rsi: 0x00000000:000610e4 rdi: 0x00000000:0005b9cc
r8 : 0x00000000:00000000 r9 : 0x00000000:00000000
r10: 0x00000000:00000000 r11: 0x00000000:00000000
r12: 0x00000000:00000000 r13: 0x00000000:00000000
r14: 0x00000000:00000000 r15: 0x00000000:00000000
rip: 0x00000000:00458a3c
eflags 0x00000002
将PSL_KRENEL赋给eflags:
224  /* Don't trust what the BIOS gives for eflags. */
225          pushl   $PSL_KERNEL
226          popfl
PSL_KERNEL是在/sys/i386/include/psl.h中定义的:
60  /*
61   * The i486 manual says that we are not supposed to change reserved flags,
62   * but this is too much trouble since the reserved flags depend on the cpu
63   * and setting them to their historical values works in practice.
64   */
65  #define PSL_RESERVED_DEFAULT    0x00000002
66
67  /*
68   * Initial flags for kernel and user mode.  The kernel later inherits

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:/sys/i386/include/pmap.h中与页表相关宏值的含义

下一篇:init386之前的地址空间和页表结构示意图