Note that there are some explanatory texts on larger screens.

plurals
  1. POabout linux v0.01 bootsect.S
    text
    copied!<p>Recently I'm looking at the linux 0.01 source code, since the bootsect.S in 2.6.11 and upper version is useless and it is a good place to start learning linux code, therefore I choose to trace the first version of linux. :P</p> <p>I have some question in bootsect.S. The following is some of the code in bootsect.S linux v 0.01.</p> <p>P.S the first version assembly code is using intel syntax instead of at&amp;t.</p> <pre><code>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. </code></pre> <p>gdt: </p> <pre><code>.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 </code></pre> <p>The booting process seems to be like the following:</p> <ul> <li><p>move the bootloader code from 0x7c00 to 0x9000</p></li> <li><p>jumps to 0x9000</p></li> <li><p>set the segment registers.</p></li> <li><p>load the system code to 0x10000 (the system code contains boot/head.S and init/main.c according to the Makefile)</p></li> <li><p>load temporary gdt and idt with lgdt and lidt</p></li> <li><p>enable A20 to access the 16mb physical memory.</p></li> <li><p>set cr0 PE bit to go to protected mode</p></li> <li><p>jump to 0x000000</p></li> </ul> <p>the following is the Makefile for system:</p> <pre><code>tools/system: boot/head.o init/main.o \ $(ARCHIVES) $(LIBS) $(LD) $(LDFLAGS) boot/head.o init/main.o \ $(ARCHIVES) \ $(LIBS) \ -o tools/system &gt; System.map </code></pre> <p>It seems like that the head.S and main.c is link together as the system binary which the bootsect loads into memory.</p> <p>My question is if the system code(which entry is head.S/startup_32 ) is loaded in 0x10000 than why not jumps to 0x10000 instead jumps to 0x000000? Isn't it weird to jump to 0x0 since there is no code loaded inside there??</p> <p>the following is the link to download the source code: <a href="https://docs.google.com/viewer?a=v&amp;pid=explorer&amp;chrome=true&amp;srcid=0B1F0m2rUn8BYMjQ4ZDQxZTUtODI5My00MGZiLTgwZDQtM2ZiZWQ2ZWQxYzIx" rel="nofollow">https://docs.google.com/viewer?a=v&amp;pid=explorer&amp;chrome=true&amp;srcid=0B1F0m2rUn8BYMjQ4ZDQxZTUtODI5My00MGZiLTgwZDQtM2ZiZWQ2ZWQxYzIx</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload