1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
<html>
<body bgcolor=#ffffff text=#000000 link=#4f4fff vlink=#0000ff alink=#00ff00>
<h1>Technical information</h1>
The primary purpose of this section of the documentation is to be a source of information for those who want to make their enhancements to chos, but is also an source of information for anyone interested in how things work.
<br><b>There's a lot to do in here.</b>
<ul>
<li><a href="#bprocess">The boot process</a>
<li><a href="#modules">Modules</a>
<li><a href="#references">References</a>
<li><a href="initrd.html">Initial ramdisk</a>
</ul>
<a name="bprocess">
<p><h2>The boot process</h2>
<ol>
<li><b>The BIOS</b> loads the MBR at 0x7c00 (0x07c0:0000) and jumps there.<br>
(MBR <i>(Master Boot Record)</i> is the very first sector on storage devices. Normally bios first tries to boot off fd0 and then hda, but the sequence can usually be configured. Some bioses (at least mine) can also boot off an IDE CD.)
<li><b>Chos bootsector:</b>
<ol>
<li>First, if mbr rewrite is enabled, a safe copy of it will be made at 0x6000.
(Data in the version at 0x7c00 will be modified and we don't wanna save the changes
on disk.)
<li> 5 sectors of 2nd stage loader will be loaded at 0x8000 (<b>STAGE2_OFF</b>)
<li> 2 sectors of mapfile will be loaded right after it (at <b>DATA_OFF</b> and <b>IMAGES_OFF</b>) .
<li> Now it'll jump to the second stage loader
</ol>
<li><b>2nd stage loader:</b>
<ol>
<li>State of '<i>single-shot autoboot</i>' will be checked.
If it is enabled, the flag will be cleared and first mapfile sector will be rewritten on disk.
Proceed to step 3.5
<li>First the state of <i>autoboot</i> will be checked.
If it matches with the modifier keys pressed, proceed to step 3.5.
<li>The background file will be loaded at text video memory (0xb8000) and the image names will be printed on screen.
<li>Now the loader will just wait for user to choose an image to start.
If there's no user input in given number of seconds, the first image will be chosen.
<li>Once the image to be started is known, the 2nd stage loader will
first determine the required OS-specific loader and load it at 0x9000 (<b>LOADER_OFF</b>).
After that, the sector specified by <i>MF_ImageDes::device</i> and <i>MF_ImageDes::addr</i>
will be loaded at 0x8e00 (<b>MAP_OFF</b>).
<li>Control will be transferred to the OS-specific loader by jumping at 0x9000.
</ol>
<li><b>OS-specific loader.</b>
Currently available are the bootsector loader and Linux loader:
<ul>
<li><b>The bootsector loader:</b>
<ol>
<li> The bootsector will be moved from <b>MAP_OFF</b> to it's rightful place at 0x7c00.
<li> If the partition table will be rewritten, now it's time to do that.
<li> If any drives will be swapped, new int13h handler will be installed at this point.
<li> If dos4boot is enabled, a flag in the bootsector at 0x7c00 will be set.
<li> Jump to the OS's bootsector at 0x7c00.
</ol>
<li><b>The Linux loader:</b>
<ol>
<li> If the image was started with <i>space</i>, let the user enter a new command line over the default at MAP_OFF+0x10..
<li> Process the command line. (Handle '<i>vga=</i>' and copy rest at INIT_SEG::0xdc00.)<br>
Append '<i>auto</i>' at the end of the command line if started automagically (i.e. with default command line).<br>
Append '<i>BOOT_IMAGE=<IMAGE_NAME></i>' at the end of the command line.
<li> Load initial ramdisk at given address if one's to be loaded.
<li> Load linux bootsector at INITSEG and setup variables there.
<li> Load linux setup sectors at SETUPSEG.
<li> In case of zImage, load the kernel at 0x10000.
In case of bzImage load it at 0x100000 (1M).
<li> And now it's time the enter Linux at SETUPSEG::0.
</ol>
</ul>
</ol>
<p>
<a name="modules">
<p><h2>Modules</h2>
Choose-OS supports OS-specific loader modules. Bootsector and Linux loaders exist at the moment.
A loader module must begin with the following:
<blockquote><pre>
.globl _main
.org LOADER_OFF
_main: jmp real_entry_point_of_this_module
.org LOADER_OFF+2
chos_id: .ascii "CHO"
chos_stage: .byte BIT_xxx|0x10
chos_major: .byte CHOS_MAJOR
chos_minor: .byte CHOS_MINOR
...
real_entry_point_of_this_module:
</pre></blockquote>
<b>LOADER_OFF</b> is 0x9000, so the assembled/compiled loader will be big, but the extra 0x9000
bytes+32 bytes of header will be stripped from the final raw loader. This way the OS-specific loaders can use the same segment as the 2nd stage loader - which is compiled at 0x8000 - does.
<p>A loader is also required to include <i>chos/module.h</i>, which defines the addresses for
2nd stage loader exported variables and function pointer table entries.
Such functions should be called with the <b>CALL(</b><i>FN_NAME</i><b>)</b> macro.
Variables can be accessed normally.
<p>
<a name="references">
<p><h2>References</h2>
Here are some good sources of information:
<ul>
<li> Help-PC
<li> LILO documentation
<li> Almost any PC BIOS programming book
</ul>
</html>
|