TempleOSCDV4.01.ISO

This commit is contained in:
Terry A. Davis authored and minexew committed 2018-09-08 21:46:47 +02:00
1 parent 0e0592d9a6
commit fedf66361e
85 files changed
+2463 -2376

No files matched your search

+7 -7
View File
@@ -9,7 +9,7 @@ U0 BlkPoolAdd(CBlkPool *bp,CMemBlk *m,I64 pages512)
m->next=bp->mem_free_lst;
m->pages=pages512;
m->mb_signature=MBS_UNUSED_SIGNATURE_VAL;
bp->alloced_u8s+=pages512<<PAGE_BITS;
bp->alloced_u8s+=pages512<<MEM_PAGE_BITS;
bp->mem_free_lst=m;
LBtr(&bp->locked_flags,BPlf_LOCKED);
POPFD
@@ -20,9 +20,9 @@ U0 BlkPoolInit(CBlkPool *bp,I64 pages512)
I64 num;
CMemBlk *m;
MemSet(bp,0,sizeof(CBlkPool));
m=(bp(U8 *)+sizeof(CBlkPool)+PAGE_SIZE-1)&~(PAGE_SIZE-1);
num=(bp(U8 *)+pages512<<PAGE_BITS-m(U8 *))>>PAGE_BITS;
bp->alloced_u8s=(pages512-num)<<PAGE_BITS; //Compensate before num added.
m=(bp(U8 *)+sizeof(CBlkPool)+MEM_PAGE_SIZE-1)&~(MEM_PAGE_SIZE-1);
num=(bp(U8 *)+pages512<<MEM_PAGE_BITS-m(U8 *))>>MEM_PAGE_BITS;
bp->alloced_u8s=(pages512-num)<<MEM_PAGE_BITS; //Compensate before num added.
BlkPoolAdd(bp,m,num);
}
@@ -42,7 +42,7 @@ U0 BlkPoolsInit()
code_heap_limit=0x80000000;
i=code_heap_limit-0x1000000;
BlkPoolAdd(sys_code_bp,0x1000000,i>>PAGE_BITS);
BlkPoolAdd(sys_code_bp,0x1000000,i>>MEM_PAGE_BITS);
sys_heap_limit=i+0x1000000-1;
if (code_heap_limit<total) {
@@ -58,12 +58,12 @@ U0 BlkPoolsInit()
}
if (code_heap_limit<=lo<hi) {
if (first) {
BlkPoolInit(lo,(hi-lo)>>PAGE_BITS);
BlkPoolInit(lo,(hi-lo)>>MEM_PAGE_BITS);
sys_data_bp=lo;
Fs->data_heap=HeapCtrlInit(,Fs,sys_data_bp);
first=FALSE;
} else
BlkPoolAdd(sys_data_bp,lo,(hi-lo)>>PAGE_BITS);
BlkPoolAdd(sys_data_bp,lo,(hi-lo)>>MEM_PAGE_BITS);
}
}
m20++;
+4 -3
View File
@@ -17,9 +17,10 @@ CHeapCtrl *HeapCtrlBPInit(CBlkPool *bp,I64 pages512)
CHeapCtrl *hc;
MemSet(bp,0,sizeof(CBlkPool)+sizeof(CHeapCtrl));
hc=HeapCtrlInit(bp(U8 *)+sizeof(CBlkPool),,bp);
m=(bp(U8 *)+sizeof(CBlkPool)+sizeof(CHeapCtrl)+PAGE_SIZE-1)&~(PAGE_SIZE-1);
num=(bp(U8 *)+pages512<<PAGE_BITS-m(U8 *))>>PAGE_BITS;
bp->alloced_u8s=(pages512-num)<<PAGE_BITS;
m=(bp(U8 *)+sizeof(CBlkPool)+sizeof(CHeapCtrl)+MEM_PAGE_SIZE-1)&
~(MEM_PAGE_SIZE-1);
num=(bp(U8 *)+pages512<<MEM_PAGE_BITS-m(U8 *))>>MEM_PAGE_BITS;
bp->alloced_u8s=(pages512-num)<<MEM_PAGE_BITS;
BlkPoolAdd(bp,m,num);
return hc;
}
+8 -8
View File
@@ -41,7 +41,7 @@ _MALLOC::
PAUSE //don't know if this instruction helps
JC @@25
CMP RAX,HEAP_HASH_SIZE
CMP RAX,MEM_HEAP_HASH_SIZE
JAE @@30
MOV RSI,U64 CHeapCtrl.heap_hash[RAX+RDX]
TEST RSI,RSI
@@ -51,8 +51,8 @@ _MALLOC::
JMP I32 MALLOC_ALMOST_DONE
//Big allocation
@@30: ADD RAX,sizeof(CMemBlk)+PAGE_SIZE-1
SHR RAX,PAGE_BITS
@@30: ADD RAX,sizeof(CMemBlk)+MEM_PAGE_SIZE-1
SHR RAX,MEM_PAGE_BITS
PUSH RDX //preserve HeapCtrl
PUSH RAX //num blks (we must pass address of this)
@@ -66,7 +66,7 @@ _MALLOC::
TEST RSI,RSI
JZ @@45 //Out of memory
SHL RAX,PAGE_BITS
SHL RAX,MEM_PAGE_BITS
SUB RAX,sizeof(CMemBlk)
ADD RSI,sizeof(CMemBlk)
JMP I32 MALLOC_ALMOST_DONE
@@ -79,8 +79,8 @@ _MALLOC::
TEST RSI,RSI
JNZ @@55
PUSH RAX //-**** save byte size
ADD RAX,16*PAGE_SIZE-1
SHR RAX,PAGE_BITS
ADD RAX,16*MEM_PAGE_SIZE-1
SHR RAX,MEM_PAGE_BITS
PUSH RDX //preserve HeapCtrl
PUSH RAX //num blks (we must pass address of this)
@@ -105,7 +105,7 @@ _MALLOC::
JMP I32 MALLOC_FINAL_EXIT //Never gets here, hopefully.
@@50: LEA RSI,U64 sizeof(CMemBlk)[RSI]
SHL RAX,PAGE_BITS
SHL RAX,MEM_PAGE_BITS
SUB RAX,sizeof(CMemBlk)
LEA RBX,U64 CHeapCtrl.malloc_free_lst-CMemUnused.next[RDX]
MOV RDI,U64 CMemUnused.next[RBX]
@@ -292,7 +292,7 @@ _FREE::
MOV RDX,U64 CMemUsed.hc[RSI]
#endif
CMP RAX,HEAP_HASH_SIZE
CMP RAX,MEM_HEAP_HASH_SIZE
JAE @@50
#assert CMemUnused.size==CMemUsed.size
+11 -11
View File
@@ -14,7 +14,7 @@ Return: NULL if out of memory.
CLI
while (LBts(&bp->locked_flags,BPlf_LOCKED))
PAUSE
num<<=21-PAGE_BITS;
num<<=21-MEM_PAGE_BITS;
m=&bp->mem_free_2meg_lst;
while (TRUE) {
@@ -28,7 +28,7 @@ Return: NULL if out of memory.
goto am_done;
} else {
result->pages-=num;
result(U8 *)+=result->pages<<PAGE_BITS;
result(U8 *)+=result->pages<<MEM_PAGE_BITS;
result->pages=num;
goto am_done;
}
@@ -53,20 +53,20 @@ Return: NULL if out of memory.
goto am_done;
}
} else {
if (i=(result(U8 *)&0x1FFFFF)>>PAGE_BITS) {
j=1<<(21-PAGE_BITS)-i;
if (i=(result(U8 *)&0x1FFFFF)>>MEM_PAGE_BITS) {
j=1<<(21-MEM_PAGE_BITS)-i;
if (result->pages<num+j)
m=result;
else if (result->pages==num+j) {
result->pages-=num;
result(U8 *)+=result->pages<<PAGE_BITS;
result(U8 *)+=result->pages<<MEM_PAGE_BITS;
result->pages=num;
goto am_done;
} else {
m1=result;
result(U8 *)+=j<<PAGE_BITS;
result(U8 *)+=j<<MEM_PAGE_BITS;
result->pages=num;
m=result(U8 *)+num<<PAGE_BITS;
m=result(U8 *)+num<<MEM_PAGE_BITS;
m->pages=m1->pages-num-j;
m1->pages=j;
m->next=m1->next;
@@ -75,7 +75,7 @@ Return: NULL if out of memory.
goto am_done;
}
} else {
m=m->next=result(U8 *)+num<<PAGE_BITS;
m=m->next=result(U8 *)+num<<MEM_PAGE_BITS;
m->next=result->next;
m->pages=result->pages-num;
m->mb_signature=MBS_UNUSED_SIGNATURE_VAL;
@@ -86,9 +86,9 @@ Return: NULL if out of memory.
}
}
am_done:
i=num<<PAGE_BITS;
i=num<<MEM_PAGE_BITS;
bp->used_u8s+=i;
num>>=21-PAGE_BITS;
num>>=21-MEM_PAGE_BITS;
*_pages2Meg=num;
m=result;
m1=m(U8 *)+i;
@@ -170,7 +170,7 @@ U0 Mem2MegFree(CMemBlk *m,I64 pages2Meg,CBlkPool *bp=NULL)
while (LBts(&bp->locked_flags,BPlf_LOCKED))
PAUSE
m->mb_signature=MBS_UNUSED_SIGNATURE_VAL;
m->pages=pages2Meg<<(21-PAGE_BITS);
m->pages=pages2Meg<<(21-MEM_PAGE_BITS);
bp->used_u8s-=pages2Meg<<21;
m->next=bp->mem_free_2meg_lst;
bp->mem_free_2meg_lst=m;
+16 -16
View File
@@ -23,21 +23,21 @@ Return: NULL if out of memory.
CLI
while (LBts(&bp->locked_flags,BPlf_LOCKED))
PAUSE
if (num<FREE_PAGE_HASH_SIZE) {
if (num<MEM_FREE_PAGE_HASH_SIZE) {
if (result=bp->free_page_hash[num]) {
bp->free_page_hash[num]=result->next;
goto at_done;
}
i=Bsr(FREE_PAGE_HASH_SIZE)+1;
i=Bsr(MEM_FREE_PAGE_HASH_SIZE)+1;
} else {
//We'll now round-up to a power of two.
//There is some overhead on allocations and
//we wouldn't want to round to the next
//power of two if a power of two was requested.
//So we use a little more than a power of two.
num-=2;
num-=MEM_EXTRA_HASH2_PAGES;
i=Bsr(num)+1;
num=1<<i+2;
num=1<<i+MEM_EXTRA_HASH2_PAGES;
if (result=bp->free_page_hash2[i]) {
bp->free_page_hash2[i]=result->next;
goto at_done;
@@ -50,11 +50,11 @@ Return: NULL if out of memory.
//freed larger size block... and, screw-it, return the whole thing.
do {
if (result=bp->free_page_hash2[++i]) {
num=1<<i+2;
num=1<<i+MEM_EXTRA_HASH2_PAGES;
bp->free_page_hash2[i]=result->next;
goto at_done;
}
} while (i<64-PAGE_BITS-1);
} while (i<64-MEM_PAGE_BITS-1);
num=0;
result=NULL; //Out of memory
goto at_done;
@@ -67,7 +67,7 @@ Return: NULL if out of memory.
goto at_done;
} else {
result->pages-=num;
result(U8 *)+=result->pages<<PAGE_BITS;
result(U8 *)+=result->pages<<MEM_PAGE_BITS;
result->pages=num;
goto at_done;
}
@@ -75,7 +75,7 @@ Return: NULL if out of memory.
}
at_done:
*_pages512=num;
bp->used_u8s+=num<<PAGE_BITS;
bp->used_u8s+=num<<MEM_PAGE_BITS;
LBtr(&bp->locked_flags,BPlf_LOCKED);
POPFD
return result;
@@ -92,8 +92,8 @@ U0 Mem512Free(CMemBlk *m,I64 pages512,CBlkPool *bp=NULL)
PAUSE
m->mb_signature=MBS_UNUSED_SIGNATURE_VAL;
m->pages=pages512;
bp->used_u8s-=pages512<<PAGE_BITS;
if (pages512<FREE_PAGE_HASH_SIZE) {
bp->used_u8s-=pages512<<MEM_PAGE_BITS;
if (pages512<MEM_FREE_PAGE_HASH_SIZE) {
m->next=bp->free_page_hash[pages512];
bp->free_page_hash[pages512]=m;
} else {
@@ -102,7 +102,7 @@ U0 Mem512Free(CMemBlk *m,I64 pages512,CBlkPool *bp=NULL)
//we wouldn't want to round to the next
//power of two if a power of two was requested.
//So we use a little more than a power of two.
pages512-=2;
pages512-=MEM_EXTRA_HASH2_PAGES;
i=Bsr(pages512);
m->next=bp->free_page_hash2[i];
bp->free_page_hash2[i]=m;
@@ -124,12 +124,12 @@ Return: NULL if out of memory.
if (result=Mem512Alloc(_pages512,hc->bp)) {
QueIns(result,hc->last_mem_blk);
result->mb_signature=MBS_USED_SIGNATURE_VAL;
hc->alloced_u8s+=*_pages512<<PAGE_BITS;
hc->alloced_u8s+=*_pages512<<MEM_PAGE_BITS;
//Tidy-up free lst (Move into heap hash)
//because if free lst gets long, delay causes crash
threshold=HEAP_HASH_SIZE>>4;
#assert HEAP_HASH_SIZE>>4>=sizeof(U8 *)
threshold=MEM_HEAP_HASH_SIZE>>4;
#assert MEM_HEAP_HASH_SIZE>>4>=sizeof(U8 *)
do {
cnt=0;
_uum=&hc->malloc_free_lst;
@@ -147,7 +147,7 @@ Return: NULL if out of memory.
}
}
threshold<<=1;
} while (cnt>8 && threshold<=HEAP_HASH_SIZE);
} while (cnt>8 && threshold<=MEM_HEAP_HASH_SIZE);
}
return result;
}
@@ -161,7 +161,7 @@ U0 Mem512TaskFree(CMemBlk *m,CHeapCtrl *hc)
SysBadFree(m);
else {
QueRem(m);
hc->alloced_u8s-=m->pages<<PAGE_BITS;
hc->alloced_u8s-=m->pages<<MEM_PAGE_BITS;
Mem512Free(m,m->pages,hc->bp);
}
POPFD
+4 -3
View File
@@ -124,7 +124,8 @@ pain without MAlloc up-and-running.
#define ESTIMATED_MISC_ALLOCS 0x100000
#assert CONSERVATIVE_16MEG_SIZE-
(SYS_FIXED_AREA+sizeof(CSysFixedArea))>ADAM_STK+ESTIMATED_MISC_ALLOCS
(SYS_FIXED_AREA+sizeof(CSysFixedArea))>MEM_ADAM_STK+
ESTIMATED_MISC_ALLOCS
//EBX=BASE EAX=SIZE
TEST U8 [SYS_MEM_INIT_FLAG],1
@@ -136,7 +137,7 @@ pain without MAlloc up-and-running.
REP_STOSB
POP EAX
@@40: SHR EAX,PAGE_BITS
@@40: SHR EAX,MEM_PAGE_BITS
MOV ESI,SYS_FIXED_AREA+CSysFixedArea.adam_bp
MOV EDI,U32 CBlkPool.mem_free_lst[ESI]
MOV U32 CMemBlk.next[EBX],EDI
@@ -145,7 +146,7 @@ pain without MAlloc up-and-running.
MOV U32 CBlkPool.mem_free_lst+4[ESI],0
MOV U32 CMemBlk.mb_signature[EBX],MBS_UNUSED_SIGNATURE_VAL
MOV U32 CMemBlk.pages[EBX],EAX
SHL EAX,PAGE_BITS
SHL EAX,MEM_PAGE_BITS
ADD U32 CBlkPool.alloced_u8s[ESI],EAX
RET
}