Linux内核分析方法谈(2)
II、实模式下的初始化实模式下的初始化,主要是指从内核引导成功后,到进入保护模式之前系统所做的一些处理。在内核源码中对应的程序是 /Arch/i386/boot/setup.S;以下部分主要是针对此文件进行的分析。这部分的分析主要是要弄懂它的处理流程和INITSEG(9000:0000)段参数表的建立,此参数表包含了很多硬件参数,这些都是以后进行保护模式下初始化,以及核心建立的基础。
1. 几个其它相关文件:
<1> /Arch/i386/boot/bootsect.S
<2> /include/linux/config.h
<3> /include/asm/boot.h
<4> /include/ asm/segment.h
<5> /include/linux/version.h
<6> /include/linux/compile.h
2. 实模式下的初始化过程分析:
INITSEG(9000:0000)段参数表:(参见Include/linux/tty.h)
参数名 | 偏移量(段址均为0x9000) | 长度Byte | 参考文件 |
PARAM_CURSOR_POS | 0x0000 | 2 | Arch/i386/boot/video.S |
extended mem Size | 0x0002 | 2 | Arch/i386/boot/setup.S |
PARAM_VIDEO_PAGE | 0x0004 | 2 | Arch/i386/boot/video.S |
PARAM_VIDEO_MODE | 0x0006 | 1 | Arch/i386/boot/video.S |
PARAM_VIDEO_COLS | 0x0007 | 1 | Arch/i386/boot/video.S |
没用 | 0x0008 | 2 | Include/linux/tty.h |
PARAM_VIDEO_EGA_BX | 0x000a | 2 | Arch/i386/boot/video.S |
没用 | 0x000c | 2 | Include/linux/tty.h |
PARAM_VIDEO_LINES | 0x000e | 1 | Arch/i386/boot/video.S |
PARAM_HAVE_VGA | 0x000f | 1 | Arch/i386/boot/video.S |
PARAM_FONT_POINTS | 0x0010 | 2 | Arch/i386/boot/video.S |
PARAM_LFB_WIDTH | 0x0012 | 2 | Arch/i386/boot/video.S |
PARAM_LFB_HEIGHT | 0x0014 | 2 | Arch/i386/boot/video.S |
PARAM_LFB_DEPTH | 0x0016 | 2 | Arch/i386/boot/video.S |
PARAM_LFB_BASE | 0x0018 | 4 | Arch/i386/boot/video.S |
PARAM_LFB_SIZE | 0x001c | 4 | Arch/i386/boot/video.S |
暂未用① | 0x0020 | 4 | Include/linux/tty.h |
PARAM_LFB_LINELENGTH | 0x0024 | 2 | Arch/i386/boot/video.S |
PARAM_LFB_COLORS | 0x0026 | 6 | Arch/i386/boot/video.S |
暂未用② | 0x002c | 2 | Arch/i386/boot/video.S |
PARAM_VESAPM_SEG | 0x002e | 2 | Arch/i386/boot/video.S |
PARAM_VESAPM_OFF | 0x0030 | 2 | Arch/i386/boot/video.S |
PARAM_LFB_PAGES | 0x0032 | 2 | Arch/i386/boot/video.S |
保留 | 0x0034--0x003f | Include/linux/tty.h | |
APM BIOS Version③ | 0x0040 | 2 | Arch/i386/boot/setup.S |
BIOS code segment | 0x0042 | 2 | Arch/i386/boot/setup.S |
BIOS entry offset | 0x0044 | 4 | Arch/i386/boot/setup.S |
BIOS 16 bit code seg | 0x0048 | 2 | Arch/i386/boot/setup.S |
BIOS data segment | 0x004a | 2 | Arch/i386/boot/setup.S |
支持32位标志④ | 0x004c | 2 | Arch/i386/boot/setup.S |
BIOS code seg length | 0x004e | 4 | Arch/i386/boot/setup.S |
BIOS data seg length | 0x0052 | 2 | Arch/i386/boot/setup.S |
hd0 参数 | 0x0080 | 16 | Arch/i386/boot/setup.S |
hd0 参数 | 0x0090 | 16 | Arch/i386/boot/setup.S |
PS/2 device 标志⑤ | 0x01ff | 1 | Arch/i386/boot/setup.S |
* 注: ① Include/linux/tty.h : CL_MAGIC and CL_OFFSET here
Include/linux/tty.h :
unsigned char rsvd_size; /* 0x2c */
unsigned char rsvd_pos; /* 0x2d */
③ 0表示没有APM BIOS
④ 0x0002置位表示支持32位模式
⑤ 0表示没有,0x0aa表示有鼠标器
III、保护模式下的初始化
保护模式下的初始化,是指处理机进入保护模式后到运行系统第一个内核程序过程中系统所做的一些处理。保护模式下的初始化在内核源码中对应的程序是 /Arch/i386/boot/compressed/head.S 和 /Arch/i386/KERNEL/head.S ;以下部分主要是针对这两个文件进行的分析。
几个相关文件:
<1.> /Arch/i386/boot/compressed/head.S
<2.> /Arch/i386/KERNEL/head.S
<3.> //Arch/i386/boot/compressed/MISC.c
<4.> /Arch/i386/boot/setup.S
<5.> /include/ asm/segment.h
<6.> /arch/i386/kernel/traps.c
<7.> /include/i386/desc.h
<8.> /include/asm-i386/processor.h
保护模式下的初始化过程分析:
一、/Arch/i386/KERNEL/head.S流程:
二、/Arch/i386/boot/compressed/head.S流程:
从流程图中可以看到,保护模式