templeos-info/public/Wb/Kernel/Mem/BlkPool.HC.HTML

105 lines
9.1 KiB
Plaintext
Raw Normal View History

2024-03-24 21:24:44 +00:00
<!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>U0</span><span class=cF0> </span><span class=cF5>BlkPoolAdd</span><span class=cF0>(</span><span class=cF9>CBlkPool</span><span class=cF0> *bp,</span><span class=cF9>CMemBlk</span><span class=cF0> *m,</span><span class=cF9>I64</span><span class=cF0> pags)
<a name="l2"></a>{</span><span class=cF2>//Add mem to BlkPool.</span><span class=cF0>
<a name="l3"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>sys_mem_init_flag</span><span class=cF0>)
<a name="l4"></a> </span><span class=cF5>MemSet</span><span class=cF0>(m,</span><span class=cFB>sys_mem_init_val</span><span class=cF0>,pags*</span><span class=cF3>MEM_PAG_SIZE</span><span class=cF0>);
<a name="l5"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l6"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l7"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&amp;bp-&gt;locked_flags,</span><span class=cF3>BPlf_LOCKED</span><span class=cF7>)</span><span class=cF0>)
<a name="l8"></a> </span><span class=cF1>PAUSE</span><span class=cF0>
<a name="l9"></a> m-&gt;next=bp-&gt;mem_free_lst;
<a name="l10"></a> m-&gt;pags=pags;
<a name="l11"></a> m-&gt;mb_signature=</span><span class=cF3>MBS_UNUSED_SIGNATURE_VAL</span><span class=cF0>;
<a name="l12"></a> bp-&gt;alloced_u8s+=pags&lt;&lt;</span><span class=cF3>MEM_PAG_BITS</span><span class=cF0>;
<a name="l13"></a> bp-&gt;mem_free_lst=m;
<a name="l14"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;bp-&gt;locked_flags,</span><span class=cF3>BPlf_LOCKED</span><span class=cF0>);
<a name="l15"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l16"></a>}
<a name="l17"></a>
<a name="l18"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>BlkPoolInit</span><span class=cF0>(</span><span class=cF9>CBlkPool</span><span class=cF0> *bp,</span><span class=cF9>I64</span><span class=cF0> pags)
<a name="l19"></a>{</span><span class=cF2>//Make mem chunk into a BlkPool.</span><span class=cF0>
<a name="l20"></a> </span><span class=cF9>I64</span><span class=cF0> num;
<a name="l21"></a> </span><span class=cF9>CMemBlk</span><span class=cF0> *m;
<a name="l22"></a> </span><span class=cF5>MemSet</span><span class=cF0>(bp,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CBlkPool</span><span class=cF7>)</span><span class=cF0>);
<a name="l23"></a> m=(bp</span><span class=cF7>(</span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>+</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CBlkPool</span><span class=cF7>)</span><span class=cF0>+</span><span class=cF3>MEM_PAG_SIZE</span><span class=cF0>-1)&amp;~(</span><span class=cF3>MEM_PAG_SIZE</span><span class=cF0>-1);
<a name="l24"></a> num=(bp</span><span class=cF7>(</span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>+pags&lt;&lt;</span><span class=cF3>MEM_PAG_BITS</span><span class=cF0>-m</span><span class=cF7>(</span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>)&gt;&gt;</span><span class=cF3>MEM_PAG_BITS</span><span class=cF0>;
<a name="l25"></a> bp-&gt;alloced_u8s=(pags-num)&lt;&lt;</span><span class=cF3>MEM_PAG_BITS</span><span class=cF0>; </span><span class=cF2>//Compensate before num added.</span><span class=cF0>
<a name="l26"></a> </span><span class=cF5>BlkPoolAdd</span><span class=cF0>(bp,m,num);
<a name="l27"></a>}
<a name="l28"></a>
<a name="l29"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>BlkPoolsInit</span><span class=cF0>()
<a name="l30"></a>{
<a name="l31"></a> </span><span class=cF9>I64</span><span class=cF0> i,total,lo,hi,code_heap_limit;
<a name="l32"></a> </span><span class=cF9>CMemE820</span><span class=cF0> *m20=</span><span class=cFD>MEM_E820</span><span class=cF0>;
<a name="l33"></a> </span><span class=cF1>Bool</span><span class=cF0> first=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l34"></a>
<a name="l35"></a> total=</span><span class=cFD>BIOSTotalMem</span><span class=cF0>;
<a name="l36"></a>
<a name="l37"></a> </span><span class=cF1>if</span><span class=cF0> (total&lt;=0x80000000)
<a name="l38"></a> code_heap_limit=total;
<a name="l39"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (total&lt;=0x100000000)
<a name="l40"></a> code_heap_limit=total/4;
<a name="l41"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l42"></a> code_heap_limit=0x80000000;
<a name="l43"></a>
<a name="l44"></a> i=code_heap_limit-</span><span class=cF3>SYS_16MEG_AREA_LIMIT</span><span class=cF0>; </span><span class=cF2>//See </span><a href="/Wb/Kernel/Mem/PageTables.HC.HTML#l195"><span class=cF4>RLf_16MEG_SYS_CODE_BP</span></a><span class=cF0>
<a name="l45"></a> </span><span class=cF5>BlkPoolAdd</span><span class=cF0>(</span><span class=cFB>sys_code_bp</span><span class=cF0>,</span><span class=cF3>SYS_16MEG_AREA_LIMIT</span><span class=cF0>,i&gt;&gt;</span><span class=cF3>MEM_PAG_BITS</span><span class=cF0>);
<a name="l46"></a> </span><span class=cFB>mem_heap_limit</span><span class=cF0>=i+</span><span class=cF3>SYS_16MEG_AREA_LIMIT</span><span class=cF0>-1;
<a name="l47"></a>
<a name="l48"></a> </span><span class=cF1>if</span><span class=cF0> (code_heap_limit&lt;total) </span><span class=cF7>{</span><span class=cF0>
<a name="l49"></a> </span><span class=cF1>while</span><span class=cF0> (m20-&gt;type) {
<a name="l50"></a> </span><span class=cF1>if</span><span class=cF0> (m20-&gt;type==1) </span><span class=cF7>{</span><span class=cF0>
<a name="l51"></a> lo=m20-&gt;base;
<a name="l52"></a> hi=m20-&gt;base+m20-&gt;len;
<a name="l53"></a> </span><span class=cF1>if</span><span class=cF0> (lo&lt;code_heap_limit) {
<a name="l54"></a> </span><span class=cF1>if</span><span class=cF0> (hi&gt;code_heap_limit)
<a name="l55"></a> lo=code_heap_limit;
<a name="l56"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l57"></a> hi=lo; </span><span class=cF2>//cancel</span><span class=cF0>
<a name="l58"></a> }
<a name="l59"></a> </span><span class=cF1>if</span><span class=cF0> (code_heap_limit&lt;=lo&lt;hi) {
<a name="l60"></a> </span><span class=cF1>if</span><span class=cF0> (first) </span><span class=cF7>{</span><span class=cF0>
<a name="l61"></a> </span><span class=cF5>BlkPoolInit</span><span class=cF0>(lo,</span><span class=cF7>(</span><span class=cF0>hi-lo</span><span class=cF7>)</span><span class=cF0>&gt;&gt;</span><span class=cF3>MEM_PAG_BITS</span><span class=cF0>);
<a name="l62"></a> </span><span class=cFB>sys_data_bp</span><span class=cF0>=lo;
<a name="l63"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;data_heap=</span><span class=cF5>HeapCtrlInit</span><span class=cF0>(,</span><span class=cF5>Fs</span><span class=cF0>,</span><span class=cFB>sys_data_bp</span><span class=cF0>);
<a name="l64"></a> first=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l65"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l66"></a> </span><span class=cF5>BlkPoolAdd</span><span class=cF0>(</span><span class=cFB>sys_data_bp</span><span class=cF0>,lo,</span><span class=cF7>(</span><span class=cF0>hi-lo</span><span class=cF7>)</span><span class=cF0>&gt;&gt;</span><span class=cF3>MEM_PAG_BITS</span><span class=cF0>);
<a name="l67"></a> }
<a name="l68"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l69"></a> m20++;
<a name="l70"></a> }
<a name="l71"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l72"></a> </span><span class=cF5>LBts</span><span class=cF0>(&amp;</span><span class=cFB>sys_run_level</span><span class=cF0>,</span><span class=cF3>RLf_FULL_HEAPS</span><span class=cF0>);
<a name="l73"></a>}
</span></pre></body>
</html>