mirror of
git://projects.qi-hardware.com/iris.git
synced 2025-01-30 19:01:05 +02:00
prepare memory reorganization and minor fixes
This commit is contained in:
parent
4b47df85e3
commit
cc1dc267d5
2
Makefile
2
Makefile
@ -23,7 +23,7 @@ LD = $(CROSS)ld
|
||||
OBJCOPY = $(CROSS)objcopy
|
||||
|
||||
headers = kernel.hh iris.h $(arch_headers)
|
||||
kernel_sources = panic.cc data.cc alloc.cc invoke.cc schedule.cc $(arch_kernel_sources)
|
||||
kernel_sources = panic.cc data.cc alloc.cc memory.cc invoke.cc schedule.cc $(arch_kernel_sources)
|
||||
BUILT_SOURCES = $(kernel_sources) $(boot_sources)
|
||||
|
||||
# Include arch-specific rules.
|
||||
|
45
alloc.ccp
45
alloc.ccp
@ -37,51 +37,6 @@ void Memory::unuse ():
|
||||
for Memory *m = this; m; m = m->address_space:
|
||||
--m->used
|
||||
|
||||
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
|
||||
|
||||
void *Memory::search_free (unsigned size, void **first):
|
||||
Free *f
|
||||
unsigned s = 0
|
||||
|
@ -287,11 +287,10 @@ static void memory_invoke (unsigned target, unsigned protected_data, Capability:
|
||||
t &= ~CAP_PAGE_WRITE
|
||||
reply_cap (t, (unsigned)page)
|
||||
break
|
||||
case CAP_MEMORY_SET_LIMIT:
|
||||
mem->limit = c->data[1]
|
||||
break
|
||||
case CAP_MEMORY_GET_LIMIT:
|
||||
case CAP_MEMORY_LIMIT:
|
||||
reply_num (mem->limit)
|
||||
if c->data[2]:
|
||||
mem->limit = c->data[1]
|
||||
break
|
||||
case CAP_MEMORY_DROP:
|
||||
if !c->cap[0] || c->cap[0]->address_space != mem:
|
||||
|
8
iris.h
8
iris.h
@ -67,8 +67,7 @@ extern "C" {
|
||||
#define CAP_MEMORY_LIST 3
|
||||
#define CAP_MEMORY_MAP 4
|
||||
#define CAP_MEMORY_MAPPING 5
|
||||
#define CAP_MEMORY_SET_LIMIT 6
|
||||
#define CAP_MEMORY_GET_LIMIT 7
|
||||
#define CAP_MEMORY_LIMIT 6
|
||||
#define CAP_MEMORY_DROP 8
|
||||
#define CAP_MEMORY_ALL_RIGHTS 0x1ff
|
||||
|
||||
@ -463,6 +462,11 @@ static Capability memory_mapping (Capability memory, unsigned address)
|
||||
return call_c02 (memory, CAP_MEMORY_MAPPING, address);
|
||||
}
|
||||
|
||||
static unsigned memory_limit (Capability memory, unsigned limit)
|
||||
{
|
||||
return call_c02 (memory, CAP_MEMORY_MAPPING, address);
|
||||
}
|
||||
|
||||
static void drop (Capability cap)
|
||||
{
|
||||
invoke_11 (__my_memory, cap, CAP_MEMORY_DROP);
|
||||
|
@ -186,7 +186,6 @@ void timer_interrupt ()
|
||||
struct FreePage:
|
||||
FreePage *next
|
||||
|
||||
EXTERN FreePage *zero_pages, *junk_pages
|
||||
EXTERN Memory top_memory
|
||||
EXTERN Thread *sleepers, *runners
|
||||
EXTERN Thread idle
|
||||
@ -195,7 +194,8 @@ EXTERN Page idle_page
|
||||
EXTERN Thread *first_scheduled, *first_sleeper
|
||||
EXTERN Thread *current
|
||||
|
||||
// Defined in alloc.cc
|
||||
// Defined in memory.cc
|
||||
unsigned init_memory (unsigned mem)
|
||||
unsigned raw_zalloc ()
|
||||
void raw_pfree (unsigned page)
|
||||
|
||||
|
63
memory.ccp
Normal file
63
memory.ccp
Normal file
@ -0,0 +1,63 @@
|
||||
#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
|
||||
|
@ -154,7 +154,7 @@ extern "C":
|
||||
|
||||
#ifdef INIT
|
||||
// Initialize most things (the rest is done in boot.S)
|
||||
void init ()
|
||||
void init (unsigned mem)
|
||||
// Start running the idle task for the first time.
|
||||
void run_idle (Thread *self)
|
||||
#endif
|
||||
|
@ -55,6 +55,8 @@ start_hack_for_disassembler:
|
||||
bne $a1, $a0, 1b
|
||||
addu $a0, 4
|
||||
|
||||
// First argument is the memory size: 128 megabytes.
|
||||
li $a0, 128 << 20
|
||||
la $t9, init
|
||||
jr $t9
|
||||
nop
|
||||
|
@ -111,6 +111,7 @@ static void init_threads ():
|
||||
Thread *previous = NULL
|
||||
first_scheduled = NULL
|
||||
first_sleeper = NULL
|
||||
Receiver *init_receiver = NULL
|
||||
for unsigned i = 0; i < NUM_THREADS; ++i:
|
||||
Memory *mem = top_memory.alloc_memory ()
|
||||
Thread *thread = mem->alloc_thread ()
|
||||
@ -185,33 +186,27 @@ static void init_threads ():
|
||||
thread->arch.a1 = mkcap (mem, CAPTYPE_THREAD | CAP_THREAD_ALL_PRIV_RIGHTS, thread)
|
||||
thread->arch.a2 = mkcap (mem, CAPTYPE_MEMORY | CAP_MEMORY_ALL_RIGHTS, mem)
|
||||
thread->arch.a3 = mkcap (mem, CAPTYPE_RECEIVER | (1 << CAP_RECEIVER_CALL), recv)
|
||||
mem->pfree ((unsigned)pages)
|
||||
thread->flags = THREAD_FLAG_RUNNING | THREAD_FLAG_PRIV
|
||||
thread->schedule_next = NULL
|
||||
thread->schedule_prev = previous
|
||||
if previous:
|
||||
previous->schedule_next = thread
|
||||
else:
|
||||
if !i:
|
||||
first_scheduled = thread
|
||||
init_receiver = recv
|
||||
else:
|
||||
thread->arch.t0 = mkcap (mem, (unsigned)init_receiver, (void *)i)
|
||||
previous->schedule_next = thread
|
||||
thread->schedule_prev = previous
|
||||
previous = thread
|
||||
|
||||
mem->pfree ((unsigned)pages)
|
||||
thread->schedule_next = NULL
|
||||
|
||||
// Initialize the kernel, finish by falling into the idle task.
|
||||
extern unsigned _end
|
||||
void init ():
|
||||
void init (unsigned mem):
|
||||
// Disable interrupts and set interrupt vectors to normal.
|
||||
cp0_set0 (CP0_STATUS)
|
||||
// Initialize kernel variables to empty.
|
||||
sleepers = NULL
|
||||
runners = NULL
|
||||
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 < (1 << 27); p = next, next = (FreePage *)((unsigned)p + PAGE_SIZE):
|
||||
p->next = next
|
||||
++count
|
||||
p->next = NULL
|
||||
unsigned count = init_memory (mem)
|
||||
// initialize system control coprocessor.
|
||||
init_cp0 ()
|
||||
// initialize everything about the idle task.
|
||||
@ -258,13 +253,13 @@ void init ():
|
||||
GPIO_GPDR (GPIO_USB_CLK_EN_PORT) |= 1 << GPIO_USB_CLK_EN
|
||||
|
||||
// Start the operating system timer, and set it to give an interrupt immediately.
|
||||
// This is better, because the kernel start with jumping into the idle task and
|
||||
// This is better, because the kernel starts with jumping into the idle task and
|
||||
// waiting for the first interrupt.
|
||||
unsigned latch = (JZ_EXTAL + (HZ >> 1)) / HZ
|
||||
ost_disable_all ()
|
||||
ost_set_mode (0, OST_TCSR_UIE | OST_TCSR_CKS_EXTAL)
|
||||
ost_set_reload (0, latch)
|
||||
ost_set_count (0, 0)
|
||||
ost_set_count (0, 1)
|
||||
ost_set_mode (0, OST_TCSR_UIE | OST_TCSR_CKS_EXTAL)
|
||||
ost_enable_channel (0)
|
||||
intc_unmask_irq (IRQ_OST0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user