mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2024-12-26 15:26:43 +00:00
283 lines
38 KiB
HTML
Executable file
283 lines
38 KiB
HTML
Executable file
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
|
|
<meta name="generator" content="ZealOS V1.07">
|
|
<style type="text/css">
|
|
body {background-color:#1f1f1f;}
|
|
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
|
|
.cF1{color:#4f84a6;background-color:#1f1f1f;}
|
|
.cF2{color:#73a255;background-color:#1f1f1f;}
|
|
.cF3{color:#297582;background-color:#1f1f1f;}
|
|
.cF4{color:#b34f4b;background-color:#1f1f1f;}
|
|
.cF5{color:#8a52c3;background-color:#1f1f1f;}
|
|
.cF6{color:#b7822f;background-color:#1f1f1f;}
|
|
.cF7{color:#444444;background-color:#1f1f1f;}
|
|
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
|
|
.cF9{color:#94bfde;background-color:#1f1f1f;}
|
|
.cFA{color:#a1ce97;background-color:#1f1f1f;}
|
|
.cFB{color:#6db4be;background-color:#1f1f1f;}
|
|
.cFC{color:#e88e88;background-color:#1f1f1f;}
|
|
.cFD{color:#ca94e8;background-color:#1f1f1f;}
|
|
.cFE{color:#d4b475;background-color:#1f1f1f;}
|
|
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<pre style="font-family:monospace;font-size:12pt">
|
|
<a name="l1"></a><span class=cF1>asm</span><span class=cF0> {
|
|
<a name="l2"></a></span><span class=cFD>INT_MP_CRASH_ADDR</span><span class=cF0>:: </span><span class=cF2>//Forward reference to work around compiler</span><span class=cF0>
|
|
<a name="l3"></a> </span><span class=cF1>DU32</span><span class=cF0> &</span><span class=cFD>IntMPCrash</span><span class=cF0>;
|
|
<a name="l4"></a>
|
|
<a name="l5"></a></span><span class=cFD>INT_WAKE</span><span class=cF0>::
|
|
<a name="l6"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cFC>RDX</span><span class=cF0>
|
|
<a name="l7"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>
|
|
<a name="l8"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>EAX</span><span class=cF0>, &</span><span class=cFB>dev</span><span class=cF0>
|
|
<a name="l9"></a> </span><span class=cF1>MOV</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=cF3>LAPIC_EOI</span><span class=cF0>
|
|
<a name="l10"></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> </span><span class=cF9>CDevGlobals</span><span class=cF0>.uncached_alias[</span><span class=cFC>RAX</span><span class=cF0>]
|
|
<a name="l11"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> [</span><span class=cFC>RAX</span><span class=cF0>+</span><span class=cFC>RDX</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF0>
|
|
<a name="l12"></a> </span><span class=cF1>POP</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>
|
|
<a name="l13"></a> </span><span class=cF1>POP</span><span class=cF0> </span><span class=cFC>RDX</span><span class=cF0>
|
|
<a name="l14"></a> </span><span class=cF1>IRET</span><span class=cF0>
|
|
<a name="l15"></a>
|
|
<a name="l16"></a></span><span class=cFD>IRQ_TIMER</span><span class=cF0>:: </span><span class=cF2>//I_TIMER</span><span class=cF0>
|
|
<a name="l17"></a> </span><span class=cF1>CALL</span><span class=cF0> </span><span class=cFD>TASK_CONTEXT_SAVE</span><span class=cF0>
|
|
<a name="l18"></a> </span><span class=cF1>CLD</span><span class=cF0>
|
|
<a name="l19"></a>
|
|
<a name="l20"></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> [</span><span class=cFC>RSP</span><span class=cF0>]
|
|
<a name="l21"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CTask</span><span class=cF0>.rip[</span><span class=cFC>RSI</span><span class=cF0>], </span><span class=cFC>RAX</span><span class=cF0>
|
|
<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> </span><span class=cFE>16</span><span class=cF0>[</span><span class=cFC>RSP</span><span class=cF0>]
|
|
<a name="l23"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CTask</span><span class=cF0>.rflags[</span><span class=cFC>RSI</span><span class=cF0>], </span><span class=cFC>RAX</span><span class=cF0>
|
|
<a name="l24"></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> </span><span class=cFE>24</span><span class=cF0>[</span><span class=cFC>RSP</span><span class=cF0>]
|
|
<a name="l25"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CTask</span><span class=cF0>.rsp[</span><span class=cFC>RSI</span><span class=cF0>], </span><span class=cFC>RAX</span><span class=cF0>
|
|
<a name="l26"></a>
|
|
<a name="l27"></a> </span><span class=cF1>XOR</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>, </span><span class=cFC>RAX</span><span class=cF0>
|
|
<a name="l28"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RDI</span><span class=cF0>, </span><span class=cF9>U64</span><span class=cF0> </span><span class=cFC>GS</span><span class=cF0>:</span><span class=cF9>CCPU</span><span class=cF0>.addr[</span><span class=cFC>RAX</span><span class=cF0>]
|
|
<a name="l29"></a> </span><span class=cF1>LOCK</span><span class=cF0>
|
|
<a name="l30"></a> </span><span class=cF1>INC</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CCPU</span><span class=cF0>.total_jiffies[</span><span class=cFC>RDI</span><span class=cF0>]
|
|
<a name="l31"></a>
|
|
<a name="l32"></a> </span><span class=cF1>BT</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CTask</span><span class=cF0>.task_flags[</span><span class=cFC>RSI</span><span class=cF0>], </span><span class=cF3>TASKf_IDLE</span><span class=cF0>
|
|
<a name="l33"></a> </span><span class=cF1>JNC</span><span class=cF0> @@05
|
|
<a name="l34"></a> </span><span class=cF1>LOCK</span><span class=cF0>
|
|
<a name="l35"></a> </span><span class=cF1>INC</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CCPU</span><span class=cF0>.idle_pt_hits[</span><span class=cFC>RDI</span><span class=cF0>]
|
|
<a name="l36"></a>
|
|
<a name="l37"></a>@@05: </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> </span><span class=cF9>CCPU</span><span class=cF0>.profiler_timer_irq[</span><span class=cFC>RDI</span><span class=cF0>]
|
|
<a name="l38"></a> </span><span class=cF1>TEST</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>, </span><span class=cFC>RAX</span><span class=cF0>
|
|
<a name="l39"></a> </span><span class=cF1>JZ</span><span class=cF0> @@10
|
|
<a name="l40"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cFC>RSI</span><span class=cF0>
|
|
<a name="l41"></a> </span><span class=cF1>CALL</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0> </span><span class=cF2>//See </span><a href="https://zeal-operating-system.github.io/ZealOS/System/Utils/Profiler.ZC.html#l11"><span class=cF4>ProfTimerInt</span></a><span class=cF2>().</span><span class=cF0>
|
|
<a name="l42"></a> </span><span class=cF1>JMP</span><span class=cF0> @@15
|
|
<a name="l43"></a>@@10: </span><span class=cF1>ADD</span><span class=cF0> </span><span class=cFC>RSP</span><span class=cF0>, </span><span class=cFE>8</span><span class=cF0>
|
|
<a name="l44"></a>@@15: </span><span class=cF1>CLI</span><span class=cF0>
|
|
<a name="l45"></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> </span><span class=cF9>CCPU</span><span class=cF0>.num[</span><span class=cFC>RDI</span><span class=cF0>]
|
|
<a name="l46"></a> </span><span class=cF1>TEST</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>, </span><span class=cFC>RAX</span><span class=cF0>
|
|
<a name="l47"></a> </span><span class=cF1>JZ</span><span class=cF0> @@20
|
|
<a name="l48"></a>
|
|
<a name="l49"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>EAX</span><span class=cF0>, &</span><span class=cFB>dev</span><span class=cF0>
|
|
<a name="l50"></a> </span><span class=cF1>MOV</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=cF3>LAPIC_EOI</span><span class=cF0>
|
|
<a name="l51"></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> </span><span class=cF9>CDevGlobals</span><span class=cF0>.uncached_alias[</span><span class=cFC>RAX</span><span class=cF0>]
|
|
<a name="l52"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> [</span><span class=cFC>RAX</span><span class=cF0> + </span><span class=cFC>RDX</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF0>
|
|
<a name="l53"></a> </span><span class=cF1>JMP</span><span class=cF0> @@25
|
|
<a name="l54"></a>
|
|
<a name="l55"></a>@@20: </span><span class=cF1>CALL</span><span class=cF0> &</span><span class=cFD>IntCore0TimerHandler</span><span class=cF0> </span><span class=cF2>//Only Core 0 calls this.</span><span class=cF0>
|
|
<a name="l56"></a>@@25: </span><span class=cF1>XOR</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>, </span><span class=cFC>RAX</span><span class=cF0>
|
|
<a name="l57"></a> </span><span class=cF1>CMP</span><span class=cF0> </span><span class=cFC>RSI</span><span class=cF0>, </span><span class=cF9>U64</span><span class=cF0> </span><span class=cFC>GS</span><span class=cF0>:</span><span class=cF9>CCPU</span><span class=cF0>.idle_task[</span><span class=cFC>RAX</span><span class=cF0>]
|
|
<a name="l58"></a> </span><span class=cF1>JE</span><span class=cF0> </span><span class=cF9>I32</span><span class=cF0> RESTORE_EXECUTIVE_TASK_IF_READY
|
|
<a name="l59"></a> </span><span class=cF1>JMP</span><span class=cF0> </span><span class=cF9>I32</span><span class=cF0> RESTORE_RSI_TASK
|
|
<a name="l60"></a>
|
|
<a name="l61"></a></span><span class=cF2>//************************************</span><span class=cF0>
|
|
<a name="l62"></a></span><span class=cFD>INT_FAULT</span><span class=cF0>::
|
|
<a name="l63"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cFC>RBX</span><span class=cF0>
|
|
<a name="l64"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>
|
|
<a name="l65"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>BL</span><span class=cF0>, </span><span class=cF1>U8</span><span class=cF0> </span><span class=cFE>16</span><span class=cF0>[</span><span class=cFC>RSP</span><span class=cF0>] </span><span class=cF2>//We pushed fault_num </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KInterrupts.ZC.html#l199"><span class=cF4>IntFaultHandlersNew</span></a><span class=cF2>().</span><span class=cF0>
|
|
<a name="l66"></a> </span><span class=cF1>XOR</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>, </span><span class=cFC>RAX</span><span class=cF0>
|
|
<a name="l67"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>FS</span><span class=cF0>:</span><span class=cF1>U8</span><span class=cF0> </span><span class=cF9>CTask</span><span class=cF0>.fault_num[</span><span class=cFC>RAX</span><span class=cF0>], </span><span class=cFC>BL</span><span class=cF0>
|
|
<a name="l68"></a> </span><span class=cF1>POP</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>
|
|
<a name="l69"></a> </span><span class=cF1>POP</span><span class=cF0> </span><span class=cFC>RBX</span><span class=cF0>
|
|
<a name="l70"></a> </span><span class=cF1>ADD</span><span class=cF0> </span><span class=cFC>RSP</span><span class=cF0>, </span><span class=cFE>8</span><span class=cF0> </span><span class=cF2>//Pop fault_num</span><span class=cF0>
|
|
<a name="l71"></a>
|
|
<a name="l72"></a> </span><span class=cF1>CALL</span><span class=cF0> </span><span class=cFD>TASK_CONTEXT_SAVE</span><span class=cF0>
|
|
<a name="l73"></a>
|
|
<a name="l74"></a> </span><span class=cF1>XOR</span><span class=cF0> </span><span class=cFC>RDX</span><span class=cF0>, </span><span class=cFC>RDX</span><span class=cF0>
|
|
<a name="l75"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CTask</span><span class=cF0>.fault_err_code[</span><span class=cFC>RSI</span><span class=cF0>], </span><span class=cFC>RDX</span><span class=cF0>
|
|
<a name="l76"></a> </span><span class=cF1>MOV</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=cF9>CTask</span><span class=cF0>.fault_num[</span><span class=cFC>RSI</span><span class=cF0>]
|
|
<a name="l77"></a> </span><span class=cF1>BT</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> [</span><span class=cFD>INT_FAULT_ERR_CODE_BITMAP</span><span class=cF0>], </span><span class=cFC>RDX</span><span class=cF0>
|
|
<a name="l78"></a> </span><span class=cF1>JNC</span><span class=cF0> @@1
|
|
<a name="l79"></a> </span><span class=cF1>POP</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CTask</span><span class=cF0>.fault_err_code[</span><span class=cFC>RSI</span><span class=cF0>]
|
|
<a name="l80"></a>
|
|
<a name="l81"></a>@@1: </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> [</span><span class=cFC>RSP</span><span class=cF0>]
|
|
<a name="l82"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CTask</span><span class=cF0>.rip[</span><span class=cFC>RSI</span><span class=cF0>], </span><span class=cFC>RAX</span><span class=cF0>
|
|
<a name="l83"></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> </span><span class=cFE>16</span><span class=cF0>[</span><span class=cFC>RSP</span><span class=cF0>]
|
|
<a name="l84"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CTask</span><span class=cF0>.rflags[</span><span class=cFC>RSI</span><span class=cF0>], </span><span class=cFC>RAX</span><span class=cF0>
|
|
<a name="l85"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RSP</span><span class=cF0>, </span><span class=cF9>U64</span><span class=cF0> </span><span class=cFE>24</span><span class=cF0>[</span><span class=cFC>RSP</span><span class=cF0>]
|
|
<a name="l86"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CTask</span><span class=cF0>.rsp[</span><span class=cFC>RSI</span><span class=cF0>], </span><span class=cFC>RSP</span><span class=cF0>
|
|
<a name="l87"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RBP</span><span class=cF0>, </span><span class=cF9>CTask</span><span class=cF0>.rbp[</span><span class=cFC>RSI</span><span class=cF0>]
|
|
<a name="l88"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CTask</span><span class=cF0>.fault_err_code[</span><span class=cFC>RSI</span><span class=cF0>]
|
|
<a name="l89"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CTask</span><span class=cF0>.fault_num[</span><span class=cFC>RSI</span><span class=cF0>]
|
|
<a name="l90"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RSI</span><span class=cF0>, </span><span class=cF9>CTask</span><span class=cF0>.rsi[</span><span class=cFC>RSI</span><span class=cF0>]
|
|
<a name="l91"></a> </span><span class=cF1>CALL</span><span class=cF0> &</span><span class=cFD>Fault2</span><span class=cF0> </span><span class=cF2>//See </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KDebug.ZC.html#l706"><span class=cF4>Fault2</span></a><span class=cF0>
|
|
<a name="l92"></a> </span><span class=cF1>JMP</span><span class=cF0> </span><span class=cF9>I32</span><span class=cF0> RESTORE_FS_TASK
|
|
<a name="l93"></a>
|
|
<a name="l94"></a></span><span class=cFD>INT_FAULT_ERR_CODE_BITMAP</span><span class=cF0>::
|
|
<a name="l95"></a> </span><span class=cF1>DU32</span><span class=cF0> </span><span class=cFE>0x00027D00</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l96"></a>}
|
|
<a name="l97"></a>
|
|
<a name="l98"></a></span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF5>IntEntryGet</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> irq)
|
|
<a name="l99"></a>{</span><span class=cF2>//Get interrupt handler.</span><span class=cF0>
|
|
<a name="l100"></a> </span><span class=cF9>I64</span><span class=cF0> handler_addr;
|
|
<a name="l101"></a> </span><span class=cF9>CIDTEntry</span><span class=cF0> *entry = &</span><span class=cFB>dev</span><span class=cF0>.idt[irq];
|
|
<a name="l102"></a>
|
|
<a name="l103"></a> handler_addr.u16[</span><span class=cFE>0</span><span class=cF0>] = entry->offset_low;
|
|
<a name="l104"></a> handler_addr.u16[</span><span class=cFE>1</span><span class=cF0>] = entry->offset_mid;
|
|
<a name="l105"></a> handler_addr.u32[</span><span class=cFE>1</span><span class=cF0>] = entry->offset_hi;
|
|
<a name="l106"></a>
|
|
<a name="l107"></a> </span><span class=cF1>return</span><span class=cF0> handler_addr;
|
|
<a name="l108"></a>}
|
|
<a name="l109"></a>
|
|
<a name="l110"></a></span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF5>IntEntrySet</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> irq, </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF7>(</span><span class=cF0>*fp_new_handler</span><span class=cF7>)()</span><span class=cF0>, </span><span class=cF9>I64</span><span class=cF0> type=</span><span class=cF3>IDTET_IRQ</span><span class=cF0>)
|
|
<a name="l111"></a>{</span><span class=cF2>//Set interrupt handler. Returns old handler. See </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l322"><span class=cF4>IDTET_IRQ</span></a><span class=cF2>.</span><span class=cF0>
|
|
<a name="l112"></a></span><span class=cF2>//See </span><a href="https://zeal-operating-system.github.io/ZealOS/Demo/Lectures/InterruptDemo.ZC.html#l1"><span class=cF4>::/Demo/Lectures/InterruptDemo.ZC</span></a><span class=cF2>.</span><span class=cF0>
|
|
<a name="l113"></a></span><span class=cF2>//See </span><a href="https://zeal-operating-system.github.io/ZealOS/Demo/MultiCore/Interrupts.ZC.html#l1"><span class=cF4>::/Demo/MultiCore/Interrupts.ZC</span></a><span class=cF2>.</span><span class=cF0>
|
|
<a name="l114"></a> </span><span class=cF9>I64</span><span class=cF0> fp = fp_new_handler;
|
|
<a name="l115"></a> </span><span class=cF1>U8</span><span class=cF0> *old_handler;
|
|
<a name="l116"></a> </span><span class=cF9>CIDTEntry</span><span class=cF0> *entry;
|
|
<a name="l117"></a>
|
|
<a name="l118"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
|
|
<a name="l119"></a> </span><span class=cF1>CLI</span><span class=cF0>
|
|
<a name="l120"></a> old_handler = </span><span class=cF5>IntEntryGet</span><span class=cF0>(irq);
|
|
<a name="l121"></a> entry = &</span><span class=cFB>dev</span><span class=cF0>.idt[irq];
|
|
<a name="l122"></a> entry->seg_select = </span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CGDT</span><span class=cF0>.cs64);
|
|
<a name="l123"></a> entry->offset_low = fp.u16[</span><span class=cFE>0</span><span class=cF0>];
|
|
<a name="l124"></a> entry->offset_mid = fp.u16[</span><span class=cFE>1</span><span class=cF0>];
|
|
<a name="l125"></a> entry->offset_hi = fp.u32[</span><span class=cFE>1</span><span class=cF0>];
|
|
<a name="l126"></a> entry->type_attr = </span><span class=cFE>0x80</span><span class=cF0> + type; </span><span class=cF2>//bit 7 is 'segment present'</span><span class=cF0>
|
|
<a name="l127"></a> entry->ist = entry->zero = </span><span class=cFE>0</span><span class=cF0>; </span><span class=cF2>//We don't care about the IST mechanism</span><span class=cF0>
|
|
<a name="l128"></a> </span><span class=cF1>POPFD</span><span class=cF0>
|
|
<a name="l129"></a>
|
|
<a name="l130"></a> </span><span class=cF1>return</span><span class=cF0> old_handler;
|
|
<a name="l131"></a>}
|
|
<a name="l132"></a>
|
|
<a name="l133"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>IntEntryAlloc</span><span class=cF0>()
|
|
<a name="l134"></a>{ </span><span class=cF2>// 'Allocate' a user irq num.</span><span class=cF0>
|
|
<a name="l135"></a> </span><span class=cF2>// 64 user irqs available, 0xFF <--> 0xBF.</span><span class=cF0>
|
|
<a name="l136"></a> </span><span class=cF2>// </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l343"><span class=cF4>Goes backwards from 0xFF.</span></a><span class=cF0>
|
|
<a name="l137"></a> </span><span class=cF9>I64</span><span class=cF0> i, res = </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l138"></a>
|
|
<a name="l139"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0xFF</span><span class=cF0>; i > </span><span class=cFE>0xFF</span><span class=cF0> - </span><span class=cFE>64</span><span class=cF0>; i--)
|
|
<a name="l140"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>Bts</span><span class=cF7>(</span><span class=cF0>&</span><span class=cFB>dev</span><span class=cF0>.user_int_bitmap, i - </span><span class=cFE>192</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l141"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l142"></a> res = i;
|
|
<a name="l143"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l144"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l145"></a>
|
|
<a name="l146"></a> </span><span class=cF1>return</span><span class=cF0> res;
|
|
<a name="l147"></a>}
|
|
<a name="l148"></a>
|
|
<a name="l149"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>IntPICInit</span><span class=cF0>()
|
|
<a name="l150"></a>{</span><span class=cF2>//Init 8259</span><span class=cF0>
|
|
<a name="l151"></a> </span><span class=cF5>OutU8</span><span class=cF0>(</span><span class=cF3>PIC_1</span><span class=cF0>, </span><span class=cF3>PIC_INIT</span><span class=cF0>); </span><span class=cF2>//IW (Initialization Word) 1</span><span class=cF0>
|
|
<a name="l152"></a> </span><span class=cF5>OutU8</span><span class=cF0>(</span><span class=cF3>PIC_2</span><span class=cF0>, </span><span class=cF3>PIC_INIT</span><span class=cF0>); </span><span class=cF2>//IW1</span><span class=cF0>
|
|
<a name="l153"></a>
|
|
<a name="l154"></a> </span><span class=cF5>OutU8</span><span class=cF0>(</span><span class=cF3>PIC_1_DATA</span><span class=cF0>, </span><span class=cFE>0x20</span><span class=cF0>); </span><span class=cF2>//IW2 Moving IRQ base from 0 -> 32 (beyond Intel reserved faults)</span><span class=cF0>
|
|
<a name="l155"></a> </span><span class=cF5>OutU8</span><span class=cF0>(</span><span class=cF3>PIC_2_DATA</span><span class=cF0>, </span><span class=cFE>0x28</span><span class=cF0>); </span><span class=cF2>//IW2 Moving IRQ base from 8 -> 40</span><span class=cF0>
|
|
<a name="l156"></a> </span><span class=cF5>OutU8</span><span class=cF0>(</span><span class=cF3>PIC_1_DATA</span><span class=cF0>, </span><span class=cFE>0x04</span><span class=cF0>); </span><span class=cF2>//IW3 Telling PIC_1 PIC_2 exists.</span><span class=cF0>
|
|
<a name="l157"></a> </span><span class=cF5>OutU8</span><span class=cF0>(</span><span class=cF3>PIC_2_DATA</span><span class=cF0>, </span><span class=cFE>0x02</span><span class=cF0>); </span><span class=cF2>//IW3 Telling PIC_2 its cascade identity.</span><span class=cF0>
|
|
<a name="l158"></a> </span><span class=cF5>OutU8</span><span class=cF0>(</span><span class=cF3>PIC_1_DATA</span><span class=cF0>, </span><span class=cFE>0x0D</span><span class=cF0>); </span><span class=cF2>//IW4 8086 Mode, Buffered Mode (Master PIC)</span><span class=cF0>
|
|
<a name="l159"></a> </span><span class=cF5>OutU8</span><span class=cF0>(</span><span class=cF3>PIC_2_DATA</span><span class=cF0>, </span><span class=cFE>0x09</span><span class=cF0>); </span><span class=cF2>//IW4 8086 Mode, Buffered Mode (Slave PIC)</span><span class=cF0>
|
|
<a name="l160"></a> </span><span class=cF5>OutU8</span><span class=cF0>(</span><span class=cF3>PIC_1_DATA</span><span class=cF0>, </span><span class=cFE>0xFA</span><span class=cF0>); </span><span class=cF2>//Mask all but IRQ0 (timer) and IRQ2 Cascade.</span><span class=cF0>
|
|
<a name="l161"></a> </span><span class=cF5>OutU8</span><span class=cF0>(</span><span class=cF3>PIC_2_DATA</span><span class=cF0>, </span><span class=cFE>0xFF</span><span class=cF0>);
|
|
<a name="l162"></a>}
|
|
<a name="l163"></a>
|
|
<a name="l164"></a></span><span class=cF1>interrupt</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>IntNop</span><span class=cF0>()
|
|
<a name="l165"></a>{</span><span class=cF2>//Make unplanned IRQs stop by all means!</span><span class=cF0>
|
|
<a name="l166"></a> </span><span class=cF5>OutU8</span><span class=cF0>(</span><span class=cF3>PIC_2</span><span class=cF0>, </span><span class=cF3>PIC_EOI</span><span class=cF0>);
|
|
<a name="l167"></a> </span><span class=cF5>OutU8</span><span class=cF0>(</span><span class=cF3>PIC_1</span><span class=cF0>, </span><span class=cF3>PIC_EOI</span><span class=cF0>);
|
|
<a name="l168"></a> *(</span><span class=cFB>dev</span><span class=cF0>.uncached_alias + </span><span class=cF3>LAPIC_EOI</span><span class=cF0>)(</span><span class=cF9>U32</span><span class=cF0> *) = </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l169"></a>}
|
|
<a name="l170"></a>
|
|
<a name="l171"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>IntEntryFree</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> irq)
|
|
<a name="l172"></a>{ </span><span class=cF2>// 'Free' a user irq num. Unsets bit in user irq bitmap.</span><span class=cF0>
|
|
<a name="l173"></a> </span><span class=cF9>I64</span><span class=cF0> res = </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l174"></a>
|
|
<a name="l175"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFE>0xFF</span><span class=cF0> >= irq >= </span><span class=cFE>0xFF</span><span class=cF0> - </span><span class=cFE>64</span><span class=cF0>)
|
|
<a name="l176"></a> </span><span class=cF1>if</span><span class=cF0> (res = </span><span class=cF5>Btr</span><span class=cF7>(</span><span class=cF0>&</span><span class=cFB>dev</span><span class=cF0>.user_int_bitmap, irq - </span><span class=cFE>192</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l177"></a> </span><span class=cF5>IntEntrySet</span><span class=cF0>(irq, &</span><span class=cFD>IntNop</span><span class=cF0>); </span><span class=cF2>// clear the irq entry vect</span><span class=cF0>
|
|
<a name="l178"></a>
|
|
<a name="l179"></a> </span><span class=cF1>return</span><span class=cF0> res;
|
|
<a name="l180"></a>}
|
|
<a name="l181"></a>
|
|
<a name="l182"></a></span><span class=cF1>interrupt</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>IntDivZero</span><span class=cF0>()
|
|
<a name="l183"></a>{
|
|
<a name="l184"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Gs</span><span class=cF0>->num)
|
|
<a name="l185"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l186"></a> </span><span class=cFB>mp_count</span><span class=cF0> = </span><span class=cFE>1</span><span class=cF0>;
|
|
<a name="l187"></a> </span><span class=cFB>debug</span><span class=cF0>.mp_crash->cpu_num = </span><span class=cF5>Gs</span><span class=cF0>->num;
|
|
<a name="l188"></a> </span><span class=cFB>debug</span><span class=cF0>.mp_crash->task = </span><span class=cF5>Fs</span><span class=cF0>;
|
|
<a name="l189"></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> </span><span class=cFE>8</span><span class=cF0>[</span><span class=cFC>RBP</span><span class=cF0>] </span><span class=cF2>//Get RIP off of stack.</span><span class=cF0>
|
|
<a name="l190"></a> </span><span class=cFB>debug</span><span class=cF0>.mp_crash->rip = </span><span class=cF5>RAXGet</span><span class=cF0>;
|
|
<a name="l191"></a> </span><span class=cFB>debug</span><span class=cF0>.mp_crash->message = </span><span class=cF6>"Div Zero"</span><span class=cF0>;
|
|
<a name="l192"></a> </span><span class=cFB>debug</span><span class=cF0>.mp_crash->message_num = </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l193"></a> </span><span class=cF5>MPInt</span><span class=cF0>(</span><span class=cF3>I_MP_CRASH</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>);
|
|
<a name="l194"></a> </span><span class=cF5>SysHlt</span><span class=cF0>;
|
|
<a name="l195"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l196"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'DivZero'</span><span class=cF0>);
|
|
<a name="l197"></a>}
|
|
<a name="l198"></a>
|
|
<a name="l199"></a></span><span class=cF1>U8</span><span class=cF0> *</span><span class=cFD>IntFaultHandlersNew</span><span class=cF0>()
|
|
<a name="l200"></a>{
|
|
<a name="l201"></a> </span><span class=cF9>I64</span><span class=cF0> i;
|
|
<a name="l202"></a> </span><span class=cF1>U8</span><span class=cF0> *res = </span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cFE>256</span><span class=cF0> * </span><span class=cFE>7</span><span class=cF0>, </span><span class=cF5>Fs</span><span class=cF0>->code_heap), *dst = res;
|
|
<a name="l203"></a>
|
|
<a name="l204"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i < </span><span class=cFE>256</span><span class=cF0>; i++)
|
|
<a name="l205"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l206"></a> *dst++ = </span><span class=cFE>0x6A</span><span class=cF0>; </span><span class=cF2>//PUSH I8 xx</span><span class=cF0>
|
|
<a name="l207"></a> *dst(</span><span class=cF1>I8</span><span class=cF0> *)++ = i;
|
|
<a name="l208"></a> *dst++ = </span><span class=cFE>0xE9</span><span class=cF0>; </span><span class=cF2>//JMP</span><span class=cF0> </span><span class=cF2>I32 xxxxxxxx</span><span class=cF0>
|
|
<a name="l209"></a> *dst(</span><span class=cF9>I32</span><span class=cF0> *) = </span><span class=cFD>INT_FAULT</span><span class=cF0> - dst - </span><span class=cFE>4</span><span class=cF0>;
|
|
<a name="l210"></a> dst += </span><span class=cFE>4</span><span class=cF0>;
|
|
<a name="l211"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l212"></a>
|
|
<a name="l213"></a> </span><span class=cF1>return</span><span class=cF0> res;
|
|
<a name="l214"></a>}
|
|
<a name="l215"></a>
|
|
<a name="l216"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>IntInit1</span><span class=cF0>()
|
|
<a name="l217"></a>{</span><span class=cF2>//Interrupt descriptor table part1.</span><span class=cF0>
|
|
<a name="l218"></a> </span><span class=cF9>I64</span><span class=cF0> i;
|
|
<a name="l219"></a> </span><span class=cF9>CSysLimitBase</span><span class=cF0> tmp_ptr;
|
|
<a name="l220"></a>
|
|
<a name="l221"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>Gs</span><span class=cF0>->num) </span><span class=cF2>//Gs is current </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l4096"><span class=cF4>CCPU</span></a><span class=cF2> struct</span><span class=cF0>
|
|
<a name="l222"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l223"></a> </span><span class=cFB>dev</span><span class=cF0>.idt = </span><span class=cF5>CAllocAligned</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CIDTEntry</span><span class=cF7>)</span><span class=cF0> * </span><span class=cFE>256</span><span class=cF0>, </span><span class=cFE>8</span><span class=cF0>);
|
|
<a name="l224"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i < </span><span class=cFE>256</span><span class=cF0>; i++)
|
|
<a name="l225"></a> </span><span class=cF5>IntEntrySet</span><span class=cF0>(i, &</span><span class=cFD>IntNop</span><span class=cF0>);
|
|
<a name="l226"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l227"></a> tmp_ptr.limit = </span><span class=cFE>256</span><span class=cF0> * </span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CIDTEntry</span><span class=cF0>) - </span><span class=cFE>1</span><span class=cF0>;
|
|
<a name="l228"></a> tmp_ptr.base = </span><span class=cFB>dev</span><span class=cF0>.idt;
|
|
<a name="l229"></a> </span><span class=cF5>RAXSet</span><span class=cF0>(&tmp_ptr);
|
|
<a name="l230"></a> </span><span class=cF1>LIDT</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> [</span><span class=cFC>RAX</span><span class=cF0>]
|
|
<a name="l231"></a>}
|
|
<a name="l232"></a>
|
|
<a name="l233"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>IntInit2</span><span class=cF0>()
|
|
<a name="l234"></a>{</span><span class=cF2>//Interrupt descriptor table part2: Core 0 Only.</span><span class=cF0>
|
|
<a name="l235"></a> </span><span class=cF9>I64</span><span class=cF0> i;
|
|
<a name="l236"></a>
|
|
<a name="l237"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
|
|
<a name="l238"></a> </span><span class=cF1>CLI</span><span class=cF0>
|
|
<a name="l239"></a> </span><span class=cF5>IntEntrySet</span><span class=cF0>(</span><span class=cF3>I_DIV_ZERO</span><span class=cF0>, &</span><span class=cFD>IntDivZero</span><span class=cF0>);
|
|
<a name="l240"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>1</span><span class=cF0>; i < </span><span class=cFE>32</span><span class=cF0>; i++)
|
|
<a name="l241"></a> </span><span class=cF5>IntEntrySet</span><span class=cF0>(i, &</span><span class=cFB>debug</span><span class=cF0>.int_fault_code[</span><span class=cFE>7</span><span class=cF0> * i]);
|
|
<a name="l242"></a></span><span class=cF2>/*In theory, we use the PIC mask reg to insure we don't get</span><span class=cF0>
|
|
<a name="l243"></a></span><span class=cF2>anything but keyboard, mouse and timer IRQs.</span><span class=cF0> </span><span class=cF2>In practice, Terry had</span><span class=cF0>
|
|
<a name="l244"></a></span><span class=cF2>gotten IRQ 0x27, he thought perhaps because he didn't initialize the APIC?</span><span class=cF0>
|
|
<a name="l245"></a></span><span class=cF2>We go ahead and ACK PIC in </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KInterrupts.ZC.html#l164"><span class=cF4>IntNop</span></a><span class=cF2>().</span><span class=cF0>
|
|
<a name="l246"></a></span><span class=cF2>He had no idea why he got a IRQ 0x27.</span><span class=cF0>
|
|
<a name="l247"></a></span><span class=cF2>*/</span><span class=cF0>
|
|
<a name="l248"></a> </span><span class=cF5>IntEntrySet</span><span class=cF0>(</span><span class=cF3>I_NMI</span><span class=cF0>, </span><span class=cFD>_SYS_HLT</span><span class=cF0>);
|
|
<a name="l249"></a> </span><span class=cF5>IntEntrySet</span><span class=cF0>(</span><span class=cF3>I_TIMER</span><span class=cF0>, </span><span class=cFD>IRQ_TIMER</span><span class=cF0>);
|
|
<a name="l250"></a> </span><span class=cF5>IntEntrySet</span><span class=cF0>(</span><span class=cF3>I_MP_CRASH</span><span class=cF0>, *</span><span class=cFD>INT_MP_CRASH_ADDR</span><span class=cF7>(</span><span class=cF9>U32</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l251"></a> </span><span class=cF5>IntEntrySet</span><span class=cF0>(</span><span class=cF3>I_WAKE</span><span class=cF0>, </span><span class=cFD>INT_WAKE</span><span class=cF0>);
|
|
<a name="l252"></a> </span><span class=cF5>IntEntrySet</span><span class=cF0>(</span><span class=cF3>I_DEBUG</span><span class=cF0>, &</span><span class=cFB>debug</span><span class=cF0>.int_fault_code[</span><span class=cFE>7</span><span class=cF0> * </span><span class=cF3>I_DEBUG</span><span class=cF0>]);
|
|
<a name="l253"></a> </span><span class=cF1>POPFD</span><span class=cF0>
|
|
<a name="l254"></a>}
|
|
</span></pre></body>
|
|
</html>
|