421 lines
48 KiB
HTML
Executable File
421 lines
48 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> {
|
|
<a name="l2"></a> </span><span class=cF1>ALIGN</span><span class=cF0> 16,</span><span class=cF3>OC_NOP</span><span class=cF0>
|
|
<a name="l3"></a></span><span class=cF1>USE16</span><span class=cF0>
|
|
<a name="l4"></a></span><span class=cF2>//See </span><a href="/Wb/Doc/MultiCore.DD.HTML#l1"><span class=cF4>TempleOS MultiCore</span></a><span class=cF2>.</span><span class=cF0>
|
|
<a name="l5"></a>
|
|
<a name="l6"></a></span><span class=cF2>//This code gets copied to </span><a href="/Wb/Kernel/KernelA.HH.HTML#l526"><span class=cF4>MP_VECT_ADDR</span></a><span class=cF2>.</span><span class=cF0>
|
|
<a name="l7"></a></span><span class=cF2>//See </span><a href="/Wb/Kernel/MultiProc.HC.HTML#l312"><span class=cF4>MemCpy(MP_VECT_ADDR</span></a><span class=cF2>.</span><span class=cF0>
|
|
<a name="l8"></a></span><span class=cFD>COREAP_16BIT_INIT</span><span class=cF0>::
|
|
<a name="l9"></a> </span><span class=cF1>JMP</span><span class=cF0> @@05
|
|
<a name="l10"></a>
|
|
<a name="l11"></a> </span><span class=cF1>ALIGN</span><span class=cF0> 4,</span><span class=cF3>OC_NOP</span><span class=cF0>
|
|
<a name="l12"></a>AP_GDT_PTR: </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="l13"></a> </span><span class=cF1>DU64</span><span class=cF0> 0;
|
|
<a name="l14"></a>
|
|
<a name="l15"></a>@@05: </span><span class=cF1>CLI</span><span class=cF0>
|
|
<a name="l16"></a> </span><span class=cF1>WBINVD</span><span class=cF0>
|
|
<a name="l17"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>AX</span><span class=cF0>,</span><span class=cF3>MP_VECT_ADDR</span><span class=cF0>/16
|
|
<a name="l18"></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="l19"></a> </span><span class=cF1>LGDT</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> [</span><span class=cF9>CAP16BitInit</span><span class=cF0>.ap_gdt_ptr] </span><span class=cF2>//See </span><a href="/Wb/Kernel/MultiProc.HC.HTML#l313"><span class=cF4>mp->ap_gdt_ptr</span></a><span class=cF0>
|
|
<a name="l20"></a>
|
|
<a name="l21"></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="l22"></a> </span><span class=cF1>MOV_CR0_EAX</span><span class=cF0>
|
|
<a name="l23"></a> </span><span class=cF1>DU8</span><span class=cF0> 0x66,0xEA; </span><span class=cF2>//JMP CGDT.cs32:AP_32BIT_INIT</span><span class=cF0>
|
|
<a name="l24"></a> </span><span class=cF1>DU32</span><span class=cF0> AP_32BIT_INIT;
|
|
<a name="l25"></a> </span><span class=cF1>DU16</span><span class=cF0> </span><span class=cF9>CGDT</span><span class=cF0>.cs32;
|
|
<a name="l26"></a></span><span class=cFD>COREAP_16BIT_INIT_END</span><span class=cF0>::
|
|
<a name="l27"></a>
|
|
<a name="l28"></a></span><span class=cF1>USE32</span><span class=cF0>
|
|
<a name="l29"></a>AP_32BIT_INIT:
|
|
<a name="l30"></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="l31"></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="l32"></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="l33"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>FS</span><span class=cF0>,</span><span class=cFC>AX</span><span class=cF0>
|
|
<a name="l34"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>GS</span><span class=cF0>,</span><span class=cFC>AX</span><span class=cF0>
|
|
<a name="l35"></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="l36"></a>
|
|
<a name="l37"></a>@@05: </span><span class=cF1>LOCK</span><span class=cF0>
|
|
<a name="l38"></a> </span><span class=cF1>BTS</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> [</span><span class=cFD>SYS_MP_CNT_LOCK</span><span class=cF0>],0
|
|
<a name="l39"></a> </span><span class=cF1>JC</span><span class=cF0> @@05
|
|
<a name="l40"></a>
|
|
<a name="l41"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>ESI</span><span class=cF0>,</span><span class=cF9>U32</span><span class=cF0> [</span><span class=cFD>SYS_MP_CNT_INITIAL</span><span class=cF0>]
|
|
<a name="l42"></a> </span><span class=cF1>LOCK</span><span class=cF0>
|
|
<a name="l43"></a> </span><span class=cF1>INC</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> [</span><span class=cFD>SYS_MP_CNT_INITIAL</span><span class=cF0>]
|
|
<a name="l44"></a> </span><span class=cF1>LOCK</span><span class=cF0>
|
|
<a name="l45"></a> </span><span class=cF1>BTR</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> [</span><span class=cFD>SYS_MP_CNT_LOCK</span><span class=cF0>],0
|
|
<a name="l46"></a>
|
|
<a name="l47"></a> </span><span class=cF1>CMP</span><span class=cF0> </span><span class=cFC>ESI</span><span class=cF0>,</span><span class=cF3>MP_PROCESSORS_NUM</span><span class=cF0>
|
|
<a name="l48"></a> </span><span class=cF1>JAE</span><span class=cF0> </span><span class=cF9>I32</span><span class=cF0> </span><span class=cFD>_SYS_HLT</span><span class=cF0>
|
|
<a name="l49"></a>
|
|
<a name="l50"></a> </span><span class=cF1>IMUL2</span><span class=cF0> </span><span class=cFC>ESI</span><span class=cF0>,</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CCPU</span><span class=cF0>)
|
|
<a name="l51"></a> </span><span class=cF1>ADD</span><span class=cF0> </span><span class=cFC>ESI</span><span class=cF0>,</span><span class=cF9>U32</span><span class=cF0> [</span><span class=cFD>SYS_CPU_STRUCTS</span><span class=cF0>]
|
|
<a name="l52"></a>
|
|
<a name="l53"></a> </span><span class=cF1>LEA</span><span class=cF0> </span><span class=cFC>ESP</span><span class=cF0>,</span><span class=cF9>U32</span><span class=cF0> </span><span class=cF9>CCPU</span><span class=cF0>.start_stk+</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CCPU</span><span class=cF0>.start_stk)[</span><span class=cFC>ESI</span><span class=cF0>]
|
|
<a name="l54"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> </span><span class=cF3>RFLAGG_START</span><span class=cF0>
|
|
<a name="l55"></a> </span><span class=cF1>POPFD</span><span class=cF0>
|
|
<a name="l56"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> 0 </span><span class=cF2>//Return from next call will be 64-bit</span><span class=cF0>
|
|
<a name="l57"></a> </span><span class=cF1>CALL</span><span class=cF0> </span><span class=cFD>SYS_ENTER_LONG_MODE</span><span class=cF0>
|
|
<a name="l58"></a></span><span class=cF1>USE64</span><span class=cF0>
|
|
<a name="l59"></a> </span><span class=cF1>FNINIT</span><span class=cF0>
|
|
<a name="l60"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>,</span><span class=cFC>RSI</span><span class=cF0>
|
|
<a name="l61"></a> </span><span class=cF1>CALL</span><span class=cF0> </span><span class=cFD>SET_GS_BASE</span><span class=cF0>
|
|
<a name="l62"></a>@@10: </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>.seth_task[</span><span class=cFC>RSI</span><span class=cF0>]
|
|
<a name="l63"></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="l64"></a> </span><span class=cF1>JZ</span><span class=cF0> @@10
|
|
<a name="l65"></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>.gs[</span><span class=cFC>RAX</span><span class=cF0>],</span><span class=cFC>RSI</span><span class=cF0>
|
|
<a name="l66"></a> </span><span class=cF1>CALL</span><span class=cF0> </span><span class=cFD>SET_FS_BASE</span><span class=cF0>
|
|
<a name="l67"></a>
|
|
<a name="l68"></a> </span><span class=cF1>JMP</span><span class=cF0> </span><span class=cF9>I32</span><span class=cF0> </span><span class=cFD>_TASK_CONTEXT_RESTORE</span><span class=cF0>
|
|
<a name="l69"></a>}
|
|
<a name="l70"></a>
|
|
<a name="l71"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>TSSBusy</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> tr,</span><span class=cF1>Bool</span><span class=cF0> val=</span><span class=cF3>OFF</span><span class=cF0>)
|
|
<a name="l72"></a>{</span><span class=cF2>//See </span><a href="/Wb/Demo/Lectures/Ring3.HC.HTML#l1"><span class=cF4>::/Demo/Lectures/Ring3.HC</span></a><span class=cF2>.</span><span class=cF0>
|
|
<a name="l73"></a> </span><span class=cF5>LBEqu</span><span class=cF0>(</span><span class=cF7>(</span><span class=cF0>&</span><span class=cFB>sys_gdt</span><span class=cF7>)(</span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>+tr+4,9,val);
|
|
<a name="l74"></a>}
|
|
<a name="l75"></a>
|
|
<a name="l76"></a></span><span class=cF9>CTSS</span><span class=cF0> *</span><span class=cFD>TSSNew</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> cpu_num)
|
|
<a name="l77"></a>{
|
|
<a name="l78"></a> </span><span class=cF9>U32</span><span class=cF0> *d,*d1;
|
|
<a name="l79"></a> </span><span class=cF9>CTSS</span><span class=cF0> *tss=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CTSS</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l80"></a> tss->io_map_offset=</span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CTSS</span><span class=cF0>.io_map);
|
|
<a name="l81"></a> </span><span class=cF5>MemSet</span><span class=cF0>(tss->io_map,0xFF,0x10000/8);
|
|
<a name="l82"></a>
|
|
<a name="l83"></a> tss->st0=</span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF3>MEM_INTERRUPT_STK</span><span class=cF0>);
|
|
<a name="l84"></a> tss->rsp0=tss->st0(</span><span class=cF1>U8</span><span class=cF0> *)+</span><span class=cF5>MSize</span><span class=cF0>(tss->st0);
|
|
<a name="l85"></a> tss->st1=</span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF3>MEM_INTERRUPT_STK</span><span class=cF0>);
|
|
<a name="l86"></a> tss->rsp1=tss->st1(</span><span class=cF1>U8</span><span class=cF0> *)+</span><span class=cF5>MSize</span><span class=cF0>(tss->st1);
|
|
<a name="l87"></a> tss->st2=</span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF3>MEM_INTERRUPT_STK</span><span class=cF0>);
|
|
<a name="l88"></a> tss->rsp2=tss->st2(</span><span class=cF1>U8</span><span class=cF0> *)+</span><span class=cF5>MSize</span><span class=cF0>(tss->st2);
|
|
<a name="l89"></a>
|
|
<a name="l90"></a> tss->tr =</span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CGDT</span><span class=cF0>.tr)+cpu_num*16;
|
|
<a name="l91"></a> tss->tr_ring3=</span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CGDT</span><span class=cF0>.tr_ring3)+cpu_num*16;
|
|
<a name="l92"></a>
|
|
<a name="l93"></a> d=(&</span><span class=cFB>sys_gdt</span><span class=cF0>)(</span><span class=cF1>U8</span><span class=cF0> *)+tss->tr;
|
|
<a name="l94"></a> d1=d(</span><span class=cF1>U8</span><span class=cF0> *)+4;
|
|
<a name="l95"></a> *d =0x0000FFFF;
|
|
<a name="l96"></a> *d1=0x008F8900;
|
|
<a name="l97"></a> d(</span><span class=cF1>U8</span><span class=cF0> *)+=2;
|
|
<a name="l98"></a> *d|=tss & 0x00FFFFFF;
|
|
<a name="l99"></a> *d1++|=tss & 0xFF000000;
|
|
<a name="l100"></a> *d1++=tss>>32;
|
|
<a name="l101"></a> *d1=0;
|
|
<a name="l102"></a>
|
|
<a name="l103"></a> d=(&</span><span class=cFB>sys_gdt</span><span class=cF0>)(</span><span class=cF1>U8</span><span class=cF0> *)+tss->tr_ring3;
|
|
<a name="l104"></a> d1=d(</span><span class=cF1>U8</span><span class=cF0> *)+4;
|
|
<a name="l105"></a> *d =0x0000FFFF;
|
|
<a name="l106"></a> *d1=0x008FE900;
|
|
<a name="l107"></a> d(</span><span class=cF1>U8</span><span class=cF0> *)+=2;
|
|
<a name="l108"></a> *d|=tss & 0x00FFFFFF;
|
|
<a name="l109"></a> *d1++|=tss & 0xFF000000;
|
|
<a name="l110"></a> *d1++=tss>>32;
|
|
<a name="l111"></a> *d1=0;
|
|
<a name="l112"></a>
|
|
<a name="l113"></a> </span><span class=cF1>return</span><span class=cF0> tss;
|
|
<a name="l114"></a>}
|
|
<a name="l115"></a>
|
|
<a name="l116"></a></span><span class=cF9>CCPU</span><span class=cF0> *</span><span class=cFD>CPUStructInit</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> num,</span><span class=cF9>CCPU</span><span class=cF0> *c,</span><span class=cF9>CTask</span><span class=cF0> *seth_task)
|
|
<a name="l117"></a>{</span><span class=cF2>//Seth is null when called by adam on CSysFixedArea.boot_cpu0</span><span class=cF0>
|
|
<a name="l118"></a> </span><span class=cF5>MemSet</span><span class=cF0>(c,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CCPU</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l119"></a> c->addr=c;
|
|
<a name="l120"></a> c->num=num;
|
|
<a name="l121"></a> c->idle_factor=0.01;
|
|
<a name="l122"></a> </span><span class=cF5>QueInit</span><span class=cF0>(&c->next_dying);
|
|
<a name="l123"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&</span><span class=cFB>sys_run_level</span><span class=cF0>,</span><span class=cF3>RLf_16MEG_ADAM_HEAP_CTRL</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l124"></a> c->idle_task=</span><span class=cF5>Spawn</span><span class=cF0>(0,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF6>"Idle Task"</span><span class=cF0>,,</span><span class=cF5>Fs</span><span class=cF0>,,0);
|
|
<a name="l125"></a> </span><span class=cF5>LBts</span><span class=cF0>(&c->idle_task->task_flags,</span><span class=cF3>TASKf_IDLE</span><span class=cF0>);
|
|
<a name="l126"></a> c->tss=</span><span class=cFD>TSSNew</span><span class=cF0>(num);
|
|
<a name="l127"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l128"></a> c->seth_task=seth_task;</span><span class=cF2>// It waits for this to be filled-in: </span><a href="/Wb/Kernel/MultiProc.HC.HTML#l62"><span class=cF4>seth_task</span></a><span class=cF0>
|
|
<a name="l129"></a> </span><span class=cF1>return</span><span class=cF0> c;
|
|
<a name="l130"></a>}
|
|
<a name="l131"></a>
|
|
<a name="l132"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>MPInt</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> num,</span><span class=cF9>I64</span><span class=cF0> cpu_num=1)
|
|
<a name="l133"></a>{</span><span class=cF2>//Generate interrupt for specified core.</span><span class=cF0>
|
|
<a name="l134"></a> </span><span class=cF1>if</span><span class=cF0> (cpu_num>=</span><span class=cFB>mp_cnt</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l135"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&</span><span class=cFB>sys_run_level</span><span class=cF0>,</span><span class=cF3>RLf_MP</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l136"></a> </span><span class=cF1>return</span><span class=cF0>;
|
|
<a name="l137"></a> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l138"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'MultCore'</span><span class=cF0>);
|
|
<a name="l139"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l140"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
|
|
<a name="l141"></a> </span><span class=cF1>CLI</span><span class=cF0> </span><span class=cF2>//Multitasking safe because each core has a local apic and IRQ's are off</span><span class=cF0>
|
|
<a name="l142"></a> </span><span class=cF1>while</span><span class=cF0> (*</span><span class=cF7>(</span><span class=cFB>dev</span><span class=cF0>.uncached_alias+</span><span class=cF3>LAPIC_ICR_LOW</span><span class=cF7>)(</span><span class=cF9>U32</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>&0x1000)
|
|
<a name="l143"></a> </span><span class=cF1>PAUSE</span><span class=cF0>
|
|
<a name="l144"></a> *(</span><span class=cFB>dev</span><span class=cF0>.uncached_alias+</span><span class=cF3>LAPIC_ICR_HIGH</span><span class=cF0>)(</span><span class=cF9>U32</span><span class=cF0> *)=</span><span class=cFB>dev</span><span class=cF0>.mp_apic_ids[cpu_num]<<24;
|
|
<a name="l145"></a> *(</span><span class=cFB>dev</span><span class=cF0>.uncached_alias+</span><span class=cF3>LAPIC_ICR_LOW</span><span class=cF0>)(</span><span class=cF9>U32</span><span class=cF0> *)=0x4000+num;
|
|
<a name="l146"></a> </span><span class=cF1>POPFD</span><span class=cF0>
|
|
<a name="l147"></a>}
|
|
<a name="l148"></a>
|
|
<a name="l149"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>MPIntAll</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> num)
|
|
<a name="l150"></a>{</span><span class=cF2>//Generate interrupt for all but own core.</span><span class=cF0>
|
|
<a name="l151"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
|
|
<a name="l152"></a> </span><span class=cF1>CLI</span><span class=cF0> </span><span class=cF2>//Multitasking safe because each core has a local apic and IRQ's are off</span><span class=cF0>
|
|
<a name="l153"></a> </span><span class=cF1>while</span><span class=cF0> (*</span><span class=cF7>(</span><span class=cFB>dev</span><span class=cF0>.uncached_alias+</span><span class=cF3>LAPIC_ICR_LOW</span><span class=cF7>)(</span><span class=cF9>U32</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>&0x1000)
|
|
<a name="l154"></a> </span><span class=cF1>PAUSE</span><span class=cF0>
|
|
<a name="l155"></a> *(</span><span class=cFB>dev</span><span class=cF0>.uncached_alias+</span><span class=cF3>LAPIC_ICR_LOW</span><span class=cF0>)(</span><span class=cF9>U32</span><span class=cF0> *)=0xC4800+num;
|
|
<a name="l156"></a> </span><span class=cF1>POPFD</span><span class=cF0>
|
|
<a name="l157"></a>}
|
|
<a name="l158"></a>
|
|
<a name="l159"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>MPNMInt</span><span class=cF0>()
|
|
<a name="l160"></a>{</span><span class=cF2>//Generate nonmaskable interrupt.</span><span class=cF0>
|
|
<a name="l161"></a> *(</span><span class=cFB>dev</span><span class=cF0>.uncached_alias+</span><span class=cF3>LAPIC_ICR_LOW</span><span class=cF0>)(</span><span class=cF9>U32</span><span class=cF0> *)=0xC4400;
|
|
<a name="l162"></a>}
|
|
<a name="l163"></a>
|
|
<a name="l164"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>MPHalt</span><span class=cF0>()
|
|
<a name="l165"></a>{</span><span class=cF2>//Halt all other cores.</span><span class=cF0>
|
|
<a name="l166"></a> </span><span class=cFB>mp_cnt</span><span class=cF0>=1;
|
|
<a name="l167"></a> </span><span class=cF5>MPNMInt</span><span class=cF0>;
|
|
<a name="l168"></a> </span><span class=cF5>Busy</span><span class=cF0>(10000);
|
|
<a name="l169"></a>}
|
|
<a name="l170"></a>
|
|
<a name="l171"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>MPAPICInit</span><span class=cF0>()
|
|
<a name="l172"></a>{</span><span class=cF2>//Called by adam during start-up</span><span class=cF0>
|
|
<a name="l173"></a></span><span class=cF2>//and other cores during initialization</span><span class=cF0>
|
|
<a name="l174"></a> </span><span class=cF2>//after </span><a href="/Wb/Kernel/MultiProc.HC.HTML#l283"><span class=cF4>Core0StartMP</span></a><span class=cF2>().</span><span class=cF0>
|
|
<a name="l175"></a> *(</span><span class=cFB>dev</span><span class=cF0>.uncached_alias+</span><span class=cF3>LAPIC_SVR</span><span class=cF0>)(</span><span class=cF9>U32</span><span class=cF0> *)|=</span><span class=cF3>LAPICF_APIC_ENABLED</span><span class=cF0>;
|
|
<a name="l176"></a> </span><span class=cFB>dev</span><span class=cF0>.mp_apic_ids[</span><span class=cF5>Gs</span><span class=cF0>->num]=*(</span><span class=cFB>dev</span><span class=cF0>.uncached_alias+</span><span class=cF3>LAPIC_APIC_ID</span><span class=cF0>)(</span><span class=cF9>U32</span><span class=cF0> *)>>24;
|
|
<a name="l177"></a> *(</span><span class=cFB>dev</span><span class=cF0>.uncached_alias+</span><span class=cF3>LAPIC_LDR</span><span class=cF0>)(</span><span class=cF9>U32</span><span class=cF0> *)=</span><span class=cFB>dev</span><span class=cF0>.mp_apic_ids[</span><span class=cF5>Gs</span><span class=cF0>->num]<<24;
|
|
<a name="l178"></a> *(</span><span class=cFB>dev</span><span class=cF0>.uncached_alias+</span><span class=cF3>LAPIC_DFR</span><span class=cF0>)(</span><span class=cF9>U32</span><span class=cF0> *)=0xF0000000;
|
|
<a name="l179"></a>
|
|
<a name="l180"></a> </span><span class=cF2>// MemSet(dev.uncached_alias+LAPIC_IRR,0,0x20);</span><span class=cF0>
|
|
<a name="l181"></a> </span><span class=cF2>// MemSet(dev.uncached_alias+LAPIC_ISR,0,0x20);</span><span class=cF0>
|
|
<a name="l182"></a> </span><span class=cF2>// MemSet(dev.uncached_alias+LAPIC_TMR,0,0x20);</span><span class=cF0>
|
|
<a name="l183"></a>
|
|
<a name="l184"></a> </span><span class=cF5>SetRAX</span><span class=cF0>(</span><span class=cF5>Gs</span><span class=cF0>->tss->tr);
|
|
<a name="l185"></a> </span><span class=cF1>LTR</span><span class=cF0> </span><span class=cFC>AX</span><span class=cF0>
|
|
<a name="l186"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Gs</span><span class=cF0>->num) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l187"></a> </span><span class=cFD>IntInit1</span><span class=cF0>;
|
|
<a name="l188"></a> </span><span class=cF5>SetRFlags</span><span class=cF0>(</span><span class=cF3>RFLAGG_NORMAL</span><span class=cF0>);
|
|
<a name="l189"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l190"></a>}
|
|
<a name="l191"></a>
|
|
<a name="l192"></a>#</span><span class=cF1>assert</span><span class=cF0> !</span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CJobCtrl</span><span class=cF0>.next_waiting)
|
|
<a name="l193"></a>
|
|
<a name="l194"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>CoreAPSethTask</span><span class=cF0>()
|
|
<a name="l195"></a>{
|
|
<a name="l196"></a> </span><span class=cF9>CJobCtrl</span><span class=cF0> *ctrl=&</span><span class=cF5>Fs</span><span class=cF0>->srv_ctrl;
|
|
<a name="l197"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l198"></a> </span><span class=cF1>STI</span><span class=cF0>
|
|
<a name="l199"></a> </span><span class=cF1>do</span><span class=cF0> {
|
|
<a name="l200"></a> </span><span class=cF5>TaskKillDying</span><span class=cF0>;
|
|
<a name="l201"></a> </span><span class=cF1>do</span><span class=cF0> </span><span class=cF1>PAUSE</span><span class=cF0>
|
|
<a name="l202"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&ctrl->flags,</span><span class=cF3>JOBCf_LOCKED</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l203"></a> } </span><span class=cF1>while</span><span class=cF0> (ctrl->next_waiting!=ctrl && </span><span class=cFD>JobRunOne</span><span class=cF7>(</span><span class=cF5>GetRFlags</span><span class=cF0>,ctrl</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l204"></a> </span><span class=cF1>CLI</span><span class=cF0>
|
|
<a name="l205"></a> </span><span class=cF5>LBts</span><span class=cF0>(&</span><span class=cF5>Fs</span><span class=cF0>->task_flags,</span><span class=cF3>TASKf_AWAITING_MSG</span><span class=cF0>);
|
|
<a name="l206"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&ctrl->flags,</span><span class=cF3>JOBCf_LOCKED</span><span class=cF0>);
|
|
<a name="l207"></a> </span><span class=cF5>LBts</span><span class=cF0>(&</span><span class=cF5>Fs</span><span class=cF0>->task_flags,</span><span class=cF3>TASKf_IDLE</span><span class=cF0>);
|
|
<a name="l208"></a> </span><span class=cF5>Yield</span><span class=cF0>;
|
|
<a name="l209"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&</span><span class=cF5>Fs</span><span class=cF0>->task_flags,</span><span class=cF3>TASKf_IDLE</span><span class=cF0>);
|
|
<a name="l210"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l211"></a>}
|
|
<a name="l212"></a>
|
|
<a name="l213"></a></span><span class=cF9>CJob</span><span class=cF0> *</span><span class=cF5>JobQue</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> </span><span class=cF7>(</span><span class=cF0>*fp_addr</span><span class=cF7>)(</span><span class=cF1>U8</span><span class=cF0> *data</span><span class=cF7>)</span><span class=cF0>,</span><span class=cF1>U8</span><span class=cF0> *data=</span><span class=cF3>NULL</span><span class=cF0>,
|
|
<a name="l214"></a> </span><span class=cF9>I64</span><span class=cF0> target_cpu=1,</span><span class=cF9>I64</span><span class=cF0> flags=1<<</span><span class=cF3>JOBf_FREE_ON_COMPLETE</span><span class=cF0>,
|
|
<a name="l215"></a> </span><span class=cF9>I64</span><span class=cF0> job_code=</span><span class=cF3>JOBT_CALL</span><span class=cF0>,</span><span class=cF1>U8</span><span class=cF0> *aux_str=</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF9>I64</span><span class=cF0> aux1=0,</span><span class=cF9>I64</span><span class=cF0> aux2=0)
|
|
<a name="l216"></a>{</span><span class=cF2>//Queue multicore jobs, handled by Seth tasks.</span><span class=cF0>
|
|
<a name="l217"></a></span><span class=cF2>//Set flags to zero if you wish to get the res.</span><span class=cF0>
|
|
<a name="l218"></a> </span><span class=cF2>//See </span><a href="/Wb/Demo/MultiCore/Lock.HC.HTML#l1"><span class=cF4>::/Demo/MultiCore/Lock.HC</span></a><span class=cF0>
|
|
<a name="l219"></a> </span><span class=cF9>CJobCtrl</span><span class=cF0> *ctrl;
|
|
<a name="l220"></a> </span><span class=cF9>CJob</span><span class=cF0> *tmpc;
|
|
<a name="l221"></a> </span><span class=cF9>CTask</span><span class=cF0> *seth;
|
|
<a name="l222"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>0<=target_cpu<</span><span class=cFB>mp_cnt</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l223"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'MultCore'</span><span class=cF0>);
|
|
<a name="l224"></a> tmpc=</span><span class=cF5>ACAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CJob</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l225"></a> </span><span class=cF1>if</span><span class=cF0> (aux_str)
|
|
<a name="l226"></a> tmpc->aux_str=</span><span class=cF5>AStrNew</span><span class=cF0>(aux_str);
|
|
<a name="l227"></a> tmpc->job_code=job_code;
|
|
<a name="l228"></a> tmpc->addr=fp_addr;
|
|
<a name="l229"></a> tmpc->fun_arg=data;
|
|
<a name="l230"></a> tmpc->flags=flags;
|
|
<a name="l231"></a> tmpc->aux1=aux1;
|
|
<a name="l232"></a> tmpc->aux2=aux2;
|
|
<a name="l233"></a> seth=</span><span class=cFB>cpu_structs</span><span class=cF0>[target_cpu].seth_task;
|
|
<a name="l234"></a> tmpc->ctrl=ctrl=&seth->srv_ctrl;
|
|
<a name="l235"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
|
|
<a name="l236"></a> </span><span class=cF1>CLI</span><span class=cF0>
|
|
<a name="l237"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&ctrl->flags,</span><span class=cF3>JOBCf_LOCKED</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l238"></a> </span><span class=cF5>Yield</span><span class=cF0>;
|
|
<a name="l239"></a> </span><span class=cF1>if</span><span class=cF0> (ctrl->next_waiting==ctrl && </span><span class=cF5>LBtr</span><span class=cF7>(</span><span class=cF0>&seth->task_flags,</span><span class=cF3>TASKf_AWAITING_MSG</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l240"></a> </span><span class=cF5>MPInt</span><span class=cF0>(</span><span class=cF3>I_WAKE</span><span class=cF0>,target_cpu);
|
|
<a name="l241"></a> </span><span class=cF5>QueIns</span><span class=cF0>(tmpc,ctrl->last_waiting);
|
|
<a name="l242"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&ctrl->flags,</span><span class=cF3>JOBCf_LOCKED</span><span class=cF0>);
|
|
<a name="l243"></a> </span><span class=cF1>POPFD</span><span class=cF0>
|
|
<a name="l244"></a> </span><span class=cF1>return</span><span class=cF0> tmpc;
|
|
<a name="l245"></a>}
|
|
<a name="l246"></a>
|
|
<a name="l247"></a></span><span class=cF9>CTask</span><span class=cF0> *</span><span class=cF5>SpawnQue</span><span class=cF0>(</span><span class=cF1>U0</span><span class=cF0> </span><span class=cF7>(</span><span class=cF0>*fp_addr</span><span class=cF7>)(</span><span class=cF1>U8</span><span class=cF0> *data</span><span class=cF7>)</span><span class=cF0>,</span><span class=cF1>U8</span><span class=cF0> *data=</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF1>U8</span><span class=cF0> *task_name=</span><span class=cF3>NULL</span><span class=cF0>,
|
|
<a name="l248"></a> </span><span class=cF9>I64</span><span class=cF0> target_cpu, </span><span class=cF9>CTask</span><span class=cF0> *parent=</span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF2>//NULL means adam</span><span class=cF0>
|
|
<a name="l249"></a> </span><span class=cF9>I64</span><span class=cF0> stk_size=0,</span><span class=cF9>I64</span><span class=cF0> flags=1<<</span><span class=cF3>JOBf_ADD_TO_QUE</span><span class=cF0>)
|
|
<a name="l250"></a>{
|
|
<a name="l251"></a> </span><span class=cF9>CTask</span><span class=cF0> *res;
|
|
<a name="l252"></a> </span><span class=cF9>CJob</span><span class=cF0> *tmpc=</span><span class=cF5>JobQue</span><span class=cF0>(fp_addr,data,target_cpu,
|
|
<a name="l253"></a> flags,</span><span class=cF3>JOBT_SPAWN_TASK</span><span class=cF0>,task_name,parent,stk_size);
|
|
<a name="l254"></a> </span><span class=cF9>CJobCtrl</span><span class=cF0> *ctrl;
|
|
<a name="l255"></a>
|
|
<a name="l256"></a> </span><span class=cF1>while</span><span class=cF0> (!</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&tmpc->flags,</span><span class=cF3>JOBf_DONE</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l257"></a> </span><span class=cF5>LBts</span><span class=cF0>(&</span><span class=cF5>Fs</span><span class=cF0>->task_flags,</span><span class=cF3>TASKf_IDLE</span><span class=cF0>);
|
|
<a name="l258"></a> </span><span class=cF5>Yield</span><span class=cF0>;
|
|
<a name="l259"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l260"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&</span><span class=cF5>Fs</span><span class=cF0>->task_flags,</span><span class=cF3>TASKf_IDLE</span><span class=cF0>);
|
|
<a name="l261"></a>
|
|
<a name="l262"></a> res=tmpc->spawned_task;
|
|
<a name="l263"></a> ctrl=tmpc->ctrl;
|
|
<a name="l264"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
|
|
<a name="l265"></a> </span><span class=cF1>CLI</span><span class=cF0>
|
|
<a name="l266"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&ctrl->flags,</span><span class=cF3>JOBCf_LOCKED</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l267"></a> </span><span class=cF5>Yield</span><span class=cF0>;
|
|
<a name="l268"></a> </span><span class=cF5>QueRem</span><span class=cF0>(tmpc);
|
|
<a name="l269"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&ctrl->flags,</span><span class=cF3>JOBCf_LOCKED</span><span class=cF0>);
|
|
<a name="l270"></a> </span><span class=cF1>POPFD</span><span class=cF0>
|
|
<a name="l271"></a> </span><span class=cF5>JobDel</span><span class=cF0>(tmpc);
|
|
<a name="l272"></a> </span><span class=cF1>return</span><span class=cF0> res;
|
|
<a name="l273"></a>}
|
|
<a name="l274"></a>
|
|
<a name="l275"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>CoreAPSethInit</span><span class=cF0>()
|
|
<a name="l276"></a>{</span><span class=cF2>//Called by multicore's seth task after </span><a href="/Wb/Kernel/MultiProc.HC.HTML#l283"><span class=cF4>Core0StartMP</span></a><span class=cF2>()</span><span class=cF0>
|
|
<a name="l277"></a></span><span class=cF2>//as the first thing a CPU does before waiting for jobs.</span><span class=cF0>
|
|
<a name="l278"></a> </span><span class=cFD>MPAPICInit</span><span class=cF0>;
|
|
<a name="l279"></a> </span><span class=cF5>Fs</span><span class=cF0>->rip=&</span><span class=cF5>CoreAPSethTask</span><span class=cF0>;
|
|
<a name="l280"></a> </span><span class=cF5>TaskContextRestore</span><span class=cF0>;
|
|
<a name="l281"></a>}
|
|
<a name="l282"></a>
|
|
<a name="l283"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>Core0StartMP</span><span class=cF0>()
|
|
<a name="l284"></a>{</span><span class=cF2>//Called by adam during </span><a href="/Wb/Kernel/KMain.HC.HTML#l199"><span class=cF4>start-up</span></a><span class=cF2>.</span><span class=cF0>
|
|
<a name="l285"></a> </span><span class=cF9>CTask</span><span class=cF0> *task;
|
|
<a name="l286"></a> </span><span class=cF1>U8</span><span class=cF0> buf[</span><span class=cF3>STR_LEN</span><span class=cF0>];
|
|
<a name="l287"></a> </span><span class=cF9>CAP16BitInit</span><span class=cF0> *mp=</span><span class=cF3>MP_VECT_ADDR</span><span class=cF0>;
|
|
<a name="l288"></a> </span><span class=cF9>CCPU</span><span class=cF0> *c;
|
|
<a name="l289"></a> </span><span class=cF9>I64</span><span class=cF0> i,my_mp_cnt;
|
|
<a name="l290"></a> </span><span class=cF9>CRAXRBCRCXRDX</span><span class=cF0> ee;
|
|
<a name="l291"></a>
|
|
<a name="l292"></a> </span><span class=cF5>CPUId</span><span class=cF0>(0x1,&ee);
|
|
<a name="l293"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&ee.rdx,9</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l294"></a> </span><span class=cF1>return</span><span class=cF0>;
|
|
<a name="l295"></a>
|
|
<a name="l296"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
|
|
<a name="l297"></a> </span><span class=cF1>CLI</span><span class=cF0>
|
|
<a name="l298"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>mp_cnt</span><span class=cF0>>1) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l299"></a> my_mp_cnt=</span><span class=cFB>mp_cnt</span><span class=cF0>;
|
|
<a name="l300"></a> </span><span class=cF5>MPHalt</span><span class=cF0>; </span><span class=cF2>//sets mp_cnt to 1</span><span class=cF0>
|
|
<a name="l301"></a> </span><span class=cF1>for</span><span class=cF0> (i=1;i<my_mp_cnt;i++) {
|
|
<a name="l302"></a> c=&</span><span class=cFB>cpu_structs</span><span class=cF0>[i];
|
|
<a name="l303"></a> </span><span class=cFD>JobQueDel</span><span class=cF0>(&c->seth_task->srv_ctrl.next_waiting);
|
|
<a name="l304"></a> </span><span class=cFD>JobQueDel</span><span class=cF0>(&c->seth_task->srv_ctrl.next_done);
|
|
<a name="l305"></a> }
|
|
<a name="l306"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l307"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&</span><span class=cFB>cpu_structs</span><span class=cF0>[1],0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CCPU</span><span class=cF7>)</span><span class=cF0>*</span><span class=cF7>(</span><span class=cF3>MP_PROCESSORS_NUM</span><span class=cF0>-1</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l308"></a>
|
|
<a name="l309"></a> </span><span class=cF2>//When you start-up other cores, they jump to an addr</span><span class=cF0>
|
|
<a name="l310"></a> </span><span class=cF2>//specified by a byte vect number, </span><a href="/Wb/Kernel/KernelA.HH.HTML#l525"><span class=cF4>MPN_VECT</span></a><span class=cF2> which corresponds</span><span class=cF0>
|
|
<a name="l311"></a> </span><span class=cF2>//to a location 4096*vect number, </span><a href="/Wb/Kernel/KernelA.HH.HTML#l526"><span class=cF4>MP_VECT_ADDR</span></a><span class=cF2>.</span><span class=cF0>
|
|
<a name="l312"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(mp,</span><span class=cFD>COREAP_16BIT_INIT</span><span class=cF0>,</span><span class=cFD>COREAP_16BIT_INIT_END</span><span class=cF0>-</span><span class=cFD>COREAP_16BIT_INIT</span><span class=cF0>);
|
|
<a name="l313"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(&mp->ap_gdt_ptr,</span><span class=cFD>SYS_GDT_PTR</span><span class=cF0>,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CSysLimitBase</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l314"></a> </span><span class=cFB>mp_cnt_initial</span><span class=cF0>=</span><span class=cFB>mp_cnt</span><span class=cF0>=1;
|
|
<a name="l315"></a> </span><span class=cFB>mp_cnt_lock</span><span class=cF0>=0;
|
|
<a name="l316"></a>
|
|
<a name="l317"></a> *(</span><span class=cFB>dev</span><span class=cF0>.uncached_alias+</span><span class=cF3>LAPIC_LVT_ERR</span><span class=cF0>)(</span><span class=cF9>U32</span><span class=cF0> *)=
|
|
<a name="l318"></a> *(</span><span class=cFB>dev</span><span class=cF0>.uncached_alias+</span><span class=cF3>LAPIC_LVT_ERR</span><span class=cF0>)(</span><span class=cF9>U32</span><span class=cF0> *)&0xFFFFFF00+</span><span class=cF3>MPN_VECT</span><span class=cF0>;
|
|
<a name="l319"></a> </span><span class=cF1>WBINVD</span><span class=cF0> </span><span class=cF2>//Not sure why this is needed.</span><span class=cF0> </span><span class=cF2>Might just need delay. </span><a href="/Wb/Kernel/KernelB.HH.HTML#l169"><span class=cF4>MemCpy</span></a><span class=cF2> above?</span><span class=cF0>
|
|
<a name="l320"></a>
|
|
<a name="l321"></a> *(</span><span class=cFB>dev</span><span class=cF0>.uncached_alias+</span><span class=cF3>LAPIC_ICR_LOW</span><span class=cF0>)(</span><span class=cF9>U32</span><span class=cF0> *)=0xC4500; </span><span class=cF2>//assert init IPI</span><span class=cF0>
|
|
<a name="l322"></a> </span><span class=cF5>Busy</span><span class=cF0>(10000);
|
|
<a name="l323"></a>
|
|
<a name="l324"></a> *(</span><span class=cFB>dev</span><span class=cF0>.uncached_alias+</span><span class=cF3>LAPIC_ICR_LOW</span><span class=cF0>)(</span><span class=cF9>U32</span><span class=cF0> *)=0xC4600+</span><span class=cF3>MPN_VECT</span><span class=cF0>; </span><span class=cF2>//start-up</span><span class=cF0>
|
|
<a name="l325"></a> </span><span class=cF5>Busy</span><span class=cF0>(200);
|
|
<a name="l326"></a> *(</span><span class=cFB>dev</span><span class=cF0>.uncached_alias+</span><span class=cF3>LAPIC_ICR_LOW</span><span class=cF0>)(</span><span class=cF9>U32</span><span class=cF0> *)=0xC4600+</span><span class=cF3>MPN_VECT</span><span class=cF0>;
|
|
<a name="l327"></a>
|
|
<a name="l328"></a> </span><span class=cF5>Busy</span><span class=cF0>(100000);
|
|
<a name="l329"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<10000;i++)
|
|
<a name="l330"></a> </span><span class=cF5>LBts</span><span class=cF0>(&</span><span class=cFB>mp_cnt_lock</span><span class=cF0>,0); </span><span class=cF2>//Don't let more through</span><span class=cF0>
|
|
<a name="l331"></a> my_mp_cnt=</span><span class=cFB>mp_cnt_initial</span><span class=cF0>;
|
|
<a name="l332"></a>
|
|
<a name="l333"></a> </span><span class=cF1>if</span><span class=cF0> (my_mp_cnt></span><span class=cF3>MP_PROCESSORS_NUM</span><span class=cF0>)
|
|
<a name="l334"></a> my_mp_cnt=</span><span class=cF3>MP_PROCESSORS_NUM</span><span class=cF0>;
|
|
<a name="l335"></a>
|
|
<a name="l336"></a> </span><span class=cF1>for</span><span class=cF0> (i=1;i<my_mp_cnt;i++) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l337"></a> </span><span class=cF5>StrPrint</span><span class=cF0>(buf,</span><span class=cF6>"Seth Task CPU%02X"</span><span class=cF0>,i);
|
|
<a name="l338"></a> task=</span><span class=cF5>Spawn</span><span class=cF0>(&</span><span class=cFD>CoreAPSethInit</span><span class=cF0>,</span><span class=cF3>NULL</span><span class=cF0>,buf,,,</span><span class=cF3>MEM_SETH_STK</span><span class=cF0>,0);
|
|
<a name="l339"></a> task->rflags=</span><span class=cF3>RFLAGG_START</span><span class=cF0>;
|
|
<a name="l340"></a></span><span class=cF2>//</span><a href="/Wb/Kernel/KernelA.HH.HTML#l3271"><span class=cF4>CTask</span></a><span class=cF2> alloced off this core's seth_task's heap (Which is Adam)</span><span class=cF0>
|
|
<a name="l341"></a> </span><span class=cFD>CPUStructInit</span><span class=cF0>(i,&</span><span class=cFB>cpu_structs</span><span class=cF0>[i],task);
|
|
<a name="l342"></a> </span><span class=cF1>WBINVD</span><span class=cF0> </span><span class=cF2>//Not sure why this is needed. Might just need delay.</span><span class=cF0>
|
|
<a name="l343"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l344"></a>
|
|
<a name="l345"></a> </span><span class=cF2>//Make sure they're all up-and-running</span><span class=cF0>
|
|
<a name="l346"></a> </span><span class=cF1>for</span><span class=cF0> (i=1;i<my_mp_cnt;i++)
|
|
<a name="l347"></a> </span><span class=cF1>while</span><span class=cF0> (!</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&</span><span class=cFB>cpu_structs</span><span class=cF0>[i].seth_task->task_flags,</span><span class=cF3>TASKf_AWAITING_MSG</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l348"></a> </span><span class=cF1>PAUSE</span><span class=cF0>;
|
|
<a name="l349"></a>
|
|
<a name="l350"></a> </span><span class=cF1>POPFD</span><span class=cF0>
|
|
<a name="l351"></a> </span><span class=cFB>mp_cnt</span><span class=cF0>=my_mp_cnt; </span><span class=cF2>//Finalize cnt</span><span class=cF0>
|
|
<a name="l352"></a>}
|
|
<a name="l353"></a>
|
|
<a name="l354"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>Core0Init</span><span class=cF0>()
|
|
<a name="l355"></a>{</span><span class=cF2>//Called by adam during start-up</span><span class=cF0>
|
|
<a name="l356"></a> </span><span class=cF9>CRAXRBCRCXRDX</span><span class=cF0> ee;
|
|
<a name="l357"></a> </span><span class=cF5>CPUId</span><span class=cF0>(0x1,&ee);
|
|
<a name="l358"></a>
|
|
<a name="l359"></a> </span><span class=cFB>mp_cnt_initial</span><span class=cF0>=</span><span class=cFB>mp_cnt</span><span class=cF0>=1;
|
|
<a name="l360"></a> </span><span class=cFB>mp_cnt_lock</span><span class=cF0>=0;
|
|
<a name="l361"></a>
|
|
<a name="l362"></a> </span><span class=cFB>dbg</span><span class=cF0>.mp_crash=</span><span class=cF5>ACAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CMPCrash</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l363"></a>
|
|
<a name="l364"></a> </span><span class=cF2>//Must be in code heap because init code uses 32 bit addr of cpu_struct</span><span class=cF0>
|
|
<a name="l365"></a> </span><span class=cFB>adam_task</span><span class=cF0>->gs=</span><span class=cFB>cpu_structs</span><span class=cF0>=
|
|
<a name="l366"></a> </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CCPU</span><span class=cF7>)</span><span class=cF0>*</span><span class=cF3>MP_PROCESSORS_NUM</span><span class=cF0>,</span><span class=cF5>Fs</span><span class=cF0>->code_heap);
|
|
<a name="l367"></a> </span><span class=cFD>CPUStructInit</span><span class=cF0>(0,</span><span class=cFB>cpu_structs</span><span class=cF0>,</span><span class=cFB>adam_task</span><span class=cF0>);
|
|
<a name="l368"></a> </span><span class=cF1>asm</span><span class=cF0> </span><span class=cF7>{</span><span class=cF2>//RAX has GS</span><span class=cF0>
|
|
<a name="l369"></a> </span><span class=cF1>IMPORT</span><span class=cF0> </span><span class=cFD>SET_GS_BASE</span><span class=cF0>;
|
|
<a name="l370"></a> </span><span class=cF1>CALL</span><span class=cF0> </span><span class=cFD>SET_GS_BASE</span><span class=cF0>
|
|
<a name="l371"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l372"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&ee.rdx,9</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l373"></a></span><span class=cF2>//Unnecessary?</span><span class=cF0>
|
|
<a name="l374"></a> </span><span class=cF2>//</span><span class=cF0> </span><span class=cF2> SetMSR(IA32_LAPIC_BASE,dev.uncached_alias+LAPIC_BASE+0x900);</span><span class=cF0>
|
|
<a name="l375"></a> </span><span class=cFD>MPAPICInit</span><span class=cF0>;
|
|
<a name="l376"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l377"></a>}
|
|
<a name="l378"></a>
|
|
<a name="l379"></a></span><span class=cF1>interrupt</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>IntMPCrash</span><span class=cF0>()
|
|
<a name="l380"></a>{</span><span class=cF2>//Entering the debugger from another core causes an interrupt on Core0</span><span class=cF0>
|
|
<a name="l381"></a></span><span class=cF2>//Which calls this routine.</span><span class=cF0>
|
|
<a name="l382"></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> *)=0;
|
|
<a name="l383"></a> </span><span class=cFB>mp_cnt</span><span class=cF0>=1;
|
|
<a name="l384"></a> </span><span class=cF5>Raw</span><span class=cF0>(</span><span class=cF3>ON</span><span class=cF0>);
|
|
<a name="l385"></a> </span><span class=cFB>text</span><span class=cF0>.raw_flags|=</span><span class=cF3>RWF_SHOW_DOLLAR</span><span class=cF0>;
|
|
<a name="l386"></a> </span><span class=cF6>"MP Crash CPU%02X Task:%08X\n"</span><span class=cF0>
|
|
<a name="l387"></a> </span><span class=cF6>"RIP:%P\n"</span><span class=cF0>,</span><span class=cFB>dbg</span><span class=cF0>.mp_crash->cpu_num,</span><span class=cFB>dbg</span><span class=cF0>.mp_crash->task,</span><span class=cFB>dbg</span><span class=cF0>.mp_crash->rip;
|
|
<a name="l388"></a> </span><span class=cF5>Panic</span><span class=cF0>(</span><span class=cFB>dbg</span><span class=cF0>.mp_crash->msg,</span><span class=cFB>dbg</span><span class=cF0>.mp_crash->msg_num);
|
|
<a name="l389"></a>}
|
|
</span></pre></body>
|
|
</html>
|