ZealOS/docs/Kernel/KDebug.html
TomAwezome 5002ed5880 Fix HTML index file generation.
Fix HTML generation tab width.
2021-07-04 18:11:43 -04:00

764 lines
77 KiB
HTML
Executable file

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V0.05">
<style type="text/css">
body {background-color:#000000;}
.cF0{color:#ffffff;background-color:#000000;}
.cF1{color:#3465a4;background-color:#000000;}
.cF2{color:#4e9a06;background-color:#000000;}
.cF3{color:#06989a;background-color:#000000;}
.cF4{color:#a24444;background-color:#000000;}
.cF5{color:#75507b;background-color:#000000;}
.cF6{color:#ce982f;background-color:#000000;}
.cF7{color:#bcc0b9;background-color:#000000;}
.cF8{color:#555753;background-color:#000000;}
.cF9{color:#729fcf;background-color:#000000;}
.cFA{color:#82bc49;background-color:#000000;}
.cFB{color:#34e2e2;background-color:#000000;}
.cFC{color:#ac3535;background-color:#000000;}
.cFD{color:#ad7fa8;background-color:#000000;}
.cFE{color:#fce94f;background-color:#000000;}
.cFF{color:#000000;background-color:#000000;}
</style>
</head>
<body>
<pre style="font-family:courier;font-size:10pt">
<a name="l1"></a><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>CheckPtr</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *ptr)
<a name="l2"></a>{</span><span class=cF2>//Check if addr is valid ptr.</span><span class=cF0>
<a name="l3"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>mem_heap_base</span><span class=cF0> &lt;= ptr &lt;= </span><span class=cFB>mem_mapped_space</span><span class=cF0>)
<a name="l4"></a> </span><span class=cF1>return</span><span class=cF0> *</span><span class=cF5>MemPageTable</span><span class=cF0>(ptr) &amp; </span><span class=cFE>1</span><span class=cF0>;
<a name="l5"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l6"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFB>mem_boot_base</span><span class=cF0> &lt; ptr &lt; </span><span class=cF3>VGAM_GRAPHICS</span><span class=cF0>;
<a name="l7"></a>}
<a name="l8"></a>
<a name="l9"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>CheckCodePtr</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *ptr)
<a name="l10"></a>{</span><span class=cF2>//Check if addr is valid code addr.</span><span class=cF0>
<a name="l11"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>mem_heap_base</span><span class=cF0> &lt;= ptr &lt;= </span><span class=cFB>mem_heap_limit</span><span class=cF0>)
<a name="l12"></a> </span><span class=cF1>return</span><span class=cF0> *</span><span class=cF5>MemPageTable</span><span class=cF0>(ptr) &amp; </span><span class=cFE>1</span><span class=cF0>;
<a name="l13"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l14"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFB>mem_boot_base</span><span class=cF0> &lt; ptr &lt; </span><span class=cF3>VGAM_GRAPHICS</span><span class=cF0>;
<a name="l15"></a>}
<a name="l16"></a>
<a name="l17"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>CheckOnStack</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *ptr, </span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>)
<a name="l18"></a>{</span><span class=cF2>//Check if addr is valid stack addr.</span><span class=cF0>
<a name="l19"></a> </span><span class=cF1>Bool</span><span class=cF0> res = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l20"></a>
<a name="l21"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l22"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l23"></a> </span><span class=cF1>if</span><span class=cF0> (task)
<a name="l24"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l25"></a> </span><span class=cF1>if</span><span class=cF0> (&amp;task-&gt;stack-&gt;stack_base &lt;= ptr &lt;= </span><span class=cF7>(</span><span class=cF0>&amp;task-&gt;stack-&gt;stack_base</span><span class=cF7>)(</span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0> + task-&gt;stack-&gt;stack_size)
<a name="l26"></a> res = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l27"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l28"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>mem_heap_base</span><span class=cF0> &lt;= ptr &lt;= </span><span class=cFB>mem_heap_limit</span><span class=cF0>)
<a name="l29"></a> res = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l30"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l31"></a>
<a name="l32"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l33"></a>}
<a name="l34"></a>
<a name="l35"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>UnusedStack</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>)
<a name="l36"></a>{</span><span class=cF2>//Count of usused bytes in task's stack.</span><span class=cF0>
<a name="l37"></a> </span><span class=cF9>I64</span><span class=cF0> res;
<a name="l38"></a>
<a name="l39"></a> </span><span class=cF1>if</span><span class=cF0> (!task)
<a name="l40"></a> task = </span><span class=cF5>Fs</span><span class=cF0>;
<a name="l41"></a>
<a name="l42"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l43"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l44"></a> </span><span class=cF1>if</span><span class=cF0> (task == </span><span class=cF5>Fs</span><span class=cF0>)
<a name="l45"></a> res = </span><span class=cF5>RSPGet</span><span class=cF0>()(</span><span class=cF1>U8</span><span class=cF0> *) - (&amp;task-&gt;stack-&gt;stack_base)(</span><span class=cF1>U8</span><span class=cF0> *);
<a name="l46"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l47"></a> res = task-&gt;rsp(</span><span class=cF1>U8</span><span class=cF0> *) - (&amp;task-&gt;stack-&gt;stack_base)(</span><span class=cF1>U8</span><span class=cF0> *);
<a name="l48"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l49"></a>
<a name="l50"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l51"></a>}
<a name="l52"></a>
<a name="l53"></a></span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF5>Caller</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> num=</span><span class=cFE>1</span><span class=cF0>)
<a name="l54"></a>{</span><span class=cF2>//Returns the addr of the fun which called this one,</span><span class=cF0>
<a name="l55"></a></span><span class=cF2>//or the caller of the caller, etc.</span><span class=cF0>
<a name="l56"></a> </span><span class=cF1>U8</span><span class=cF0> **rbp = </span><span class=cF5>RBPGet</span><span class=cF0>, **ptr;
<a name="l57"></a>
<a name="l58"></a> </span><span class=cF1>while</span><span class=cF0> (num--)
<a name="l59"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l60"></a> </span><span class=cF1>if</span><span class=cF0> (rbp &gt;= *rbp)
<a name="l61"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l62"></a> rbp = *rbp;
<a name="l63"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>CheckOnStack</span><span class=cF7>(</span><span class=cF0>rbp, </span><span class=cF5>Fs</span><span class=cF7>)</span><span class=cF0>)
<a name="l64"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l65"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l66"></a> ptr = rbp + </span><span class=cFE>1</span><span class=cF0>;
<a name="l67"></a> </span><span class=cF1>return</span><span class=cF0> *ptr;
<a name="l68"></a>}
<a name="l69"></a>
<a name="l70"></a></span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF5>TaskCaller</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF9>I64</span><span class=cF0> num=</span><span class=cFE>0</span><span class=cF0>, </span><span class=cF1>Bool</span><span class=cF0> saved_context=</span><span class=cF3>FALSE</span><span class=cF0>)
<a name="l71"></a>{</span><span class=cF2>//Fetches addr of Nth caller on task's stack.</span><span class=cF0>
<a name="l72"></a> </span><span class=cF1>U8</span><span class=cF0> **ptr, **rbp, **rsp;
<a name="l73"></a>
<a name="l74"></a> </span><span class=cF1>if</span><span class=cF0> (!task)
<a name="l75"></a> task = </span><span class=cF5>Fs</span><span class=cF0>;
<a name="l76"></a> </span><span class=cF1>if</span><span class=cF0> (!saved_context &amp;&amp; task == </span><span class=cF5>Fs</span><span class=cF0>)
<a name="l77"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>Caller</span><span class=cF0>(num + </span><span class=cFE>1</span><span class=cF0>);
<a name="l78"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>TaskValidate</span><span class=cF7>(</span><span class=cF0>task</span><span class=cF7>)</span><span class=cF0>)
<a name="l79"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l80"></a> rbp = task-&gt;rbp;
<a name="l81"></a> rsp = task-&gt;rsp;
<a name="l82"></a> </span><span class=cF1>if</span><span class=cF0> (num)
<a name="l83"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l84"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>CheckOnStack</span><span class=cF7>(</span><span class=cF0>rbp, task</span><span class=cF7>)</span><span class=cF0>)
<a name="l85"></a> {
<a name="l86"></a> ptr = rbp + </span><span class=cFE>1</span><span class=cF0>;
<a name="l87"></a> </span><span class=cF1>if</span><span class=cF0> (! --num)
<a name="l88"></a> </span><span class=cF1>return</span><span class=cF0> *ptr;
<a name="l89"></a> </span><span class=cF1>if</span><span class=cF0> (rbp &gt;= *rbp)
<a name="l90"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l91"></a> rbp = *rbp;
<a name="l92"></a> }
<a name="l93"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l94"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l95"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l96"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l97"></a> </span><span class=cF1>if</span><span class=cF0> (task-&gt;rip == </span><span class=cFD>_RET</span><span class=cF0>)
<a name="l98"></a> </span><span class=cF1>return</span><span class=cF0> *rsp;
<a name="l99"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l100"></a> </span><span class=cF1>return</span><span class=cF0> task-&gt;rip;
<a name="l101"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l102"></a>}
<a name="l103"></a>#</span><span class=cF1>define</span><span class=cF0> STACK_REP_LEN </span><span class=cFE>32</span><span class=cF0>
<a name="l104"></a>
<a name="l105"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>StackRep</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>)
<a name="l106"></a>{</span><span class=cF2>//Reports whats on the stack.</span><span class=cF0>
<a name="l107"></a> </span><span class=cF9>I64</span><span class=cF0> i, j, addr, **rbp, **rsp, *my_rsp[STACK_REP_LEN];
<a name="l108"></a> </span><span class=cF9>CHashTable</span><span class=cF0> *old_hash = </span><span class=cF5>Fs</span><span class=cF0>-&gt;hash_table;
<a name="l109"></a>
<a name="l110"></a> </span><span class=cF1>if</span><span class=cF0> (!task)
<a name="l111"></a> task = </span><span class=cF5>Fs</span><span class=cF0>;
<a name="l112"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>TaskValidate</span><span class=cF7>(</span><span class=cF0>task</span><span class=cF7>)</span><span class=cF0>)
<a name="l113"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l114"></a>
<a name="l115"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l116"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l117"></a> </span><span class=cF1>if</span><span class=cF0> (task == </span><span class=cF5>Fs</span><span class=cF0>)
<a name="l118"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l119"></a> rbp = </span><span class=cF5>RBPGet</span><span class=cF0>;
<a name="l120"></a> rsp = rbp + </span><span class=cFE>3</span><span class=cF0>;
<a name="l121"></a> rbp = *rbp;
<a name="l122"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l123"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l124"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l125"></a> rsp = task-&gt;rsp;
<a name="l126"></a> rbp = task-&gt;rbp;
<a name="l127"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l128"></a> </span><span class=cF1>if</span><span class=cF0> (task-&gt;rip == </span><span class=cFD>_RET</span><span class=cF0>)
<a name="l129"></a> addr = *rsp;
<a name="l130"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l131"></a> addr = task-&gt;rip;
<a name="l132"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(my_rsp, rsp, STACK_REP_LEN * </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>);
<a name="l133"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l134"></a>
<a name="l135"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;hash_table = task-&gt;hash_table;
<a name="l136"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; STACK_REP_LEN; i++)
<a name="l137"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l138"></a> </span><span class=cF6>&quot;%08X [RSP+%04X]: %016X &quot;</span><span class=cF0>, rsp + i, i * </span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *), my_rsp[i];
<a name="l139"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l140"></a> {
<a name="l141"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>&amp;task-&gt;stack-&gt;stack_base &lt;= rbp &lt; (&amp;task-&gt;stack-&gt;stack_base)(</span><span class=cF1>U8</span><span class=cF0> *) + task-&gt;stack-&gt;stack_size</span><span class=cF7>)</span><span class=cF0>)
<a name="l142"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l143"></a> j = rbp - rsp;
<a name="l144"></a> </span><span class=cF1>if</span><span class=cF0> (j &gt;= i)
<a name="l145"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l146"></a> addr = my_rsp[j + </span><span class=cFE>1</span><span class=cF0>];
<a name="l147"></a> </span><span class=cF1>if</span><span class=cF0> (rbp &gt;= my_rsp[j])
<a name="l148"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l149"></a> rbp = my_rsp[j];
<a name="l150"></a> }
<a name="l151"></a> </span><span class=cF1>if</span><span class=cF0> (my_rsp[i] == addr)
<a name="l152"></a> </span><span class=cF6>&quot;$RED$&quot;</span><span class=cF0>;
<a name="l153"></a> </span><span class=cF6>&quot;%P$FG$\n&quot;</span><span class=cF0>, my_rsp[i];
<a name="l154"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l155"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l156"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;hash_table = old_hash;
<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>CallerRep</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> **rbp=</span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>)
<a name="l160"></a>{</span><span class=cF2>//Prints a report of calling routines.</span><span class=cF0>
<a name="l161"></a> </span><span class=cF9>I64</span><span class=cF0> **ptr;
<a name="l162"></a>
<a name="l163"></a> </span><span class=cF1>if</span><span class=cF0> (!task)
<a name="l164"></a> task = </span><span class=cF5>Fs</span><span class=cF0>;
<a name="l165"></a> </span><span class=cF1>if</span><span class=cF0> (!rbp)
<a name="l166"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l167"></a> </span><span class=cF1>if</span><span class=cF0> (task == </span><span class=cF5>Fs</span><span class=cF0>)
<a name="l168"></a> rbp = </span><span class=cF5>RBPGet</span><span class=cF0>;
<a name="l169"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l170"></a> rbp = task-&gt;rbp;
<a name="l171"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l172"></a> </span><span class=cF6>&quot;CallerRep:\n&quot;</span><span class=cF0>;
<a name="l173"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>CheckOnStack</span><span class=cF7>(</span><span class=cF0>rbp, task</span><span class=cF7>)</span><span class=cF0>)
<a name="l174"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l175"></a> ptr = rbp + </span><span class=cFE>1</span><span class=cF0>;
<a name="l176"></a> </span><span class=cF6>&quot;%08X:%08tX:%P\n&quot;</span><span class=cF0>, ptr, *ptr, *ptr;
<a name="l177"></a> </span><span class=cF1>if</span><span class=cF0> (rbp &gt;= *rbp)
<a name="l178"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l179"></a> rbp = *rbp;
<a name="l180"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l181"></a>}
<a name="l182"></a>
<a name="l183"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>D</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *addr, </span><span class=cF9>I64</span><span class=cF0> count=</span><span class=cFE>0x80</span><span class=cF0>, </span><span class=cF1>Bool</span><span class=cF0> show_offset=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l184"></a>{</span><span class=cF2>//Dump mem, showing offsets.</span><span class=cF0>
<a name="l185"></a></span><span class=cF2>//See </span><a href="https://tomawezome.github.io/ZealOS/System/DolDoc/DocPutS.html#l366"><span class=cF4>DocD</span></a><span class=cF2>() for a live dump.</span><span class=cF0>
<a name="l186"></a> </span><span class=cF9>I64</span><span class=cF0> i, j, ch;
<a name="l187"></a> </span><span class=cF1>U8</span><span class=cF0> *ptr = addr;
<a name="l188"></a>
<a name="l189"></a> </span><span class=cF1>while</span><span class=cF0> (count)
<a name="l190"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l191"></a> </span><span class=cF1>if</span><span class=cF0> (show_offset)
<a name="l192"></a> </span><span class=cF6>&quot;%08X &quot;</span><span class=cF0>, ptr - addr;
<a name="l193"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l194"></a> </span><span class=cF6>&quot;%010X &quot;</span><span class=cF0>, ptr;
<a name="l195"></a> </span><span class=cF1>if</span><span class=cF0> (count &gt; </span><span class=cFE>16</span><span class=cF0>)
<a name="l196"></a> j = </span><span class=cFE>16</span><span class=cF0>;
<a name="l197"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l198"></a> j = count;
<a name="l199"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; j; i++)
<a name="l200"></a> </span><span class=cF6>&quot;%02X &quot;</span><span class=cF0>, ptr[i];
<a name="l201"></a> </span><span class=cF1>for</span><span class=cF0> (; i &lt; </span><span class=cFE>16</span><span class=cF0>; i++)
<a name="l202"></a> </span><span class=cF6>&quot; &quot;</span><span class=cF0>;
<a name="l203"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; j; i++)
<a name="l204"></a> {
<a name="l205"></a> ch = ptr[i];
<a name="l206"></a> </span><span class=cF1>if</span><span class=cF0> (ch &lt; </span><span class=cF3>CH_SPACE</span><span class=cF0> || ch == </span><span class=cF3>CH_BACKSPACE</span><span class=cF0>)
<a name="l207"></a> ch = </span><span class=cF6>'.'</span><span class=cF0>;
<a name="l208"></a> </span><span class=cF6>''</span><span class=cF0> ch;
<a name="l209"></a> </span><span class=cF1>if</span><span class=cF0> (ch == </span><span class=cF6>'$'</span><span class=cF0>)
<a name="l210"></a> </span><span class=cF6>''</span><span class=cF0> ch;
<a name="l211"></a> }
<a name="l212"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l213"></a> count -= j;
<a name="l214"></a> ptr += j;
<a name="l215"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l216"></a>}
<a name="l217"></a>
<a name="l218"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>Dm</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *addr, </span><span class=cF9>I64</span><span class=cF0> count=</span><span class=cFE>0x80</span><span class=cF0>)
<a name="l219"></a>{</span><span class=cF2>//Show mem addr, not offsets.</span><span class=cF0>
<a name="l220"></a> </span><span class=cF5>D</span><span class=cF0>(addr, count, </span><span class=cF3>FALSE</span><span class=cF0>);
<a name="l221"></a>}
<a name="l222"></a>
<a name="l223"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>Da</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> **addr, </span><span class=cF9>I64</span><span class=cF0> count=</span><span class=cFE>0x10</span><span class=cF0>)
<a name="l224"></a>{</span><span class=cF2>//Dump mem, showing symbolic addresses.</span><span class=cF0>
<a name="l225"></a> </span><span class=cF1>while</span><span class=cF0> (count-- &gt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l226"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l227"></a> </span><span class=cF6>&quot;%08X:%08X,%P\n&quot;</span><span class=cF0>, addr, *addr, *addr;
<a name="l228"></a> addr++;
<a name="l229"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l230"></a>}
<a name="l231"></a>
<a name="l232"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>RawPrint</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> mS=</span><span class=cFE>100</span><span class=cF0>, </span><span class=cF1>U8</span><span class=cF0> *format, ...)
<a name="l233"></a>{</span><span class=cF2>//Print using </span><a href="https://tomawezome.github.io/ZealOS/Kernel/KMisc.html#l257"><span class=cF4>Raw</span></a><span class=cF2> screen output for a length of time.</span><span class=cF0>
<a name="l234"></a></span><span class=cF2>//Your heap must be good.</span><span class=cF0>
<a name="l235"></a> </span><span class=cF1>U8</span><span class=cF0> *buf = </span><span class=cF5>StrPrintJoin</span><span class=cF0>(</span><span class=cF3>NULL</span><span class=cF0>, format, argc, argv);
<a name="l236"></a> </span><span class=cF1>Bool</span><span class=cF0> old_raw, old_input_filter;
<a name="l237"></a>
<a name="l238"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l239"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l240"></a> old_raw = </span><span class=cF5>Raw</span><span class=cF0>(</span><span class=cF3>ON</span><span class=cF0>);
<a name="l241"></a> old_input_filter = </span><span class=cF5>LBtr</span><span class=cF0>(&amp;</span><span class=cF5>Fs</span><span class=cF0>-&gt;task_flags, </span><span class=cF3>TASKf_INPUT_FILTER_TASK</span><span class=cF0>);
<a name="l242"></a> </span><span class=cF6>&quot;%s&quot;</span><span class=cF0>, buf;
<a name="l243"></a> </span><span class=cF5>Busy</span><span class=cF0>(mS &lt;&lt; </span><span class=cFE>10</span><span class=cF0>);
<a name="l244"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l245"></a>
<a name="l246"></a> </span><span class=cF5>LBEqual</span><span class=cF0>(&amp;</span><span class=cF5>Fs</span><span class=cF0>-&gt;task_flags, </span><span class=cF3>TASKf_INPUT_FILTER_TASK</span><span class=cF0>, old_input_filter);
<a name="l247"></a> </span><span class=cF5>Raw</span><span class=cF0>(old_raw);
<a name="l248"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
<a name="l249"></a>}
<a name="l250"></a>
<a name="l251"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>RawD</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> mS=</span><span class=cFE>100</span><span class=cF0>, </span><span class=cF1>U8</span><span class=cF0> *addr, </span><span class=cF9>I64</span><span class=cF0> count=</span><span class=cFE>0x80</span><span class=cF0>)
<a name="l252"></a>{</span><span class=cF2>//Dumps a block of mem using </span><a href="https://tomawezome.github.io/ZealOS/Kernel/KMisc.html#l257"><span class=cF4>Raw</span></a><span class=cF0>
<a name="l253"></a></span><span class=cF2>//screen output for a fixed length</span><span class=cF0>
<a name="l254"></a> </span><span class=cF2>//of time.</span><span class=cF0>
<a name="l255"></a> </span><span class=cF1>Bool</span><span class=cF0> old_raw, old_input_filter;
<a name="l256"></a>
<a name="l257"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l258"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l259"></a> old_raw = </span><span class=cF5>Raw</span><span class=cF0>(</span><span class=cF3>ON</span><span class=cF0>);
<a name="l260"></a> old_input_filter = </span><span class=cF5>LBtr</span><span class=cF0>(&amp;</span><span class=cF5>Fs</span><span class=cF0>-&gt;task_flags, </span><span class=cF3>TASKf_INPUT_FILTER_TASK</span><span class=cF0>);
<a name="l261"></a> </span><span class=cF5>D</span><span class=cF0>(addr, count);
<a name="l262"></a> </span><span class=cF5>Busy</span><span class=cF0>(mS &lt;&lt; </span><span class=cFE>10</span><span class=cF0>);
<a name="l263"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l264"></a>
<a name="l265"></a> </span><span class=cF5>LBEqual</span><span class=cF0>(&amp;</span><span class=cF5>Fs</span><span class=cF0>-&gt;task_flags, </span><span class=cF3>TASKf_INPUT_FILTER_TASK</span><span class=cF0>, old_input_filter);
<a name="l266"></a> </span><span class=cF5>Raw</span><span class=cF0>(old_raw);
<a name="l267"></a>}
<a name="l268"></a>
<a name="l269"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>RawDm</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> mS=</span><span class=cFE>100</span><span class=cF0>, </span><span class=cF1>U8</span><span class=cF0> *addr, </span><span class=cF9>I64</span><span class=cF0> count=</span><span class=cFE>0x80</span><span class=cF0>)
<a name="l270"></a>{</span><span class=cF2>//Dumps a block of mem using </span><a href="https://tomawezome.github.io/ZealOS/Kernel/KMisc.html#l257"><span class=cF4>Raw</span></a><span class=cF0>
<a name="l271"></a></span><span class=cF2>//screen output for a fixed length</span><span class=cF0>
<a name="l272"></a> </span><span class=cF2>//of time.</span><span class=cF0>
<a name="l273"></a> </span><span class=cF1>Bool</span><span class=cF0> old_raw, old_input_filter;
<a name="l274"></a>
<a name="l275"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l276"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l277"></a> old_raw = </span><span class=cF5>Raw</span><span class=cF0>(</span><span class=cF3>ON</span><span class=cF0>);
<a name="l278"></a> old_input_filter = </span><span class=cF5>LBtr</span><span class=cF0>(&amp;</span><span class=cF5>Fs</span><span class=cF0>-&gt;task_flags, </span><span class=cF3>TASKf_INPUT_FILTER_TASK</span><span class=cF0>);
<a name="l279"></a> </span><span class=cF5>Dm</span><span class=cF0>(addr, count);
<a name="l280"></a> </span><span class=cF5>Busy</span><span class=cF0>(mS &lt;&lt; </span><span class=cFE>10</span><span class=cF0>);
<a name="l281"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l282"></a>
<a name="l283"></a> </span><span class=cF5>LBEqual</span><span class=cF0>(&amp;</span><span class=cF5>Fs</span><span class=cF0>-&gt;task_flags, </span><span class=cF3>TASKf_INPUT_FILTER_TASK</span><span class=cF0>, old_input_filter);
<a name="l284"></a> </span><span class=cF5>Raw</span><span class=cF0>(old_raw);
<a name="l285"></a>}
<a name="l286"></a>
<a name="l287"></a></span><span class=cF9>I64</span><span class=cF0> *</span><span class=cF5>TaskRegAddr</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *task, </span><span class=cF9>I64</span><span class=cF0> reg_num)
<a name="l288"></a>{
<a name="l289"></a> </span><span class=cF1>switch</span><span class=cF0> (reg_num)
<a name="l290"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l291"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>REG_RAX</span><span class=cF0>: </span><span class=cF1>return</span><span class=cF0> &amp;task-&gt;rax;
<a name="l292"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>REG_RCX</span><span class=cF0>: </span><span class=cF1>return</span><span class=cF0> &amp;task-&gt;rcx;
<a name="l293"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>REG_RDX</span><span class=cF0>: </span><span class=cF1>return</span><span class=cF0> &amp;task-&gt;rdx;
<a name="l294"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>REG_RBX</span><span class=cF0>: </span><span class=cF1>return</span><span class=cF0> &amp;task-&gt;rbx;
<a name="l295"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>REG_RSP</span><span class=cF0>: </span><span class=cF1>return</span><span class=cF0> &amp;task-&gt;rsp;
<a name="l296"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>REG_RBP</span><span class=cF0>: </span><span class=cF1>return</span><span class=cF0> &amp;task-&gt;rbp;
<a name="l297"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>REG_RSI</span><span class=cF0>: </span><span class=cF1>return</span><span class=cF0> &amp;task-&gt;rsi;
<a name="l298"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>REG_RDI</span><span class=cF0>: </span><span class=cF1>return</span><span class=cF0> &amp;task-&gt;rdi;
<a name="l299"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>8</span><span class=cF0> : </span><span class=cF1>return</span><span class=cF0> &amp;task-&gt;r8;
<a name="l300"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>9</span><span class=cF0> : </span><span class=cF1>return</span><span class=cF0> &amp;task-&gt;r9;
<a name="l301"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>10</span><span class=cF0>: </span><span class=cF1>return</span><span class=cF0> &amp;task-&gt;r10;
<a name="l302"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>11</span><span class=cF0>: </span><span class=cF1>return</span><span class=cF0> &amp;task-&gt;r11;
<a name="l303"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>12</span><span class=cF0>: </span><span class=cF1>return</span><span class=cF0> &amp;task-&gt;r12;
<a name="l304"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>13</span><span class=cF0>: </span><span class=cF1>return</span><span class=cF0> &amp;task-&gt;r13;
<a name="l305"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>14</span><span class=cF0>: </span><span class=cF1>return</span><span class=cF0> &amp;task-&gt;r14;
<a name="l306"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>15</span><span class=cF0>: </span><span class=cF1>return</span><span class=cF0> &amp;task-&gt;r15;
<a name="l307"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l308"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l309"></a>}
<a name="l310"></a>
<a name="l311"></a>#</span><span class=cF1>define</span><span class=cF0> RAWDR_COL (</span><span class=cFB>text</span><span class=cF0>.cols - </span><span class=cFE>40</span><span class=cF0>)
<a name="l312"></a>
<a name="l313"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>RawDr</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>)
<a name="l314"></a>{
<a name="l315"></a> </span><span class=cF9>I64</span><span class=cF0> i, j, old_col = </span><span class=cFB>text</span><span class=cF0>.raw_col;
<a name="l316"></a> </span><span class=cF1>Bool</span><span class=cF0> old_raw = </span><span class=cF5>Raw</span><span class=cF0>(</span><span class=cF3>ON</span><span class=cF0>);
<a name="l317"></a> </span><span class=cF1>U8</span><span class=cF0> buf[</span><span class=cFE>200</span><span class=cF0>];
<a name="l318"></a>
<a name="l319"></a> </span><span class=cF1>if</span><span class=cF0> (!task)
<a name="l320"></a> task = </span><span class=cF5>Fs</span><span class=cF0>;
<a name="l321"></a>
<a name="l322"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; </span><span class=cFE>16</span><span class=cF0>; i++)
<a name="l323"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l324"></a> </span><span class=cFB>text</span><span class=cF0>.raw_col = i * </span><span class=cFB>text</span><span class=cF0>.cols + RAWDR_COL;
<a name="l325"></a> </span><span class=cF6>&quot;.%3Z:%016X\n&quot;</span><span class=cF0>, i, </span><span class=cF6>&quot;ST_U64_REGS&quot;</span><span class=cF0>, *</span><span class=cF5>TaskRegAddr</span><span class=cF0>(task, i);
<a name="l326"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l327"></a>
<a name="l328"></a> </span><span class=cFB>text</span><span class=cF0>.raw_col = i++ * </span><span class=cFB>text</span><span class=cF0>.cols + RAWDR_COL;
<a name="l329"></a> </span><span class=cF6>&quot;.RIP:%016X\n&quot;</span><span class=cF0>, task-&gt;rip;
<a name="l330"></a>
<a name="l331"></a> </span><span class=cFB>text</span><span class=cF0>.raw_col = i++ * </span><span class=cFB>text</span><span class=cF0>.cols + RAWDR_COL;
<a name="l332"></a> </span><span class=cF6>&quot;.%-*tp\n&quot;</span><span class=cF0>, </span><span class=cFB>text</span><span class=cF0>.cols - (RAWDR_COL + </span><span class=cFE>1</span><span class=cF0>) - </span><span class=cFE>1</span><span class=cF0>, </span><span class=cF5>Fs</span><span class=cF0>-&gt;rip;
<a name="l333"></a>
<a name="l334"></a> </span><span class=cFB>text</span><span class=cF0>.raw_col = i++ * </span><span class=cFB>text</span><span class=cF0>.cols + RAWDR_COL;
<a name="l335"></a> </span><span class=cF6>'.'</span><span class=cF0>;
<a name="l336"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;</span><span class=cFB>sys_run_level</span><span class=cF0>, </span><span class=cF3>RLf_COMPILER</span><span class=cF7>)</span><span class=cF0>)
<a name="l337"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l338"></a> j = </span><span class=cF5>Fs</span><span class=cF0>-&gt;rip;
<a name="l339"></a> </span><span class=cF5>Ui</span><span class=cF0>(buf, &amp;j,,, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l340"></a> </span><span class=cF6>&quot;%s&quot;</span><span class=cF0>, buf;
<a name="l341"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l342"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l343"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l344"></a>
<a name="l345"></a> </span><span class=cFB>text</span><span class=cF0>.raw_col = i * </span><span class=cFB>text</span><span class=cF0>.cols + RAWDR_COL;
<a name="l346"></a> </span><span class=cF6>'.'</span><span class=cF0>;
<a name="l347"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; </span><span class=cFB>text</span><span class=cF0>.cols - RAWDR_COL - </span><span class=cFE>1</span><span class=cF0>; j++)
<a name="l348"></a> </span><span class=cF6>'.'</span><span class=cF0>;
<a name="l349"></a>
<a name="l350"></a> </span><span class=cFB>text</span><span class=cF0>.raw_col = old_col;
<a name="l351"></a> </span><span class=cF5>Raw</span><span class=cF0>(old_raw);
<a name="l352"></a>}
<a name="l353"></a>
<a name="l354"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>Dr</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>)
<a name="l355"></a>{</span><span class=cF2>//Dump regs</span><span class=cF0>
<a name="l356"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l357"></a>
<a name="l358"></a> </span><span class=cF1>if</span><span class=cF0> (!task)
<a name="l359"></a> task = </span><span class=cF5>Fs</span><span class=cF0>;
<a name="l360"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; </span><span class=cFE>16</span><span class=cF0>; i++)
<a name="l361"></a> </span><span class=cF6>&quot;%3Z:%016X\n&quot;</span><span class=cF0>, i, </span><span class=cF6>&quot;ST_U64_REGS&quot;</span><span class=cF0>, *</span><span class=cF5>TaskRegAddr</span><span class=cF0>(task, i);
<a name="l362"></a> </span><span class=cF6>&quot;RIP:%016X\n&quot;</span><span class=cF0>, task-&gt;rip;
<a name="l363"></a>}
<a name="l364"></a>
<a name="l365"></a></span><span class=cF1>U8</span><span class=cF0> *</span><span class=cFD>SysGetStr2</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0>)
<a name="l366"></a>{
<a name="l367"></a> </span><span class=cF1>U8</span><span class=cF0> buf[</span><span class=cFE>512</span><span class=cF0>];
<a name="l368"></a>
<a name="l369"></a> </span><span class=cF5>StrNGet</span><span class=cF0>(buf, </span><span class=cFE>512</span><span class=cF0>, </span><span class=cF3>FALSE</span><span class=cF0>);
<a name="l370"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>StrNew</span><span class=cF0>(buf);
<a name="l371"></a>}
<a name="l372"></a>
<a name="l373"></a></span><span class=cF9>CBpt</span><span class=cF0> *</span><span class=cF5>BptFind</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *needle_addr, </span><span class=cF9>CTask</span><span class=cF0> *haystack_task=</span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF1>Bool</span><span class=cF0> rem=</span><span class=cF3>FALSE</span><span class=cF0>)
<a name="l374"></a>{
<a name="l375"></a> </span><span class=cF9>CBpt</span><span class=cF0> *res=</span><span class=cF3>NULL</span><span class=cF0>, *tmpb, *tmpb1, *tmpb2;
<a name="l376"></a>
<a name="l377"></a> </span><span class=cF1>if</span><span class=cF0> (!haystack_task)
<a name="l378"></a> haystack_task = </span><span class=cF5>Fs</span><span class=cF0>;
<a name="l379"></a>
<a name="l380"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l381"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l382"></a> tmpb1 = &amp;haystack_task-&gt;bpt_list;
<a name="l383"></a> tmpb = haystack_task-&gt;bpt_list;
<a name="l384"></a> </span><span class=cF1>while</span><span class=cF0> (tmpb)
<a name="l385"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l386"></a> tmpb2 = tmpb-&gt;next;
<a name="l387"></a> </span><span class=cF1>if</span><span class=cF0> (tmpb-&gt;addr == needle_addr)
<a name="l388"></a> {
<a name="l389"></a> res = tmpb;
<a name="l390"></a> </span><span class=cF1>if</span><span class=cF0> (rem)
<a name="l391"></a> tmpb1-&gt;next = tmpb2;
<a name="l392"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l393"></a> tmpb1 = &amp;tmpb-&gt;next;
<a name="l394"></a> }
<a name="l395"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l396"></a> tmpb1 = &amp;tmpb-&gt;next;
<a name="l397"></a> tmpb = tmpb2;
<a name="l398"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l399"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l400"></a>
<a name="l401"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l402"></a>}
<a name="l403"></a>
<a name="l404"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>BptS</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *addr, </span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF1>Bool</span><span class=cF0> live=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l405"></a>{</span><span class=cF2>//Set breakpoint.</span><span class=cF0>
<a name="l406"></a> </span><span class=cF9>CBpt</span><span class=cF0> *tmpb;
<a name="l407"></a> </span><span class=cF1>Bool</span><span class=cF0> res = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l408"></a> </span><span class=cF1>if</span><span class=cF0> (!task)
<a name="l409"></a> task = </span><span class=cF5>Fs</span><span class=cF0>;
<a name="l410"></a>
<a name="l411"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l412"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l413"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>tmpb = </span><span class=cF5>BptFind</span><span class=cF0>(addr, task, </span><span class=cF3>FALSE</span><span class=cF0>)</span><span class=cF7>)</span><span class=cF0>)
<a name="l414"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l415"></a> tmpb = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CBpt</span><span class=cF7>)</span><span class=cF0>, task);
<a name="l416"></a> tmpb-&gt;addr = addr;
<a name="l417"></a> tmpb-&gt;val = *addr;
<a name="l418"></a> res = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l419"></a> tmpb-&gt;next = task-&gt;bpt_list;
<a name="l420"></a>
<a name="l421"></a> task-&gt;bpt_list = tmpb;
<a name="l422"></a> </span><span class=cF1>if</span><span class=cF0> (task == </span><span class=cF5>Fs</span><span class=cF0> &amp;&amp; live)
<a name="l423"></a> *addr = </span><span class=cF3>OC_BPT</span><span class=cF0>;
<a name="l424"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l425"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l426"></a>
<a name="l427"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l428"></a>}
<a name="l429"></a>
<a name="l430"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>BptR</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *addr, </span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF1>Bool</span><span class=cF0> live=</span><span class=cF3>TRUE</span><span class=cF0>, </span><span class=cF1>Bool</span><span class=cF0> rem=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l431"></a>{</span><span class=cF2>//Remove breakpoint.</span><span class=cF0>
<a name="l432"></a> </span><span class=cF9>CBpt</span><span class=cF0> *tmpb;
<a name="l433"></a> </span><span class=cF1>Bool</span><span class=cF0> res = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l434"></a>
<a name="l435"></a> </span><span class=cF1>if</span><span class=cF0> (!task)
<a name="l436"></a> task = </span><span class=cF5>Fs</span><span class=cF0>;
<a name="l437"></a>
<a name="l438"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l439"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l440"></a> </span><span class=cF1>if</span><span class=cF0> (tmpb = </span><span class=cF5>BptFind</span><span class=cF7>(</span><span class=cF0>addr, task, rem</span><span class=cF7>)</span><span class=cF0>)
<a name="l441"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l442"></a> </span><span class=cF1>if</span><span class=cF0> (task == </span><span class=cF5>Fs</span><span class=cF0> &amp;&amp; live)
<a name="l443"></a> *tmpb-&gt;addr = tmpb-&gt;val;
<a name="l444"></a> res = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l445"></a> </span><span class=cF1>if</span><span class=cF0> (rem)
<a name="l446"></a> </span><span class=cF5>Free</span><span class=cF0>(tmpb);
<a name="l447"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l448"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l449"></a>
<a name="l450"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l451"></a>}
<a name="l452"></a>
<a name="l453"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>B</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *addr, </span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF1>Bool</span><span class=cF0> live=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l454"></a>{</span><span class=cF2>//Toggle breakpoint.</span><span class=cF0>
<a name="l455"></a></span><span class=cF2>//Return: TRUE if removed.</span><span class=cF0>
<a name="l456"></a> </span><span class=cF1>Bool</span><span class=cF0> res = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l457"></a>
<a name="l458"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l459"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l460"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>BptFind</span><span class=cF7>(</span><span class=cF0>addr, task, </span><span class=cF3>FALSE</span><span class=cF7>)</span><span class=cF0>)
<a name="l461"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l462"></a> </span><span class=cF5>BptR</span><span class=cF0>(addr, task, live, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l463"></a> res = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l464"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l465"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l466"></a> </span><span class=cF5>BptS</span><span class=cF0>(addr, task, live);
<a name="l467"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l468"></a>
<a name="l469"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l470"></a>}
<a name="l471"></a>
<a name="l472"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>B2</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF1>Bool</span><span class=cF0> live=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l473"></a>{</span><span class=cF2>//Remove all breakpoints.</span><span class=cF0>
<a name="l474"></a></span><span class=cF2>//Return: count of removed.</span><span class=cF0>
<a name="l475"></a> </span><span class=cF9>I64</span><span class=cF0> res = </span><span class=cFE>0</span><span class=cF0>;
<a name="l476"></a> </span><span class=cF9>CBpt</span><span class=cF0> *tmpb, *tmpb1;
<a name="l477"></a>
<a name="l478"></a> </span><span class=cF1>if</span><span class=cF0> (!task)
<a name="l479"></a> task = </span><span class=cF5>Fs</span><span class=cF0>;
<a name="l480"></a>
<a name="l481"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l482"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l483"></a> tmpb = task-&gt;bpt_list;
<a name="l484"></a> task-&gt;bpt_list = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l485"></a> </span><span class=cF1>while</span><span class=cF0> (tmpb)
<a name="l486"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l487"></a> tmpb1 = tmpb-&gt;next;
<a name="l488"></a> </span><span class=cF1>if</span><span class=cF0> (task == </span><span class=cF5>Fs</span><span class=cF0> &amp;&amp; live)
<a name="l489"></a> *tmpb-&gt;addr = tmpb-&gt;val;
<a name="l490"></a> </span><span class=cF5>Free</span><span class=cF0>(tmpb);
<a name="l491"></a> tmpb = tmpb1;
<a name="l492"></a> res++;
<a name="l493"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l494"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l495"></a>
<a name="l496"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l497"></a>}
<a name="l498"></a>
<a name="l499"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>G</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *ip=</span><span class=cF3>INVALID_PTR</span><span class=cF0>, </span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>)
<a name="l500"></a>{</span><span class=cF2>//Go</span><span class=cF0>
<a name="l501"></a> </span><span class=cF1>if</span><span class=cF0> (!task)
<a name="l502"></a> task = </span><span class=cF5>Fs</span><span class=cF0>;
<a name="l503"></a> </span><span class=cF1>if</span><span class=cF0> (ip != </span><span class=cF3>INVALID_PTR</span><span class=cF0>)
<a name="l504"></a> task-&gt;rip = ip;
<a name="l505"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>BptFind</span><span class=cF7>(</span><span class=cF0>task-&gt;rip, task</span><span class=cF7>)</span><span class=cF0>)
<a name="l506"></a> </span><span class=cF6>&quot;\nDo one of the following, first:\n&quot;</span><span class=cF0>
<a name="l507"></a> </span><span class=cF6>&quot;&gt;S;\t\t\t//Single step\n&quot;</span><span class=cF0>
<a name="l508"></a> </span><span class=cF6>&quot;&gt;B2;\t\t\t//Clear all break points\n&quot;</span><span class=cF0>
<a name="l509"></a> </span><span class=cF6>&quot;&gt;G2;\t\t\t//Clear all break points and Go\n\n&quot;</span><span class=cF0>
<a name="l510"></a> </span><span class=cF6>&quot;After resuming, &lt;CTRL-ALT-n&gt; next focus task\n&quot;</span><span class=cF0>
<a name="l511"></a> </span><span class=cF6>&quot;After resuming, &lt;CTRL-ALT-v&gt; flushes screen VGA cache\n&quot;</span><span class=cF0>;
<a name="l512"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l513"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l514"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;task-&gt;task_flags, </span><span class=cF3>TASKf_DISABLE_BPTS</span><span class=cF0>);
<a name="l515"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;task-&gt;rflags, </span><span class=cF3>RFLAGf_TRAP</span><span class=cF0>);</span><span class=cF2>//No single step</span><span class=cF0>
<a name="l516"></a> </span><span class=cF5>Suspend</span><span class=cF0>(task, </span><span class=cF3>FALSE</span><span class=cF0>);
<a name="l517"></a> </span><span class=cF1>if</span><span class=cF0> (task == </span><span class=cF5>Fs</span><span class=cF0>)
<a name="l518"></a> {
<a name="l519"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>IsDebugMode</span><span class=cF0> &amp;&amp; task-&gt;next_cc != &amp;task-&gt;next_cc)
<a name="l520"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l521"></a> </span><span class=cF6>&quot;Exit Debug\n&quot;</span><span class=cF0>;
<a name="l522"></a> </span><span class=cF5>Btr</span><span class=cF0>(&amp;task-&gt;last_cc-&gt;flags, </span><span class=cF3>CCf_PROMPT</span><span class=cF0>);
<a name="l523"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l524"></a> }
<a name="l525"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l526"></a> </span><span class=cF5>Exit</span><span class=cF0>;
<a name="l527"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l528"></a>}
<a name="l529"></a>
<a name="l530"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>G2</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *ip=</span><span class=cF3>INVALID_PTR</span><span class=cF0>, </span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>)
<a name="l531"></a>{</span><span class=cF2>//Remove all breakpoints and Go.</span><span class=cF0>
<a name="l532"></a> </span><span class=cF1>if</span><span class=cF0> (!task)
<a name="l533"></a> task = </span><span class=cF5>Fs</span><span class=cF0>;
<a name="l534"></a> </span><span class=cF5>B2</span><span class=cF0>(task);
<a name="l535"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>ext</span><span class=cF0>[</span><span class=cF3>EXT_WIN_FOCUS</span><span class=cF0>])
<a name="l536"></a> </span><span class=cF5>CallExtNum</span><span class=cF0>(</span><span class=cF3>EXT_WIN_FOCUS</span><span class=cF0>, </span><span class=cFB>debug</span><span class=cF0>.focus_task);
<a name="l537"></a> </span><span class=cF5>LFBFlush</span><span class=cF0>;
<a name="l538"></a> </span><span class=cF5>G</span><span class=cF0>(ip, task);
<a name="l539"></a>}
<a name="l540"></a>
<a name="l541"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>S</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *ip=</span><span class=cF3>INVALID_PTR</span><span class=cF0>, </span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>) </span><span class=cF2>//Single-step.</span><span class=cF0>
<a name="l542"></a>{</span><span class=cF2>//Single step.</span><span class=cF0>
<a name="l543"></a> </span><span class=cF1>if</span><span class=cF0> (!task)
<a name="l544"></a> task = </span><span class=cF5>Fs</span><span class=cF0>;
<a name="l545"></a>
<a name="l546"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l547"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l548"></a> </span><span class=cF1>if</span><span class=cF0> (ip != </span><span class=cF3>INVALID_PTR</span><span class=cF0>)
<a name="l549"></a> task-&gt;rip = ip;
<a name="l550"></a> </span><span class=cF5>LBts</span><span class=cF0>(&amp;task-&gt;task_flags, </span><span class=cF3>TASKf_DISABLE_BPTS</span><span class=cF0>);
<a name="l551"></a> </span><span class=cF5>LBts</span><span class=cF0>(&amp;task-&gt;rflags, </span><span class=cF3>RFLAGf_TRAP</span><span class=cF0>);
<a name="l552"></a> </span><span class=cF5>Suspend</span><span class=cF0>(task, </span><span class=cF3>FALSE</span><span class=cF0>);
<a name="l553"></a> </span><span class=cF1>if</span><span class=cF0> (task == </span><span class=cF5>Fs</span><span class=cF0>)
<a name="l554"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l555"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>IsDebugMode</span><span class=cF0>)
<a name="l556"></a> {
<a name="l557"></a> </span><span class=cF1>if</span><span class=cF0> (task-&gt;next_cc != &amp;task-&gt;next_cc)
<a name="l558"></a> </span><span class=cF5>Btr</span><span class=cF0>(&amp;task-&gt;last_cc-&gt;flags, </span><span class=cF3>CCf_PROMPT</span><span class=cF0>);
<a name="l559"></a> }
<a name="l560"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l561"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l562"></a> </span><span class=cF5>Exit</span><span class=cF0>;
<a name="l563"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l564"></a>}
<a name="l565"></a>
<a name="l566"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>DebugHelp</span><span class=cF0>()
<a name="l567"></a>{
<a name="l568"></a> </span><span class=cF6>&quot;\n&quot;</span><span class=cF0>
<a name="l569"></a> </span><span class=cF6>&quot;The cmd line is basically the same as normal.</span><span class=cF0> </span><span class=cF6>Here are some common\n&quot;</span><span class=cF0>
<a name="l570"></a> </span><span class=cF6>&quot;debugging commands.\n\n&quot;</span><span class=cF0>
<a name="l571"></a> </span><span class=cF6>&quot;&gt;EdLite(\&quot;FileName\&quot;);\t\t//Edit file.\n&quot;</span><span class=cF0>
<a name="l572"></a> </span><span class=cF6>&quot;&gt;D(0x100000);\t\t\t//Dump page tables.\n&quot;</span><span class=cF0>
<a name="l573"></a> </span><span class=cF6>&quot;&gt;Dm(0x100000);\t\t\t//Dump page tables.\n&quot;</span><span class=cF0>
<a name="l574"></a> </span><span class=cF6>&quot;&gt;Dm(Fs,sizeof(CTask));\t\t//Dump current task record.\n&quot;</span><span class=cF0>
<a name="l575"></a> </span><span class=cF6>&quot;&gt;ClassRep(Fs,\&quot;CTask\&quot;,1);\t//Dump current task record.\n&quot;</span><span class=cF0>
<a name="l576"></a> </span><span class=cF6>&quot;&gt;ClassRep(Fs,,1);\t\t//(It knows lastclass.)\n&quot;</span><span class=cF0>
<a name="l577"></a> </span><span class=cF6>&quot;&gt;CallerRep;\t\t\t//Stack trace report.\n&quot;</span><span class=cF0>
<a name="l578"></a> </span><span class=cF6>&quot;&gt;Da(_RSP);\t\t\t//Dump stack.\n&quot;</span><span class=cF0>
<a name="l579"></a> </span><span class=cF6>&quot;&gt;Dr;\t\t\t\t//Dump Regs.\n&quot;</span><span class=cF0>
<a name="l580"></a> </span><span class=cF6>&quot;&gt;1+2*3+&amp;Print;\t\t\t//Show calculation res.\n&quot;</span><span class=cF0>
<a name="l581"></a> </span><span class=cF6>&quot;&gt;*(0x70000)(I64 *)=0x123456789;\t//Assign value to 0x70000-0x70007.\n&quot;</span><span class=cF0>
<a name="l582"></a> </span><span class=cF6>&quot;&gt;_RAX=0x1234;\t\t\t//Set RAX to 0x1234.\n&quot;</span><span class=cF0>
<a name="l583"></a> </span><span class=cF6>&quot;&gt;_RIP=&amp;Break;\t\t//Set RIP.\n&quot;</span><span class=cF0>
<a name="l584"></a> </span><span class=cF6>&quot;&gt;I64 i;\t\t\t\t//Declare variable.\n&quot;</span><span class=cF0>
<a name="l585"></a> </span><span class=cF6>&quot;&gt;i=_RCX+_RDX;\t\t\t//Assign to variable.\n&quot;</span><span class=cF0>
<a name="l586"></a> </span><span class=cF6>&quot;&gt;U(&amp;Print+0x8);\t\t\t//Unassemble Print.\n&quot;</span><span class=cF0>
<a name="l587"></a> </span><span class=cF6>&quot;&gt;Uf(\&quot;Print\&quot;);\t\t\t//Unassembler function \&quot;Print\&quot;.\n&quot;</span><span class=cF0>
<a name="l588"></a> </span><span class=cF6>&quot;&gt;Man(\&quot;Print\&quot;);\t\t\t//Edit Src for \&quot;Print\&quot;.\n&quot;</span><span class=cF0>
<a name="l589"></a> </span><span class=cF6>&quot;&gt;E(_RIP);\t\t\t//Edit Src Code.\n&quot;</span><span class=cF0>
<a name="l590"></a> </span><span class=cF6>&quot;&gt;Fix;\t\t\t\t//Edit Last Err Src Code.\n&quot;</span><span class=cF0>
<a name="l591"></a> </span><span class=cF6>&quot;&gt;B(&amp;Main+0x20);\t\t\t//Toggle break point.\n&quot;</span><span class=cF0>
<a name="l592"></a> </span><span class=cF6>&quot;&gt;B2;\t\t\t\t//Clear all break points.\n&quot;</span><span class=cF0>
<a name="l593"></a> </span><span class=cF6>&quot;&gt;S;\t\t\t\t//Single step.\n&quot;</span><span class=cF0>
<a name="l594"></a> </span><span class=cF6>&quot;&gt;G;\t\t\t\t//Resume execution.\n&quot;</span><span class=cF0>
<a name="l595"></a> </span><span class=cF6>&quot;&gt;G2;\t\t\t\t//B2;LFBFlush;WinFocus;G;\n&quot;</span><span class=cF0>
<a name="l596"></a> </span><span class=cF6>&quot;&gt;Exit;\t\t\t\t//Exit (kill) task.\n\n&quot;</span><span class=cF0>
<a name="l597"></a> </span><span class=cF6>&quot;After resuming, &lt;CTRL-ALT-n&gt; next focus task.\n&quot;</span><span class=cF0>
<a name="l598"></a> </span><span class=cF6>&quot;After resuming, &lt;CTRL-ALT-v&gt; flushes screen VGA cache.\n\n&quot;</span><span class=cF0>;
<a name="l599"></a>}
<a name="l600"></a>
<a name="l601"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>Debug2</span><span class=cF0>()
<a name="l602"></a>{
<a name="l603"></a> </span><span class=cF1>Bool</span><span class=cF0> old_win_inhibit, old_waiting_message, old_single;
<a name="l604"></a> </span><span class=cF9>I64</span><span class=cF0> i, old_getstr2;
<a name="l605"></a> </span><span class=cF1>U8</span><span class=cF0> buf[</span><span class=cFE>200</span><span class=cF0>];
<a name="l606"></a>
<a name="l607"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>debug</span><span class=cF0>.panic)
<a name="l608"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l609"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>IsRaw</span><span class=cF0>)
<a name="l610"></a> {
<a name="l611"></a> i = </span><span class=cF5>Fs</span><span class=cF0>-&gt;rip;
<a name="l612"></a> </span><span class=cF5>Ui</span><span class=cF0>(buf, &amp;i);
<a name="l613"></a> </span><span class=cF6>&quot;%s&quot;</span><span class=cF0>, buf;
<a name="l614"></a> }
<a name="l615"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l616"></a> </span><span class=cF5>U</span><span class=cF0>(</span><span class=cF5>Fs</span><span class=cF0>-&gt;rip, </span><span class=cFE>1</span><span class=cF0>);
<a name="l617"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l618"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l619"></a> </span><span class=cFB>debug</span><span class=cF0>.panic = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l620"></a> old_waiting_message = </span><span class=cF5>LBtr</span><span class=cF0>(&amp;</span><span class=cF5>Fs</span><span class=cF0>-&gt;task_flags, </span><span class=cF3>TASKf_AWAITING_MESSAGE</span><span class=cF0>);
<a name="l621"></a> old_win_inhibit = </span><span class=cF5>Fs</span><span class=cF0>-&gt;win_inhibit;
<a name="l622"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;win_inhibit = </span><span class=cF3>WIG_USER_TASK_DEFAULT</span><span class=cF0>;
<a name="l623"></a> </span><span class=cFB>sys_focus_task</span><span class=cF0> = </span><span class=cF5>Fs</span><span class=cF0>;
<a name="l624"></a> </span><span class=cFB>kbd</span><span class=cF0>.scan_code = </span><span class=cFE>0</span><span class=cF0>;
<a name="l625"></a> old_getstr2 = </span><span class=cFB>fp_getstr2</span><span class=cF0>;
<a name="l626"></a> </span><span class=cFB>fp_getstr2</span><span class=cF0> = &amp;</span><span class=cFD>SysGetStr2</span><span class=cF0>;
<a name="l627"></a> old_single = </span><span class=cF5>SingleUser</span><span class=cF0>(</span><span class=cF3>OFF</span><span class=cF0>);
<a name="l628"></a> </span><span class=cF1>while</span><span class=cF0> (!</span><span class=cFB>mouse_hard</span><span class=cF0>.install_attempts)
<a name="l629"></a> </span><span class=cF5>Yield</span><span class=cF0>;
<a name="l630"></a> </span><span class=cF5>SingleUser</span><span class=cF0>(old_single);
<a name="l631"></a> </span><span class=cF5>UserTaskCont</span><span class=cF0>;
<a name="l632"></a> </span><span class=cFB>fp_getstr2</span><span class=cF0> = old_getstr2;
<a name="l633"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;win_inhibit = old_win_inhibit;
<a name="l634"></a> </span><span class=cF5>LBEqual</span><span class=cF0>(&amp;</span><span class=cF5>Fs</span><span class=cF0>-&gt;task_flags, </span><span class=cF3>TASKf_AWAITING_MESSAGE</span><span class=cF0>, old_waiting_message);
<a name="l635"></a>}
<a name="l636"></a>
<a name="l637"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>Fault3</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> fault_num, </span><span class=cF9>I64</span><span class=cF0> fault_err_code)
<a name="l638"></a>{
<a name="l639"></a> </span><span class=cF1>no_warn</span><span class=cF0> fault_err_code;
<a name="l640"></a>
<a name="l641"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l642"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l643"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Gs</span><span class=cF0>-&gt;num &amp;&amp; </span><span class=cFB>debug</span><span class=cF0>.mp_crash)
<a name="l644"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l645"></a> </span><span class=cFB>mp_count</span><span class=cF0> = </span><span class=cFE>1</span><span class=cF0>;
<a name="l646"></a> </span><span class=cFB>debug</span><span class=cF0>.mp_crash-&gt;cpu_num = </span><span class=cF5>Gs</span><span class=cF0>-&gt;num;
<a name="l647"></a> </span><span class=cFB>debug</span><span class=cF0>.mp_crash-&gt;task = </span><span class=cF5>Fs</span><span class=cF0>;
<a name="l648"></a> </span><span class=cFB>debug</span><span class=cF0>.mp_crash-&gt;rip = </span><span class=cF5>Fs</span><span class=cF0>-&gt;rip;
<a name="l649"></a> </span><span class=cFB>debug</span><span class=cF0>.mp_crash-&gt;message = </span><span class=cFB>debug</span><span class=cF0>.message;
<a name="l650"></a> </span><span class=cFB>debug</span><span class=cF0>.mp_crash-&gt;message_num = </span><span class=cFB>debug</span><span class=cF0>.message_num;
<a name="l651"></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="l652"></a> </span><span class=cF5>SysHlt</span><span class=cF0>;
<a name="l653"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l654"></a>
<a name="l655"></a> </span><span class=cF6>&quot;\n\tZealOS Debugger\n\n&quot;</span><span class=cF0>
<a name="l656"></a> </span><span class=cF6>&quot;&gt;Help;\t//For help.\n\n&quot;</span><span class=cF0>;
<a name="l657"></a>
<a name="l658"></a> </span><span class=cF5>Beep</span><span class=cF0>(</span><span class=cFE>62</span><span class=cF0>, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l659"></a> </span><span class=cF1>if</span><span class=cF0> (fault_num == </span><span class=cF3>I_DEBUG</span><span class=cF0>)
<a name="l660"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l661"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>debug</span><span class=cF0>.message)
<a name="l662"></a> {
<a name="l663"></a> </span><span class=cF6>&quot;\n!!! %s&quot;</span><span class=cF0>, </span><span class=cFB>debug</span><span class=cF0>.message;
<a name="l664"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>debug</span><span class=cF0>.message_num)
<a name="l665"></a> </span><span class=cF6>&quot;%016X&quot;</span><span class=cF0>, </span><span class=cFB>debug</span><span class=cF0>.message_num;
<a name="l666"></a> </span><span class=cF6>&quot; !!!\n\n&quot;</span><span class=cF0>;
<a name="l667"></a> }
<a name="l668"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l669"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>debug</span><span class=cF0>.panic)
<a name="l670"></a> </span><span class=cF5>CallerRep</span><span class=cF0>;
<a name="l671"></a> </span><span class=cFD>Debug2</span><span class=cF0>;
<a name="l672"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l673"></a>}
<a name="l674"></a>
<a name="l675"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>Fault2</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> fault_num, </span><span class=cF9>I64</span><span class=cF0> fault_err_code)
<a name="l676"></a>{</span><span class=cF2>//Called from </span><a href="https://tomawezome.github.io/ZealOS/Kernel/KInterrupts.html#l91"><span class=cF4>Fault2</span></a><span class=cF2>.</span><span class=cF0>
<a name="l677"></a></span><span class=cF2>//Be careful not to swap-out and ruin the saved context</span><span class=cF0>
<a name="l678"></a> </span><span class=cF1>Bool</span><span class=cF0> was_raw, was_single_user, was_silent, was_in_debug, was_mouse_enabled;
<a name="l679"></a> </span><span class=cF9>I64</span><span class=cF0> i, old_raw_flags = </span><span class=cFB>text</span><span class=cF0>.raw_flags;
<a name="l680"></a>
<a name="l681"></a> was_single_user = </span><span class=cF5>SingleUser</span><span class=cF0>(</span><span class=cF3>ON</span><span class=cF0>);
<a name="l682"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>IsDebugMode</span><span class=cF0>)
<a name="l683"></a> </span><span class=cFB>debug</span><span class=cF0>.focus_task = </span><span class=cFB>sys_focus_task</span><span class=cF0>;
<a name="l684"></a> </span><span class=cFB>sys_focus_task</span><span class=cF0> = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l685"></a> </span><span class=cF1>if</span><span class=cF0> (fault_num == </span><span class=cF3>I_BPT</span><span class=cF0>)
<a name="l686"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;rip--;
<a name="l687"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Fs</span><span class=cF0>-&gt;debug_task)
<a name="l688"></a> </span><span class=cF5>CallExtNum</span><span class=cF0>(</span><span class=cF3>EXT_DEBUG_RESUME</span><span class=cF0>, fault_num, fault_err_code);
<a name="l689"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l690"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l691"></a> was_mouse_enabled = </span><span class=cF5>CallExtStr</span><span class=cF0>(</span><span class=cF6>&quot;MouseHardEnable&quot;</span><span class=cF0>, </span><span class=cF3>FALSE</span><span class=cF0>);
<a name="l692"></a> was_raw = </span><span class=cF5>Raw</span><span class=cF0>(</span><span class=cF3>ON</span><span class=cF0>);
<a name="l693"></a> was_silent = </span><span class=cF5>Silent</span><span class=cF0>(</span><span class=cF3>OFF</span><span class=cF0>);
<a name="l694"></a> </span><span class=cFB>text</span><span class=cF0>.raw_flags |= </span><span class=cF3>RAWF_SHOW_DOLLAR</span><span class=cF0>|</span><span class=cF3>RAWF_SCROLL</span><span class=cF0>;
<a name="l695"></a>
<a name="l696"></a> </span><span class=cF6>&quot;Task \&quot;&quot;</span><span class=cF0>;
<a name="l697"></a> </span><span class=cF6>&quot;%s&quot;</span><span class=cF0>, </span><span class=cF5>Fs</span><span class=cF0>-&gt;task_title;
<a name="l698"></a> </span><span class=cF6>&quot;\&quot;\n&quot;</span><span class=cF0>;
<a name="l699"></a> </span><span class=cF6>&quot;Fault:0x%02X %Z\t\tErr Code:%08X\n&quot;</span><span class=cF0>, fault_num, fault_num, </span><span class=cF6>&quot;ST_INT_NAMES&quot;</span><span class=cF0>, fault_err_code;
<a name="l700"></a> was_in_debug = </span><span class=cF5>DebugMode</span><span class=cF0>(</span><span class=cF3>ON</span><span class=cF0>);
<a name="l701"></a> </span><span class=cF6>&quot;RIP:%08X&quot;</span><span class=cF0>, </span><span class=cF5>Fs</span><span class=cF0>-&gt;rip; </span><span class=cF2>//Sometimes crashes on %p, so do this first</span><span class=cF0>
<a name="l702"></a> </span><span class=cF6>&quot;:%p RSP:%08X\n&quot;</span><span class=cF0>, </span><span class=cF5>Fs</span><span class=cF0>-&gt;rip, </span><span class=cF5>Fs</span><span class=cF0>-&gt;rsp;
<a name="l703"></a> </span><span class=cF1>if</span><span class=cF0> (fault_num == </span><span class=cF3>I_PAGE_FAULT</span><span class=cF0>)
<a name="l704"></a> {
<a name="l705"></a> </span><span class=cF1>MOV_RAX_CR2</span><span class=cF0>
<a name="l706"></a> i = </span><span class=cF5>RAXGet</span><span class=cF0>;
<a name="l707"></a> </span><span class=cF6>&quot;Fault Addr:%08X:%p\n&quot;</span><span class=cF0>, i, i;
<a name="l708"></a> }
<a name="l709"></a> </span><span class=cFD>Fault3</span><span class=cF0>(fault_num, fault_err_code);
<a name="l710"></a> </span><span class=cF5>DebugMode</span><span class=cF0>(was_in_debug);
<a name="l711"></a> </span><span class=cF5>Silent</span><span class=cF0>(was_silent);
<a name="l712"></a> </span><span class=cF5>Raw</span><span class=cF0>(was_raw);
<a name="l713"></a> </span><span class=cF5>CallExtStr</span><span class=cF0>(</span><span class=cF6>&quot;MouseHardEnable&quot;</span><span class=cF0>, was_mouse_enabled);
<a name="l714"></a> </span><span class=cFB>text</span><span class=cF0>.raw_flags = old_raw_flags;
<a name="l715"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l716"></a> </span><span class=cF5>SingleUser</span><span class=cF0>(was_single_user);
<a name="l717"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>LBtr</span><span class=cF7>(</span><span class=cF0>&amp;</span><span class=cF5>Fs</span><span class=cF0>-&gt;task_flags, </span><span class=cF3>TASKf_KILL_AFTER_DEBUG</span><span class=cF7>)</span><span class=cF0>)
<a name="l718"></a> </span><span class=cF5>Exit</span><span class=cF0>;
<a name="l719"></a>}
<a name="l720"></a>
<a name="l721"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>Panic</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *message=</span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF9>I64</span><span class=cF0> message_num=</span><span class=cFE>0</span><span class=cF0>, </span><span class=cF1>Bool</span><span class=cF0> panic=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l722"></a>{</span><span class=cF2>//Enter the debugger with panic?</span><span class=cF0>
<a name="l723"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l724"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l725"></a> </span><span class=cFB>debug</span><span class=cF0>.message = message;
<a name="l726"></a> </span><span class=cFB>debug</span><span class=cF0>.message_num = message_num;
<a name="l727"></a> </span><span class=cFB>debug</span><span class=cF0>.panic = panic;
<a name="l728"></a> </span><span class=cF1>INT</span><span class=cF0> </span><span class=cF3>I_DEBUG</span><span class=cF0>
<a name="l729"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l730"></a>}
<a name="l731"></a>
<a name="l732"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>Debug</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *message=</span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF9>I64</span><span class=cF0> message_num=</span><span class=cFE>0</span><span class=cF0>)
<a name="l733"></a>{</span><span class=cF2>//Enter debugger, no panic.</span><span class=cF0>
<a name="l734"></a> </span><span class=cF5>Panic</span><span class=cF0>(message, message_num, </span><span class=cF3>FALSE</span><span class=cF0>);
<a name="l735"></a>}
</span></pre></body>
</html>