1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-11-04 22:54:03 +02:00
iris/memory.ccp

64 lines
1.3 KiB
Plaintext
Raw Normal View History

#pypp 0
#include "kernel.hh"
static FreePage *zero_pages, *junk_pages
extern unsigned _end
unsigned init_memory (unsigned mem):
zero_pages = NULL
// Fill junk pages with all memory not currently used.
junk_pages = (FreePage *)(((unsigned)&_end + ~PAGE_MASK) & PAGE_MASK)
FreePage *p, *next
unsigned count = 1
for p = junk_pages, next = p; (unsigned)next - 0x80000000 < mem; p = next, next = (FreePage *)((unsigned)p + PAGE_SIZE):
p->next = next
++count
p->next = NULL
return count
unsigned raw_zalloc ():
FreePage *ret = zero_pages
if !ret:
ret = junk_pages
junk_pages = ret->next
for unsigned i = 0; i < (PAGE_SIZE >> 2); ++i:
((unsigned *)ret)[i] = 0
else:
zero_pages = ret->next
ret->next = NULL
return (unsigned)ret
void raw_pfree (unsigned page):
if !page:
return
FreePage *p = (FreePage *)page
p->next = junk_pages
junk_pages = p
unsigned Memory::palloc ():
if !use ():
return NULL
FreePage *ret = junk_pages
if !ret:
ret = zero_pages
zero_pages = ret->next
else:
junk_pages = ret->next
return (unsigned)ret
unsigned Memory::zalloc ():
if !use ():
return NULL
return raw_zalloc ()
void Memory::pfree (unsigned page):
unuse ()
return raw_pfree (page)
void Memory::zfree (unsigned page):
unuse ()
FreePage *p = (FreePage *)page
p->next = zero_pages
zero_pages = p