2020-09-15 02:55:57 +01:00
|
|
|
U0 BlkPoolAdd(CBlkPool *bp, CMemBlk *m, I64 pags)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Add mem to BlkPool.
|
2020-02-20 23:40:10 +00:00
|
|
|
if (sys_mem_init_flag)
|
2020-09-15 02:55:57 +01:00
|
|
|
MemSet(m, sys_mem_init_val, pags * MEM_PAG_SIZE);
|
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
PUSHFD
|
|
|
|
CLI
|
2020-09-15 02:55:57 +01:00
|
|
|
while (LBts(&bp->locked_flags, BPlf_LOCKED))
|
2020-02-20 23:40:10 +00:00
|
|
|
PAUSE
|
2020-09-15 02:55:57 +01:00
|
|
|
m->next = bp->mem_free_list;
|
|
|
|
m->pags = pags;
|
|
|
|
m->mb_signature = MBS_UNUSED_SIGNATURE_VAL;
|
|
|
|
bp->alloced_u8s += pags << MEM_PAG_BITS;
|
|
|
|
bp->mem_free_list = m;
|
|
|
|
LBtr(&bp->locked_flags, BPlf_LOCKED);
|
2020-02-20 23:40:10 +00:00
|
|
|
POPFD
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-09-15 02:55:57 +01:00
|
|
|
U0 BlkPoolInit(CBlkPool *bp, I64 pags)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Make mem chunk into a BlkPool.
|
2020-09-15 02:55:57 +01:00
|
|
|
I64 num;
|
|
|
|
CMemBlk *m;
|
|
|
|
|
|
|
|
MemSet(bp, 0, sizeof(CBlkPool));
|
|
|
|
m = (bp(U8 *) + sizeof(CBlkPool) + MEM_PAG_SIZE - 1) & ~(MEM_PAG_SIZE - 1);
|
|
|
|
num = (bp(U8 *) + pags << MEM_PAG_BITS - m(U8 *)) >> MEM_PAG_BITS;
|
|
|
|
bp->alloced_u8s = (pags-num) << MEM_PAG_BITS; //Compensate before num added.
|
|
|
|
BlkPoolAdd(bp, m, num);
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U0 BlkPoolsInit()
|
|
|
|
{
|
2020-09-15 02:55:57 +01:00
|
|
|
I64 i, total, lo, hi, code_heap_limit;
|
|
|
|
CMemE820 *m20 = MEM_E820;
|
|
|
|
Bool first = TRUE;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
2020-09-15 02:55:57 +01:00
|
|
|
total = MemBIOSTotal;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
2020-09-15 02:55:57 +01:00
|
|
|
if (total <= 0x80000000)
|
|
|
|
code_heap_limit = total;
|
|
|
|
else if (total <= 0x100000000)
|
|
|
|
code_heap_limit = total / 4;
|
2020-02-20 23:40:10 +00:00
|
|
|
else
|
2020-09-15 02:55:57 +01:00
|
|
|
code_heap_limit = 0x80000000;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
2021-12-11 11:21:22 +00:00
|
|
|
i = code_heap_limit - SYS_16MEG_AREA_LIMIT; //See $LK,"RLf_16MEG_SYS_CODE_BP",A="FF:::/Kernel/Memory/PageTables.ZC,RLf_16MEG_SYS_CODE_BP"$
|
2020-09-15 02:55:57 +01:00
|
|
|
BlkPoolAdd(sys_code_bp, SYS_16MEG_AREA_LIMIT, i >> MEM_PAG_BITS);
|
|
|
|
mem_heap_limit = i + SYS_16MEG_AREA_LIMIT - 1;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
2020-09-15 02:55:57 +01:00
|
|
|
if (code_heap_limit<total)
|
|
|
|
{
|
|
|
|
while (m20->type)
|
|
|
|
{
|
|
|
|
if (m20->type == MEM_E820t_USABLE)
|
|
|
|
{
|
|
|
|
lo = m20->base;
|
|
|
|
hi = m20->base + m20->len;
|
|
|
|
if (lo<code_heap_limit)
|
|
|
|
{
|
|
|
|
if (hi > code_heap_limit)
|
|
|
|
lo = code_heap_limit;
|
2020-02-20 23:40:10 +00:00
|
|
|
else
|
2020-09-15 02:55:57 +01:00
|
|
|
hi = lo; //cancel
|
2020-02-20 23:40:10 +00:00
|
|
|
}
|
2020-09-15 02:55:57 +01:00
|
|
|
if (code_heap_limit <= lo < hi)
|
|
|
|
{
|
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
BlkPoolInit(lo, (hi - lo) >> MEM_PAG_BITS);
|
|
|
|
sys_data_bp = lo;
|
|
|
|
Fs->data_heap = HeapCtrlInit(, Fs, sys_data_bp);
|
|
|
|
first = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
BlkPoolAdd(sys_data_bp, lo, (hi - lo) >> MEM_PAG_BITS);
|
2020-02-20 23:40:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
m20++;
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
2020-09-15 02:55:57 +01:00
|
|
|
LBts(&sys_run_level, RLf_FULL_HEAPS);
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|