107 lines
9.1 KiB
Plaintext
107 lines
9.1 KiB
Plaintext
|
<!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=cF2>/*TempleOS runs exclusively in ring 0.</span><span class=cF0>
|
||
|
<a name="l2"></a></span><span class=cF2>Ring 0 is part of the </span><a href="/Wb/Doc/Charter.DD.HTML#l1"><span class=cF4>Charter</span></a><span class=cF2>.</span><span class=cF0>
|
||
|
<a name="l3"></a></span><span class=cF2>This demo is for you to play around</span><span class=cF0>
|
||
|
<a name="l4"></a></span><span class=cF2>with ring 3. TempleOS is for</span><span class=cF0>
|
||
|
<a name="l5"></a></span><span class=cF2>recreational programming, after all.</span><span class=cF0>
|
||
|
<a name="l6"></a>
|
||
|
<a name="l7"></a></span><span class=cF2>This redirects the general protection</span><span class=cF0>
|
||
|
<a name="l8"></a></span><span class=cF2>fault, switches to ring 3, and generates</span><span class=cF0>
|
||
|
<a name="l9"></a></span><span class=cF2>a fault to switch back.</span><span class=cF0>
|
||
|
<a name="l10"></a></span><span class=cF2>*/</span><span class=cF0>
|
||
|
<a name="l11"></a>
|
||
|
<a name="l12"></a></span><span class=cF1>U8</span><span class=cF0> *old_stk,*new_rip;
|
||
|
<a name="l13"></a>
|
||
|
<a name="l14"></a></span><span class=cF1>asm</span><span class=cF0> {
|
||
|
<a name="l15"></a>INT_TO_RING0:: </span><span class=cF2>//Set to handle general protection 0xD fault temporarily.</span><span class=cF0>
|
||
|
<a name="l16"></a> </span><span class=cF1>INC</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> [</span><span class=cFD>SYS_PROGRESS1</span><span class=cF0>]
|
||
|
<a name="l17"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> </span><span class=cF9>CGDT</span><span class=cF0>.ds </span><span class=cF2>//STKSEG</span><span class=cF0>
|
||
|
<a name="l18"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>,</span><span class=cF9>U64</span><span class=cF0> [&old_stk]
|
||
|
<a name="l19"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>
|
||
|
<a name="l20"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> 0 </span><span class=cF2>//FLAGS--interrupts off</span><span class=cF0>
|
||
|
<a name="l21"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> </span><span class=cF9>CGDT</span><span class=cF0>.cs64
|
||
|
<a name="l22"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>,</span><span class=cF9>U64</span><span class=cF0> [&new_rip]
|
||
|
<a name="l23"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>
|
||
|
<a name="l24"></a> </span><span class=cF1>IRET</span><span class=cF0>
|
||
|
<a name="l25"></a>}
|
||
|
<a name="l26"></a>
|
||
|
<a name="l27"></a></span><span class=cF1>U0</span><span class=cF0> Ring3Demo()
|
||
|
<a name="l28"></a>{
|
||
|
<a name="l29"></a> </span><span class=cF1>U8</span><span class=cF0> *old_vect;
|
||
|
<a name="l30"></a> </span><span class=cF6>"Progress1 Before:%X\n"</span><span class=cF0>,</span><span class=cFB>progress1</span><span class=cF0>;
|
||
|
<a name="l31"></a> </span><span class=cF1>CLI</span><span class=cF0>
|
||
|
<a name="l32"></a> old_vect=</span><span class=cF5>IntEntrySet</span><span class=cF0>(0x0D,INT_TO_RING0,</span><span class=cF3>IDTET_TRAP</span><span class=cF0>,0);
|
||
|
<a name="l33"></a>
|
||
|
<a name="l34"></a> </span><span class=cF5>TSSBusy</span><span class=cF0>(</span><span class=cF5>Gs</span><span class=cF0>->tss->tr_ring3,</span><span class=cF3>OFF</span><span class=cF0>);
|
||
|
<a name="l35"></a> </span><span class=cF5>SetRAX</span><span class=cF0>(</span><span class=cF5>Gs</span><span class=cF0>->tss->tr_ring3+3);
|
||
|
<a name="l36"></a> </span><span class=cF1>LTR</span><span class=cF0> </span><span class=cFC>AX</span><span class=cF0>
|
||
|
<a name="l37"></a>
|
||
|
<a name="l38"></a> </span><span class=cF1>asm</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l39"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> [&old_stk],</span><span class=cFC>RSP</span><span class=cF0>
|
||
|
<a name="l40"></a>
|
||
|
<a name="l41"></a> </span><span class=cF1>LEA</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>,[R3_CALLBACK]
|
||
|
<a name="l42"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> [&new_rip],</span><span class=cFC>RAX</span><span class=cF0>
|
||
|
<a name="l43"></a>
|
||
|
<a name="l44"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>AX</span><span class=cF0>,</span><span class=cF9>CGDT</span><span class=cF0>.ds_ring3+3
|
||
|
<a name="l45"></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="l46"></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="l47"></a>
|
||
|
<a name="l48"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> </span><span class=cF9>CGDT</span><span class=cF0>.ds_ring3+3 </span><span class=cF2>//STKSEG</span><span class=cF0>
|
||
|
<a name="l49"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> [&old_stk]
|
||
|
<a name="l50"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> 0 </span><span class=cF2>//FLAGS--interrupts off</span><span class=cF0>
|
||
|
<a name="l51"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> </span><span class=cF9>CGDT</span><span class=cF0>.cs64_ring3+3
|
||
|
<a name="l52"></a> </span><span class=cF1>LEA</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>,[R3_START]
|
||
|
<a name="l53"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>
|
||
|
<a name="l54"></a> </span><span class=cF1>IRET</span><span class=cF0>
|
||
|
<a name="l55"></a>
|
||
|
<a name="l56"></a> R3_START:
|
||
|
<a name="l57"></a> </span><span class=cF1>INC</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> [</span><span class=cFD>SYS_PROGRESS1</span><span class=cF0>]
|
||
|
<a name="l58"></a> </span><span class=cF1>CLI</span><span class=cF0> </span><span class=cF2>//This causes general protection fault #13</span><span class=cF0>
|
||
|
<a name="l59"></a>
|
||
|
<a name="l60"></a> R3_CALLBACK:
|
||
|
<a name="l61"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>AX</span><span class=cF0>,</span><span class=cF9>CGDT</span><span class=cF0>.ds
|
||
|
<a name="l62"></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="l63"></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="l64"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l65"></a>
|
||
|
<a name="l66"></a> </span><span class=cF5>TSSBusy</span><span class=cF0>(</span><span class=cF5>Gs</span><span class=cF0>->tss->tr,</span><span class=cF3>OFF</span><span class=cF0>);
|
||
|
<a name="l67"></a> </span><span class=cF5>SetRAX</span><span class=cF0>(</span><span class=cF5>Gs</span><span class=cF0>->tss->tr);
|
||
|
<a name="l68"></a> </span><span class=cF1>LTR</span><span class=cF0> </span><span class=cFC>AX</span><span class=cF0>
|
||
|
<a name="l69"></a>
|
||
|
<a name="l70"></a> </span><span class=cF5>IntEntrySet</span><span class=cF0>(0x0D,old_vect,</span><span class=cF3>IDTET_IRQ</span><span class=cF0>,0);
|
||
|
<a name="l71"></a> </span><span class=cF1>STI</span><span class=cF0>
|
||
|
<a name="l72"></a> </span><span class=cF6>"Progress1 After :%X\n"</span><span class=cF0>,</span><span class=cFB>progress1</span><span class=cF0>;
|
||
|
<a name="l73"></a>}
|
||
|
<a name="l74"></a>
|
||
|
<a name="l75"></a>Ring3Demo;
|
||
|
</span></pre></body>
|
||
|
</html>
|