2011-10-02 55 views
1

最近我在看linux 01的源代码,因为2.6.11和更高版本的bootsect.S是无用的,因此它是开始学习linux代码的好地方,因此我选择跟踪Linux的第一个版本。 :P关于linux v0.01 bootsect.S

我在bootsect.S中有一些问题。以下是bootsect.S linux v 0.01中的一些代码。

P.S第一个版本的汇编代码使用的是intel语法,而不是在& t。

mov ax,#0x0001 | protected mode (PE) bit 
lmsw ax   | This is it! 
jmpi 0,8 | jmp offset 0 of segment 8 (cs) which is the second entry of the gdt. 

GDT:

.word 0,0,0,0  | dummy 
.word 0x07FF  | 8Mb - limit=2047 (2048*4096=8Mb) 
.word 0x0000  | base address=0 
.word 0x9A00  | code read/exec 
.word 0x00C0  | granularity=4096, 386 

.word 0x07FF  | 8Mb - limit=2047 (2048*4096=8Mb) 
.word 0x0000  | base address=0 
.word 0x9200  | data read/write 
.word 0x00C0  | granularity=4096, 386 

引导过程似乎是这样的:

  • 移动的引导程序从0x7c00到0×9000

  • 代码跳转到0×9000

  • 设置段寄存器。

  • 负载系统代码为0x10000 (系统代码包含启动/ head.S中和init/main.c中根据生成文件)

  • 负载临时GDT和IDT与LGDT和LIDT

  • 使A20能够访问16MB物理内存。

  • 组CR0的PE位去保护模式

  • 跳转到0x000000处

下面是Makefile文件系统:

tools/system: 
boot/head.o init/main.o \ 
$(ARCHIVES) $(LIBS) 
$(LD) $(LDFLAGS) boot/head.o init/main.o \ 
$(ARCHIVES) \ 
$(LIBS) \ 

-o tools/system > System.map 

好像头部.S和main.c作为bootsect加载到内存中的系统二进制文件链接在一起。

我的问题是如果系统代码(哪个条目是head.S/startup_32)加载在0x10000比为什么不跳转到0x10000而是跳转到0x000000? 跳到0x0是不是很奇怪,因为里面没有加载代码?

以下是下载源代码的链接: https://docs.google.com/viewer?a=v&pid=explorer&chrome=true&srcid=0B1F0m2rUn8BYMjQ4ZDQxZTUtODI5My00MGZiLTgwZDQtM2ZiZWQ2ZWQxYzIx

+0

一个链接到源将本来不错:) – sehe

+0

我添加一个下载链接到帖子。 tks的回复:) – mike820324

回答

1

这里的答案:

| It then loads the system at 0x10000, using BIOS interrupts. Thereafter 
| it disables all interrupts, moves the system down to 0x0000, ... 

,这里是连同它的代码:

 cli      | no interrupts allowed ! 

| first we move the system to it's rightful place 

     mov  ax,#0x0000 
     cld      | 'direction'=0, movs moves forward 
do_move: 
     mov  es,ax   | destination segment 
     add  ax,#0x1000 
     cmp  ax,#0x9000 
     jz  end_move 
     mov  ds,ax   | source segment 
     sub  di,di 
     sub  si,si 
     mov  cx,#0x8000 
     rep 
     movsw 
     j  do_move 

如果您仔细看代码,你会注意到它确实开始做ES = 0,DI = 0(目标)和DS = 0x1000,SI = 0(源)的REP MOVSW,也就是说,从0x10000(= DS * 0x10 + SI)到0(= ES * 0x10 + DI)的容量。

+0

tks,它解决了我的问题。 :d – mike820324