关于linux内核中大内核的向保护模式切换的一个细节

同样是从老BLOG上导入的早期文章也懒得再核对 只是做个记录

关于linux的setup.s向保护模式切换的个人看法-----如果有错 欢迎大家拍砖 :)

注意到网上关于内核中setup.s中向保护模式切换的论述含糊其辞。尤其对大内核情况下,如何转跳进head.s的一小段代码的分析颇多错误(个人感觉)。说一下自己对此的看法。---------------------

关于linux2.4 /2.6内核中setup.s中下面代码段的理解

.byte 0x66, 0xea           # prefix + jmpi-opcode
code32: .long 0x1000   # will be set to 0x100000
                                     # for big kernels
 .word __KERNEL_CS
对于linux的这句注释# will be set to 0x100000 for big kernels
是因为code32: .long 0x1000 在执行的时候(存放在内存的时候)
code32的值会被下面的语句篡改。

rmodeswtch_end:
# we get the code32 start address and modify the below 'jmpi'
# (loader may have changed it)
 movl %cs:code32_start, %eax
 movl %eax, %cs:code32

也就是说code32标记处的0x1000会被code32_start处的数据替换掉
而code32_start则会有两种情况 见下面代码

code32_start:    # here loaders can put a different
     # start address for 32-bit code.
#ifndef __BIG_KERNEL__
  .long 0x1000  #   0x1000 = default for zImage
#else
  .long 0x100000 # 0x100000 = default for big kernel
#endif

一种是当内核为小内核时候 是0x1000,这种情况下,替换后code32依然还是0x1000。
因为是被同样的数字替换(覆盖)。
另一种情况是内核为大内核的时候 code32_start为0x100000,这种情况下,替换后
code32变成了0x100000。这个时候前面说的代码段

.byte 0x66, 0xea   
code32: .long 0x1000   
 .word __KERNEL_CS
实际变成了
.byte 0x66, 0xea   
code32: .long 0x100000   #被code32_start替换成了0x100000   

 .word __KERNEL_CS 

posted @ 2010-01-13 18:20  woody.su  阅读(357)  评论(0编辑  收藏  举报