templeos-info/public/Wb/Kernel/KStart16.HC.HTML

238 lines
32 KiB
HTML
Executable File

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="generator" content="TempleOS V5.03">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="/style/templeos.css">
<script src="/script/templeos.js"></script>
<style type="text/css">
.cF0{color:#000000;background-color:#ffffff;}
.cF1{color:#0000aa;background-color:#ffffff;}
.cF2{color:#00aa00;background-color:#ffffff;}
.cF3{color:#00aaaa;background-color:#ffffff;}
.cF4{color:#aa0000;background-color:#ffffff;}
.cF5{color:#aa00aa;background-color:#ffffff;}
.cF6{color:#aa5500;background-color:#ffffff;}
.cF7{color:#aaaaaa;background-color:#ffffff;}
.cF8{color:#555555;background-color:#ffffff;}
.cF9{color:#5555ff;background-color:#ffffff;}
.cFA{color:#55ff55;background-color:#ffffff;}
.cFB{color:#55ffff;background-color:#ffffff;}
.cFC{color:#ff5555;background-color:#ffffff;}
.cFD{color:#ff55ff;background-color:#ffffff;}
.cFE{color:#ffff55;background-color:#ffffff;}
.cFF{color:#ffffff;background-color:#ffffff;}
</style>
</head>
<body>
<pre id="content">
<a name="l1"></a><span class=cF1>asm</span><span class=cF0> {</span><span class=cF2>/* See </span><a href="/Wb/Doc/Boot.DD.HTML#l1"><span class=cF4>::/Doc/Boot.DD</span></a><span class=cF2>.</span><span class=cF0>
<a name="l2"></a></span><span class=cF2>TempleOS starts in real, calls some BIOS</span><span class=cF0>
<a name="l3"></a></span><span class=cF2>routines, switches to 32 bit, and 64 bit mode</span><span class=cF0>
<a name="l4"></a></span><span class=cF2>and continues in </span><a href="/Wb/Doc/HolyC.DD.HTML#l1"><span class=cF4>HolyC</span></a><span class=cF2> at </span><a href="/Wb/Kernel/KMain.HC.HTML#l135"><span class=cF4>KMain</span></a><span class=cF2>().</span><span class=cF0>
<a name="l5"></a>
<a name="l6"></a></span><span class=cF2>The boot loader jumps here in real-mode (16-bit).</span><span class=cF0>
<a name="l7"></a></span><span class=cF2>It actually jumps to the </span><a href="/Wb/Kernel/KernelA.HH.HTML#l384"><span class=cF4>CBinFile</span></a><span class=cF2> header which is</span><span class=cF0>
<a name="l8"></a></span><span class=cF2>placed just before this by </span><a href="/Wb/Compiler/CMain.HC.HTML#l537"><span class=cF4>the compiler</span></a><span class=cF2>.</span><span class=cF0>
<a name="l9"></a></span><span class=cF2>The header begins with a short jmp to</span><span class=cF0>
<a name="l10"></a></span><span class=cF2>the start of this file's code which begins</span><span class=cF0>
<a name="l11"></a></span><span class=cF2>with the following small jump past some data.</span><span class=cF0>
<a name="l12"></a>
<a name="l13"></a></span><span class=cF2>This file is first in the Kernel image</span><span class=cF0>
<a name="l14"></a></span><span class=cF2>because it is #included first. </span><a href="/Wb/Kernel/Kernel.PRJ.HTML#l14"><span class=cF4>Kernel.PRJ</span></a><span class=cF0>
<a name="l15"></a></span><span class=cF2>*/</span><span class=cF0>
<a name="l16"></a></span><span class=cF1>USE16</span><span class=cF0>
<a name="l17"></a></span><span class=cFD>SYS_KERNEL</span><span class=cF0>:: </span><span class=cF2>//This must match </span><a href="/Wb/Kernel/KernelA.HH.HTML#l430"><span class=cF4>CKernel</span></a><span class=cF2>.</span><span class=cF0>
<a name="l18"></a> </span><span class=cF1>JMP</span><span class=cF0> </span><span class=cF9>I16</span><span class=cF0> </span><span class=cFD>CORE0_16BIT_INIT</span><span class=cF0>
<a name="l19"></a>
<a name="l20"></a></span><span class=cF2>//************************************</span><span class=cF0>
<a name="l21"></a></span><span class=cF2>// ASM Global vars required for 16-bit start-up</span><span class=cF0>
<a name="l22"></a> </span><span class=cF1>ALIGN</span><span class=cF0> 4,</span><span class=cF3>OC_NOP</span><span class=cF0>
<a name="l23"></a></span><span class=cFD>SYS_BOOT_SRC</span><span class=cF0>:: </span><span class=cF1>DU32</span><span class=cF0> </span><span class=cF3>BOOT_SRC_NULL</span><span class=cF0>;
<a name="l24"></a></span><span class=cFD>SYS_BOOT_BLK</span><span class=cF0>:: </span><span class=cF1>DU32</span><span class=cF0> 0;
<a name="l25"></a></span><span class=cFD>SYS_BOOT_PATCH_TABLE_BASE</span><span class=cF0>:: </span><span class=cF1>DU32</span><span class=cF0> 0;
<a name="l26"></a></span><span class=cFD>SYS_RUN_LEVEL</span><span class=cF0>:: </span><span class=cF1>DU32</span><span class=cF0> 0;
<a name="l27"></a>#</span><span class=cF1>exe</span><span class=cF0> </span><span class=cF7>{</span><span class=cF5>StreamPrint</span><span class=cF0>(</span><span class=cF6>&quot;SYS_COMPILE_TIME:: DU64 0x%X;&quot;</span><span class=cF0>,</span><span class=cF5>Now</span><span class=cF0>);</span><span class=cF7>}</span><span class=cF0> </span><span class=cF2>//See </span><a href="/Wb/Kernel/BlkDev/DskATAId.HC.HTML#l1"><span class=cF4>BootDVDProbe</span></a><span class=cF0>
<a name="l28"></a>#</span><span class=cF1>assert</span><span class=cF0> </span><span class=cFD>SYS_COMPILE_TIME</span><span class=cF0>+</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CDate</span><span class=cF0>)+</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CBinFile</span><span class=cF0>)&lt;</span><span class=cF3>DVD_BLK_SIZE</span><span class=cF0>
<a name="l29"></a>
<a name="l30"></a></span><span class=cFD>MEM_BOOT_BASE</span><span class=cF0>:: </span><span class=cF1>DU32</span><span class=cF0> 0; </span><span class=cF2>//Offset from start used by reboot</span><span class=cF0>
<a name="l31"></a></span><span class=cFD>MEM_E801</span><span class=cF0>:: </span><span class=cF1>DU16</span><span class=cF0> 0,0;
<a name="l32"></a></span><span class=cFD>MEM_E820</span><span class=cF0>:: </span><span class=cF1>DU8</span><span class=cF0> </span><span class=cF3>MEM_E820_ENTRIES_NUM</span><span class=cF0>*</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CMemE820</span><span class=cF0>) </span><span class=cF1>DUP</span><span class=cF0> (0);
<a name="l33"></a></span><span class=cFD>MEM_PHYSICAL_SPACE</span><span class=cF0>:: </span><span class=cF1>DU64</span><span class=cF0> 0;
<a name="l34"></a></span><span class=cFD>SYS_GDT_PTR</span><span class=cF0>:: </span><span class=cF1>DU16</span><span class=cF0> </span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CGDT</span><span class=cF0>)-1;
<a name="l35"></a> </span><span class=cF1>DU64</span><span class=cF0> 0;
<a name="l36"></a></span><span class=cFD>SYS_PCI_BUSES</span><span class=cF0>:: </span><span class=cF1>DU16</span><span class=cF0> 0;
<a name="l37"></a>
<a name="l38"></a> </span><span class=cF1>ALIGN</span><span class=cF0> 16,</span><span class=cF3>OC_NOP</span><span class=cF0>
<a name="l39"></a></span><span class=cFD>SYS_GDT</span><span class=cF0>:: </span><span class=cF2>//See </span><a href="/Wb/Kernel/KernelA.HH.HTML#l348"><span class=cF4>CGDT</span></a><span class=cF0>
<a name="l40"></a>GDT_NULL: </span><span class=cF1>DU64</span><span class=cF0> 0,0;
<a name="l41"></a>GDT_BOOT_DS: </span><span class=cF1>DU64</span><span class=cF0> 0x00CF92000000FFFF,0; </span><span class=cF2>//Gets patched.</span><span class=cF0>
<a name="l42"></a>GDT_BOOT_CS: </span><span class=cF1>DU64</span><span class=cF0> 0x00CF9A000000FFFF,0; </span><span class=cF2>//Gets patched.</span><span class=cF0>
<a name="l43"></a>GDT_CS32: </span><span class=cF1>DU64</span><span class=cF0> 0x00CF9A000000FFFF,0;
<a name="l44"></a>GDT_CS64: </span><span class=cF1>DU64</span><span class=cF0> 0x00209A0000000000,0; </span><span class=cF2>//The </span><a href="/Wb/Doc/Charter.DD.HTML#l1"><span class=cF4>Charter</span></a><span class=cF2> says just ring0.</span><span class=cF0>
<a name="l45"></a>GDT_CS64_RING3: </span><span class=cF1>DU64</span><span class=cF0> 0x0020FA0000000000,0; </span><span class=cF2>//</span><a href="/Wb/Demo/Lectures/Ring3.HC.HTML#l1"><span class=cF4>Ring3</span></a><span class=cF2>, so you can play with.</span><span class=cF0>
<a name="l46"></a>GDT_DS: </span><span class=cF1>DU64</span><span class=cF0> 0x00CF92000000FFFF,0;
<a name="l47"></a>GDT_DS_RING3: </span><span class=cF1>DU64</span><span class=cF0> 0x00CFF2000000FFFF,0;
<a name="l48"></a>GDT_TR: </span><span class=cF1>DU8</span><span class=cF0> </span><span class=cF3>MP_PROCESSORS_NUM</span><span class=cF0>*16 </span><span class=cF1>DUP</span><span class=cF0>(0);
<a name="l49"></a>GDT_TR_RING3: </span><span class=cF1>DU8</span><span class=cF0> </span><span class=cF3>MP_PROCESSORS_NUM</span><span class=cF0>*16 </span><span class=cF1>DUP</span><span class=cF0>(0);
<a name="l50"></a>#</span><span class=cF1>assert</span><span class=cF0> $-</span><span class=cFD>SYS_GDT</span><span class=cF0>==</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CGDT</span><span class=cF0>)
<a name="l51"></a>
<a name="l52"></a>#</span><span class=cF1>assert</span><span class=cF0> $-</span><span class=cFD>SYS_KERNEL</span><span class=cF0>==</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CKernel</span><span class=cF0>)-</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CBinFile</span><span class=cF0>)
<a name="l53"></a>
<a name="l54"></a></span><span class=cF2>//************************************</span><span class=cF0>
<a name="l55"></a></span><span class=cFD>CORE0_16BIT_INIT</span><span class=cF0>::
<a name="l56"></a></span><span class=cF2>//EAX is </span><a href="/Wb/Kernel/KStart16.HC.HTML#l165"><span class=cF4>SYS_BOOT_SRC</span></a><span class=cF2>. (Val passed from boot blk, </span><a href="/Wb/Adam/Opt/Boot/BootHD.HC.HTML#l86"><span class=cF4>BootHD</span></a><span class=cF2>, </span><a href="/Wb/Adam/Opt/Boot/BootDVD.HC.HTML#l180"><span class=cF4>BootDVD</span></a><span class=cF2>, &amp; </span><a href="/Wb/Adam/Opt/Boot/BootRAM.HC.HTML#l46"><span class=cF4>BootRAM</span></a><span class=cF2>.)</span><span class=cF0>
<a name="l57"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>ECX</span><span class=cF0>,</span><span class=cFC>EAX</span><span class=cF0>
<a name="l58"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>AX</span><span class=cF0>,(</span><span class=cF3>BOOT_RAM_LIMIT</span><span class=cF0>-</span><span class=cF3>BOOT_STK_SIZE</span><span class=cF0>)/16
<a name="l59"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>SS</span><span class=cF0>,</span><span class=cFC>AX</span><span class=cF0>
<a name="l60"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>SP</span><span class=cF0>,</span><span class=cF3>BOOT_STK_SIZE</span><span class=cF0>
<a name="l61"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cFC>ECX</span><span class=cF0> </span><span class=cF2>//Will be </span><a href="/Wb/Kernel/KStart16.HC.HTML#l165"><span class=cF4>SYS_BOOT_SRC</span></a><span class=cF2>. See </span><a href="/Wb/Adam/Opt/Boot/BootHD.HC.HTML#l86"><span class=cF4>BootHD</span></a><span class=cF2>, </span><a href="/Wb/Adam/Opt/Boot/BootDVD.HC.HTML#l180"><span class=cF4>BootDVD</span></a><span class=cF2> &amp; </span><a href="/Wb/Adam/Opt/Boot/BootRAM.HC.HTML#l46"><span class=cF4>BootRAM</span></a><span class=cF2>.</span><span class=cF0>
<a name="l62"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cFC>EBX</span><span class=cF0>
<a name="l63"></a>
<a name="l64"></a> </span><span class=cF1>CALL</span><span class=cF0> </span><span class=cF9>U16</span><span class=cF0> GET_RIP
<a name="l65"></a>GET_RIP: </span><span class=cF1>POP</span><span class=cF0> </span><span class=cFC>BX</span><span class=cF0>
<a name="l66"></a> </span><span class=cF1>SUB</span><span class=cF0> </span><span class=cFC>BX</span><span class=cF0>,GET_RIP
<a name="l67"></a> </span><span class=cF1>SHR</span><span class=cF0> </span><span class=cFC>BX</span><span class=cF0>,4
<a name="l68"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>AX</span><span class=cF0>,</span><span class=cFC>CS</span><span class=cF0>
<a name="l69"></a> </span><span class=cF1>ADD</span><span class=cF0> </span><span class=cFC>AX</span><span class=cF0>,</span><span class=cFC>BX</span><span class=cF0>
<a name="l70"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cFC>AX</span><span class=cF0>
<a name="l71"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cF9>U16</span><span class=cF0> @@05
<a name="l72"></a> </span><span class=cF1>RETF</span><span class=cF0>
<a name="l73"></a>
<a name="l74"></a>@@05: </span><span class=cF1>STI</span><span class=cF0>
<a name="l75"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>AX</span><span class=cF0>,</span><span class=cFC>CS</span><span class=cF0>
<a name="l76"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>DS</span><span class=cF0>,</span><span class=cFC>AX</span><span class=cF0>
<a name="l77"></a>
<a name="l78"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> [</span><span class=cFD>SYS_RUN_LEVEL</span><span class=cF0>],</span><span class=cF3>RLF_16BIT</span><span class=cF0>
<a name="l79"></a>
<a name="l80"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>AX</span><span class=cF0>,0x4F02
<a name="l81"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>BX</span><span class=cF0>,0x12 </span><span class=cF2>//640x480 16 color</span><span class=cF0>
<a name="l82"></a>#</span><span class=cF1>exe</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l83"></a> </span><span class=cF1>if</span><span class=cF0> (!kernel_cfg-&gt;opts[CFG_TEXT_MODE])
<a name="l84"></a> </span><span class=cF5>StreamPrint</span><span class=cF0>(</span><span class=cF6>&quot;INT 0x10&quot;</span><span class=cF0>); </span><span class=cF2>//Enable VGA</span><span class=cF0>
<a name="l85"></a></span><span class=cF7>}</span><span class=cF0>;
<a name="l86"></a> </span><span class=cF1>CMP</span><span class=cF0> </span><span class=cFC>AX</span><span class=cF0>,0x004F
<a name="l87"></a> </span><span class=cF1>JNE</span><span class=cF0> @@10 </span><span class=cF2>//Jmp if fail</span><span class=cF0>
<a name="l88"></a> </span><span class=cF1>BTS</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> [</span><span class=cFD>SYS_RUN_LEVEL</span><span class=cF0>],</span><span class=cF3>RLf_VGA</span><span class=cF0>
<a name="l89"></a>@@10:
<a name="l90"></a>
<a name="l91"></a></span><span class=cF2>//Get mem maps.</span><span class=cF0>
<a name="l92"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>AX</span><span class=cF0>,0xE801
<a name="l93"></a> </span><span class=cF1>INT</span><span class=cF0> 0x15
<a name="l94"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U16</span><span class=cF0> [</span><span class=cFD>MEM_E801</span><span class=cF0>],</span><span class=cFC>CX</span><span class=cF0>
<a name="l95"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U16</span><span class=cF0> [</span><span class=cFD>MEM_E801</span><span class=cF0>+2],</span><span class=cFC>DX</span><span class=cF0>
<a name="l96"></a>
<a name="l97"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>CX</span><span class=cF0>,</span><span class=cF3>MEM_E820_ENTRIES_NUM</span><span class=cF0>-1 </span><span class=cF2>//Leave one to terminate</span><span class=cF0>
<a name="l98"></a> </span><span class=cF1>XOR</span><span class=cF0> </span><span class=cFC>EBX</span><span class=cF0>,</span><span class=cFC>EBX</span><span class=cF0>
<a name="l99"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>AX</span><span class=cF0>,</span><span class=cFC>DS</span><span class=cF0>
<a name="l100"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>ES</span><span class=cF0>,</span><span class=cFC>AX</span><span class=cF0>
<a name="l101"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>DI</span><span class=cF0>,</span><span class=cFD>MEM_E820</span><span class=cF0>
<a name="l102"></a>@@15: </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cFC>CX</span><span class=cF0>
<a name="l103"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>EAX</span><span class=cF0>,0xE820
<a name="l104"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>ECX</span><span class=cF0>,</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CMemE820</span><span class=cF0>)
<a name="l105"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>EDX</span><span class=cF0>,</span><span class=cF6>'PAMS'</span><span class=cF0>
<a name="l106"></a> </span><span class=cF1>INT</span><span class=cF0> 0x15
<a name="l107"></a> </span><span class=cF1>JC</span><span class=cF0> @@20
<a name="l108"></a> </span><span class=cF1>CMP</span><span class=cF0> </span><span class=cFC>EAX</span><span class=cF0>,</span><span class=cF6>'PAMS'</span><span class=cF0>
<a name="l109"></a> </span><span class=cF1>JNE</span><span class=cF0> @@20
<a name="l110"></a> </span><span class=cF1>TEST</span><span class=cF0> </span><span class=cFC>EBX</span><span class=cF0>,</span><span class=cFC>EBX</span><span class=cF0>
<a name="l111"></a> </span><span class=cF1>JZ</span><span class=cF0> @@20
<a name="l112"></a> </span><span class=cF1>ADD</span><span class=cF0> </span><span class=cFC>DI</span><span class=cF0>,</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CMemE820</span><span class=cF0>)
<a name="l113"></a> </span><span class=cF1>POP</span><span class=cF0> </span><span class=cFC>CX</span><span class=cF0>
<a name="l114"></a> </span><span class=cF1>LOOP</span><span class=cF0> @@15
<a name="l115"></a> </span><span class=cF1>SUB</span><span class=cF0> </span><span class=cFC>SP</span><span class=cF0>,2
<a name="l116"></a>@@20: </span><span class=cF1>ADD</span><span class=cF0> </span><span class=cFC>SP</span><span class=cF0>,2
<a name="l117"></a>
<a name="l118"></a></span><span class=cF2>//Find how much space to map, start with E801 limit.</span><span class=cF0>
<a name="l119"></a> </span><span class=cF1>XOR</span><span class=cF0> </span><span class=cFC>EAX</span><span class=cF0>,</span><span class=cFC>EAX</span><span class=cF0>
<a name="l120"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>AX</span><span class=cF0>,[</span><span class=cFD>MEM_E801</span><span class=cF0>+2]
<a name="l121"></a> </span><span class=cF1>SHL</span><span class=cF0> </span><span class=cFC>EAX</span><span class=cF0>,16
<a name="l122"></a> </span><span class=cF1>ADD</span><span class=cF0> </span><span class=cFC>EAX</span><span class=cF0>,</span><span class=cF3>SYS_16MEG_AREA_LIMIT</span><span class=cF0>
<a name="l123"></a> </span><span class=cF1>XOR</span><span class=cF0> </span><span class=cFC>EDX</span><span class=cF0>,</span><span class=cFC>EDX</span><span class=cF0>
<a name="l124"></a>
<a name="l125"></a></span><span class=cF2>//Find max of E820 to set mapped space.</span><span class=cF0>
<a name="l126"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>SI</span><span class=cF0>,</span><span class=cFD>MEM_E820</span><span class=cF0>
<a name="l127"></a>@@25: </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>CL</span><span class=cF0>,</span><span class=cF9>CMemE820</span><span class=cF0>.type[</span><span class=cFC>SI</span><span class=cF0>]
<a name="l128"></a> </span><span class=cF1>TEST</span><span class=cF0> </span><span class=cFC>CL</span><span class=cF0>,</span><span class=cFC>CL</span><span class=cF0>
<a name="l129"></a> </span><span class=cF1>JZ</span><span class=cF0> @@35
<a name="l130"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>EBX</span><span class=cF0>,</span><span class=cF9>CMemE820</span><span class=cF0>.base[</span><span class=cFC>SI</span><span class=cF0>]
<a name="l131"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>ECX</span><span class=cF0>,</span><span class=cF9>CMemE820</span><span class=cF0>.base+4[</span><span class=cFC>SI</span><span class=cF0>]
<a name="l132"></a> </span><span class=cF1>ADD</span><span class=cF0> </span><span class=cFC>EBX</span><span class=cF0>,</span><span class=cF9>CMemE820</span><span class=cF0>.len[</span><span class=cFC>SI</span><span class=cF0>]
<a name="l133"></a> </span><span class=cF1>ADC</span><span class=cF0> </span><span class=cFC>ECX</span><span class=cF0>,</span><span class=cF9>CMemE820</span><span class=cF0>.len+4[</span><span class=cFC>SI</span><span class=cF0>]
<a name="l134"></a> </span><span class=cF1>SUB</span><span class=cF0> </span><span class=cFC>EBX</span><span class=cF0>,</span><span class=cFC>EAX</span><span class=cF0>
<a name="l135"></a> </span><span class=cF1>SBB</span><span class=cF0> </span><span class=cFC>ECX</span><span class=cF0>,</span><span class=cFC>EDX</span><span class=cF0>
<a name="l136"></a> </span><span class=cF1>JC</span><span class=cF0> @@30
<a name="l137"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>EAX</span><span class=cF0>,</span><span class=cF9>CMemE820</span><span class=cF0>.base[</span><span class=cFC>SI</span><span class=cF0>]
<a name="l138"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>EDX</span><span class=cF0>,</span><span class=cF9>CMemE820</span><span class=cF0>.base+4[</span><span class=cFC>SI</span><span class=cF0>]
<a name="l139"></a> </span><span class=cF1>ADD</span><span class=cF0> </span><span class=cFC>EAX</span><span class=cF0>,</span><span class=cF9>CMemE820</span><span class=cF0>.len[</span><span class=cFC>SI</span><span class=cF0>]
<a name="l140"></a> </span><span class=cF1>ADC</span><span class=cF0> </span><span class=cFC>EDX</span><span class=cF0>,</span><span class=cF9>CMemE820</span><span class=cF0>.len+4[</span><span class=cFC>SI</span><span class=cF0>]
<a name="l141"></a>@@30: </span><span class=cF1>ADD</span><span class=cF0> </span><span class=cFC>SI</span><span class=cF0>,</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CMemE820</span><span class=cF0>)
<a name="l142"></a> </span><span class=cF1>JMP</span><span class=cF0> @@25
<a name="l143"></a>
<a name="l144"></a>@@35: </span><span class=cF1>MOV</span><span class=cF0> [</span><span class=cFD>MEM_PHYSICAL_SPACE</span><span class=cF0>],</span><span class=cFC>EAX</span><span class=cF0>
<a name="l145"></a> </span><span class=cF1>MOV</span><span class=cF0> [</span><span class=cFD>MEM_PHYSICAL_SPACE</span><span class=cF0>+4],</span><span class=cFC>EDX</span><span class=cF0>
<a name="l146"></a>
<a name="l147"></a></span><span class=cF2>//Get PCI Bus Info</span><span class=cF0>
<a name="l148"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U16</span><span class=cF0> [</span><span class=cFD>SYS_PCI_BUSES</span><span class=cF0>],256
<a name="l149"></a> </span><span class=cF1>XOR</span><span class=cF0> </span><span class=cFC>DX</span><span class=cF0>,</span><span class=cFC>DX</span><span class=cF0>
<a name="l150"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>AX</span><span class=cF0>,0xB101
<a name="l151"></a> </span><span class=cF1>INT</span><span class=cF0> 0x1A
<a name="l152"></a> </span><span class=cF1>CMP</span><span class=cF0> </span><span class=cFC>DX</span><span class=cF0>,</span><span class=cF6>'PC'</span><span class=cF0>
<a name="l153"></a> </span><span class=cF1>JNE</span><span class=cF0> @@40
<a name="l154"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>CH</span><span class=cF0>,0
<a name="l155"></a> </span><span class=cF1>INC</span><span class=cF0> </span><span class=cFC>CX</span><span class=cF0>
<a name="l156"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U16</span><span class=cF0> [</span><span class=cFD>SYS_PCI_BUSES</span><span class=cF0>],</span><span class=cFC>CX</span><span class=cF0>
<a name="l157"></a>@@40:
<a name="l158"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l159"></a></span><span class=cF2>//Enable A20</span><span class=cF0>
<a name="l160"></a> </span><span class=cF1>IN</span><span class=cF0> </span><span class=cFC>AL</span><span class=cF0>,0x92
<a name="l161"></a> </span><span class=cF1>OR</span><span class=cF0> </span><span class=cFC>AL</span><span class=cF0>,2
<a name="l162"></a> </span><span class=cF1>OUT</span><span class=cF0> 0x92,</span><span class=cFC>AL</span><span class=cF0>
<a name="l163"></a>
<a name="l164"></a> </span><span class=cF1>POP</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> [</span><span class=cFD>SYS_BOOT_BLK</span><span class=cF0>]
<a name="l165"></a> </span><span class=cF1>POP</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> [</span><span class=cFD>SYS_BOOT_SRC</span><span class=cF0>] </span><span class=cF2>//See </span><a href="/Wb/Adam/Opt/Boot/BootHD.HC.HTML#l86"><span class=cF4>BootHD</span></a><span class=cF2>, </span><a href="/Wb/Adam/Opt/Boot/BootDVD.HC.HTML#l180"><span class=cF4>BootDVD</span></a><span class=cF2>, &amp; </span><a href="/Wb/Adam/Opt/Boot/BootRAM.HC.HTML#l46"><span class=cF4>BootRAM</span></a><span class=cF2>.</span><span class=cF0>
<a name="l166"></a>
<a name="l167"></a> </span><span class=cF1>CLD</span><span class=cF0>
<a name="l168"></a> </span><span class=cF1>XOR</span><span class=cF0> </span><span class=cFC>EAX</span><span class=cF0>,</span><span class=cFC>EAX</span><span class=cF0>
<a name="l169"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>AX</span><span class=cF0>,</span><span class=cFC>CS</span><span class=cF0>
<a name="l170"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>DS</span><span class=cF0>,</span><span class=cFC>AX</span><span class=cF0>
<a name="l171"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>ES</span><span class=cF0>,</span><span class=cFC>AX</span><span class=cF0>
<a name="l172"></a> </span><span class=cF1>SHL</span><span class=cF0> </span><span class=cFC>EAX</span><span class=cF0>,4
<a name="l173"></a>
<a name="l174"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> [</span><span class=cFD>MEM_BOOT_BASE</span><span class=cF0>],</span><span class=cFC>EAX</span><span class=cF0>
<a name="l175"></a>
<a name="l176"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>DX</span><span class=cF0>,</span><span class=cFC>CS</span><span class=cF0>
<a name="l177"></a> </span><span class=cF1>SUB</span><span class=cF0> </span><span class=cFC>DX</span><span class=cF0>,</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CBinFile</span><span class=cF0>)/16
<a name="l178"></a>#</span><span class=cF1>assert</span><span class=cF0> !(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CBinFile</span><span class=cF7>)</span><span class=cF0>&amp;15)
<a name="l179"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>GS</span><span class=cF0>,</span><span class=cFC>DX</span><span class=cF0>
<a name="l180"></a>
<a name="l181"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>EDX</span><span class=cF0>,</span><span class=cFC>EAX</span><span class=cF0>
<a name="l182"></a> </span><span class=cF1>ADD</span><span class=cF0> </span><span class=cFC>EDX</span><span class=cF0>,</span><span class=cF9>U32</span><span class=cF0> </span><span class=cFC>GS</span><span class=cF0>:[</span><span class=cF9>CBinFile</span><span class=cF0>.patch_table_offset]
<a name="l183"></a> </span><span class=cF1>SUB</span><span class=cF0> </span><span class=cFC>EDX</span><span class=cF0>,</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CBinFile</span><span class=cF0>)
<a name="l184"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> [</span><span class=cFD>SYS_BOOT_PATCH_TABLE_BASE</span><span class=cF0>],</span><span class=cFC>EDX</span><span class=cF0>
<a name="l185"></a>
<a name="l186"></a> </span><span class=cF1>ADD</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> [GDT_BOOT_DS+2],</span><span class=cFC>EAX</span><span class=cF0>
<a name="l187"></a> </span><span class=cF1>ADD</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> [GDT_BOOT_CS+2],</span><span class=cFC>EAX</span><span class=cF0>
<a name="l188"></a> </span><span class=cF1>ADD</span><span class=cF0> </span><span class=cFC>EAX</span><span class=cF0>,</span><span class=cF9>I32</span><span class=cF0> </span><span class=cFD>SYS_GDT</span><span class=cF0>
<a name="l189"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> [</span><span class=cFD>SYS_GDT_PTR</span><span class=cF0>+</span><span class=cF9>CSysLimitBase</span><span class=cF0>.base],</span><span class=cFC>EAX</span><span class=cF0>
<a name="l190"></a> </span><span class=cF1>LGDT</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> [</span><span class=cFD>SYS_GDT_PTR</span><span class=cF0>]
<a name="l191"></a>
<a name="l192"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>EAX</span><span class=cF0>,</span><span class=cF3>SYS_START_CR0</span><span class=cF0>
<a name="l193"></a> </span><span class=cF1>MOV_CR0_EAX</span><span class=cF0>
<a name="l194"></a>
<a name="l195"></a></span><span class=cF2>/* The assembler doesn't support far jumps so</span><span class=cF0>
<a name="l196"></a></span><span class=cF2>we hand code it. 16-bit code is not important</span><span class=cF0>
<a name="l197"></a></span><span class=cF2>enough to fully implement in the assembler.</span><span class=cF0>
<a name="l198"></a>
<a name="l199"></a></span><span class=cF2>To complete the switch to 32-bit mode, we have to load</span><span class=cF0>
<a name="l200"></a></span><span class=cF2>the code segment with a far jump.</span><span class=cF0>
<a name="l201"></a></span><span class=cF2>*/</span><span class=cF0>
<a name="l202"></a> </span><span class=cF1>DU8</span><span class=cF0> 0x66,0xEA; </span><span class=cF2>//JMP CGDT.boot_cs:CORE0_32BIT_INIT</span><span class=cF0>
<a name="l203"></a> </span><span class=cF1>DU32</span><span class=cF0> </span><span class=cFD>CORE0_32BIT_INIT</span><span class=cF0>;
<a name="l204"></a> </span><span class=cF1>DU16</span><span class=cF0> </span><span class=cF9>CGDT</span><span class=cF0>.boot_cs;
<a name="l205"></a>#</span><span class=cF1>assert</span><span class=cF0> $+16&lt;=0xFFFF
<a name="l206"></a>}
</span></pre></body>
</html>