1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-06-28 18:59:51 +03:00

make code work again

This commit is contained in:
Bas Wijnen 2009-12-30 22:41:45 +01:00
parent 8a7c8a1ea9
commit dc1bbc1f5f
9 changed files with 99 additions and 61 deletions

View File

@ -197,10 +197,10 @@ kThread *kMemory::alloc_thread (unsigned size):
ret->slot[i].caps = NULL
return ret
void kCaps::init (unsigned size):
void kCaps::init (unsigned s):
first_slot.thread = NULL
size = size
for unsigned i = 0; i < size; ++i:
size = s
for unsigned i = 0; i < s; ++i:
set (i, NULL, 0, kCapRef (), NULL)
kCaps *kMemory::alloc_caps (unsigned size):

View File

@ -133,15 +133,15 @@ Kernel::Num start ():
// claim backlight
Setting backlight = backlight_dev.create_user (Kernel::Cap ())
backlight_dev.use (backlight)
bool backlight_state = true
while true:
Kernel::wait ()
switch Kernel::recv.protected_data.value ():
case SYSREQ:
unsigned code = Kernel::recv.data[0].l
if code & Keyboard::RELEASE:
backlight.set (~0)
else:
backlight.set (0)
if !(code & Keyboard::RELEASE):
backlight_state = !backlight_state
backlight.set (backlight_state ? ~0 : 0)
break
default:
if Kernel::recv.data[0].l != Parent::GET_DEVICE:

View File

@ -313,9 +313,9 @@ Kernel::Num start ():
unsigned backlight_user = 0
Kernel::Num current_backlight = 0
while true:
log_str ("Wachten...\n")
//log_str ("Wachten...\n")
Kernel::wait ()
log_msg ()
//log_msg ()
switch Kernel::recv.protected_data.h:
case 0:
switch Kernel::recv.protected_data.l:

View File

@ -76,7 +76,6 @@ kCapRef kThread::find_capability (unsigned code, bool *copy):
unsigned num = c & 0xffff
if s >= slots || !slot[s].caps || num >= slot[s].caps->size:
if c != CAP_NONE:
dpanic (code, "debug")
dbg_log_num ((unsigned)old_current)
dbg_log (": invalid capability ")
dbg_log_num (code)
@ -90,6 +89,7 @@ kCapRef kThread::find_capability (unsigned code, bool *copy):
else:
dbg_log ("no caps")
dbg_log_char ('\n')
dpanic (code, "debug")
return kCapRef ()
return kCapRef (slot[s].caps, num)

View File

@ -306,6 +306,7 @@ kPage *kMemory_arch_get_mapping (kMemory *mem, unsigned address, bool *readonly)
void kPage_arch_update_mapping (kPage *page)
void arch_register_interrupt (unsigned num, kReceiverP r)
void arch_reboot ()
void arch_uncache_page (unsigned page)
bool kMemory::map (kPage *page, unsigned address, bool readonly = false):
return kMemory_arch_map (this, page, address, readonly)
@ -323,6 +324,6 @@ void kCapability::invoke (kCapability::Context *c):
::invoke (target, protected_data, c)
#define assert(x) do { if (!(x)) panic (__LINE__, "assertion failed"); } while (0)
#define dbg_log_line() do { dbg_log ("debug: line "); dbg_log_num (__LINE__); dbg_log_char ('\n'); } while (0)
#define dbg_log_line() do { dbg_log ("debug: "); dbg_log (__PRETTY_FUNCTION__); dbg_log (" line "); dbg_log_num (__LINE__); dbg_log_char ('\n'); } while (0)
#endif

View File

@ -6,6 +6,8 @@ extern unsigned _end
static void clear_page (unsigned page, unsigned num = 1):
page = (page & ~0xc0000000) | 0xa0000000
for unsigned i = 0; i < (num << (PAGE_BITS - 2)); ++i:
arch_uncache_page (page - 0x20000000)
// Clear page.
((unsigned *)page)[i] = 0
if *((unsigned *)page) != 0 || ((unsigned *)page)[(num << (PAGE_BITS - 2)) - 1] != 0:
dpanic (0, "clear_page didn't work")
@ -54,11 +56,13 @@ unsigned init_memory (unsigned mem):
first_free->prev = NULL
first_free->next = NULL
first_free->num = ((mem & PAGE_MASK) - ((unsigned)first_free & ~0xc0000000)) >> PAGE_BITS
//dbg_log ("initial memory: ")
//dbg_log_num ((unsigned)first_free & ~0xc0000000)
//dbg_log ("+")
//dbg_log_num (first_free->num)
//dbg_log ("\n")
#ifdef DEBUG_ALLOC
dbg_log ("initial memory: ")
dbg_log_num ((unsigned)first_free & ~0xc0000000)
dbg_log ("+")
dbg_log_num (first_free->num)
dbg_log ("\n")
#endif
return first_free->num
unsigned phys_alloc (unsigned num):
@ -76,11 +80,13 @@ unsigned phys_alloc (unsigned num):
if p->next:
p->next->prev = p->prev
clear_page ((unsigned)p, num)
//dbg_log ("allocating ")
//dbg_log_num ((unsigned)p & ~0xc0000000)
//dbg_log ("+")
//dbg_log_num (num << PAGE_BITS)
//dbg_log ("\n")
#ifdef DEBUG_ALLOC
dbg_log ("allocating ")
dbg_log_num ((unsigned)p & ~0xc0000000)
dbg_log ("+")
dbg_log_num (num << PAGE_BITS)
dbg_log ("\n")
#endif
return (unsigned)p
choice = p
if !choice:
@ -90,19 +96,23 @@ unsigned phys_alloc (unsigned num):
choice->num -= num
unsigned ret = (unsigned)choice + (choice->num << PAGE_BITS)
clear_page (ret, num)
//dbg_log ("allocating ")
//dbg_log_num (ret & ~0xc0000000)
//dbg_log ("+")
//dbg_log_num (num << PAGE_BITS)
//dbg_log ("\n")
#ifdef DEBUG_ALLOC
dbg_log ("allocating ")
dbg_log_num (ret & ~0xc0000000)
dbg_log ("+")
dbg_log_num (num << PAGE_BITS)
dbg_log ("\n")
#endif
return ret
void phys_free (unsigned page, unsigned num):
//dbg_log ("free ")
//dbg_log_num (page & ~0xc0000000)
//dbg_log ("+")
//dbg_log_num (num)
//dbg_log ("\n")
#ifdef DEBUG_ALLOC
dbg_log ("free ")
dbg_log_num (page & ~0xc0000000)
dbg_log ("+")
dbg_log_num (num)
dbg_log ("\n")
#endif
unsigned size = num << PAGE_BITS
if !first_free || (unsigned)first_free > page:
// This is the first free block.

View File

@ -115,6 +115,7 @@ void kMemory_arch_init (kMemory *mem):
mem->arch.shadow = NULL
void kMemory_arch_free (kMemory *mem):
//dbg_log_line ()
while mem->arch.first_page_table:
mem->unmap (mem->arch.first_page_table->first_page->page, mem->arch.first_page_table->first_page->mapping)
if (kMemory *)asids[mem->arch.asid] == mem:
@ -125,6 +126,7 @@ void kMemory_arch_free (kMemory *mem):
mem->zfree ((unsigned)mem->arch.directory)
static arch_page_table *alloc_page_table (kMemory *mem):
//dbg_log_line ()
arch_page_table *ret = (arch_page_table *)mem->search_free (sizeof (arch_page_table), (void **)&mem->arch.first_page_table)
if !ret:
return NULL
@ -132,6 +134,7 @@ static arch_page_table *alloc_page_table (kMemory *mem):
return ret
static arch_page *alloc_page (kMemory *mem, arch_page_table *t):
//dbg_log_line ()
arch_page *ret = (arch_page *)mem->search_free (sizeof (arch_page), (void **)&t->first_page)
if !ret:
return NULL
@ -142,6 +145,7 @@ static arch_page *alloc_page (kMemory *mem, arch_page_table *t):
return ret
static void free_page_table (arch_page_table *t, unsigned idx):
//dbg_log_line ()
kMemory *mem = t->address_space
mem->zfree ((unsigned)mem->arch.directory[idx])
mem->arch.directory[idx] = NULL
@ -154,6 +158,7 @@ static void free_page_table (arch_page_table *t, unsigned idx):
mem->arch.shadow = NULL
static void tlb_reset (unsigned address, unsigned asid, unsigned value):
//dbg_log_line ()
cp0_set (CP0_ENTRY_HI, address | asid)
__asm__ volatile ("tlbp")
unsigned idx
@ -166,9 +171,10 @@ static void tlb_reset (unsigned address, unsigned asid, unsigned value):
__asm__ volatile ("tlbwi")
static void free_page (arch_page_table *t, arch_page *p):
dbg_log ("free page ")
dbg_log_num ((unsigned)p)
dbg_log_char ('\n')
//dbg_log_line ()
if !p:
dpanic (0, "freeing page 0")
return
if p->prev_mapped:
p->prev_mapped->next_mapped = p->next_mapped
else:
@ -182,6 +188,7 @@ static void free_page (arch_page_table *t, arch_page *p):
free_page_table (t, idx)
static unsigned make_entry_lo (kPage *page, bool readonly):
//dbg_log_line ()
if !page->frame:
return 0
unsigned flags
@ -195,6 +202,7 @@ static unsigned make_entry_lo (kPage *page, bool readonly):
return ((page->frame & ~0x80000000) >> 6) | flags
bool kMemory_arch_map (kMemory *mem, kPage *page, unsigned address, bool readonly):
//dbg_log_line ()
if address >= 0x80000000:
panic (0x32134293, "trying to map to kernel address")
return false
@ -238,6 +246,15 @@ bool kMemory_arch_map (kMemory *mem, kPage *page, unsigned address, bool readonl
return false
unsigned idx = (address >> 12) & ((1 << 9) - 1)
if table[idx]:
dbg_log ("page already mapped: ")
dbg_log_num (idx, 3)
dbg_log (";")
dbg_log_num (table[idx])
dbg_log ("/")
dbg_log_num (table[idx + 0x200])
dbg_log (" table: ")
dbg_log_num ((unsigned)table)
dbg_log ("\n")
mem->unmap ((kPage *)table[idx + 0x200], address)
table[idx] = make_entry_lo (page, readonly)
table[idx + 0x200] = (unsigned)p
@ -250,6 +267,7 @@ bool kMemory_arch_map (kMemory *mem, kPage *page, unsigned address, bool readonl
return true
void kMemory_arch_unmap (kMemory *mem, kPage *page, unsigned address):
//dbg_log_line ()
unsigned didx = address >> 21
unsigned tidx = (address >> 12) & ((1 << 9) - 1)
unsigned *table = mem->arch.directory[didx]
@ -260,6 +278,7 @@ void kMemory_arch_unmap (kMemory *mem, kPage *page, unsigned address):
free_page (t, p)
kPage *kMemory_arch_get_mapping (kMemory *mem, unsigned address, bool *readonly):
//dbg_log_line ()
if address >= 0x80000000 || !mem->arch.directory:
return NULL
unsigned *table = mem->arch.directory[address >> 21]
@ -274,6 +293,7 @@ kPage *kMemory_arch_get_mapping (kMemory *mem, unsigned address, bool *readonly)
return page->page
void kPage_arch_update_mapping (kPage *page):
//dbg_log_line ()
if !page->arch.first_mapped:
return
kMemory *as = page->address_space
@ -290,6 +310,11 @@ void kPage_arch_update_mapping (kPage *page):
as->arch.directory[de][te] = t
tlb_reset (p->mapping & ~1, as->arch.asid, t)
typedef unsigned cacheline[8]
void arch_uncache_page (unsigned page):
for cacheline *line = (cacheline *)page; line < (cacheline *)(page + PAGE_SIZE); ++line:
__asm__ volatile ("lw $k0, %0; cache 0x10, 0($k0); cache 0x11, 0($k0)" :: "m"(line))
void arch_register_interrupt (unsigned num, kReceiver *r):
arch_interrupt_receiver[num] = r
// And enable or disable the interrupt.

View File

@ -246,10 +246,8 @@ static void init_threads ():
// Initialize the kernel, finish by falling into the idle task.
void init (unsigned mem):
#ifndef NDEBUG
// Initialize board-specific things.
board_init ()
#endif
must_wait = false
// Initialize kernel variables to empty.
unsigned count = init_memory (mem)

View File

@ -45,6 +45,34 @@ void dbg_log_num (unsigned num, unsigned digits):
return
#if 1 || defined (NDEBUG)
static void panic_message (unsigned n, unsigned line, char const *name, char const *message):
dbg_log ("Panic: caller = ")
if old_current:
dbg_log_num (old_current->id, 2)
dbg_log (":")
dbg_log_num ((unsigned)old_current)
if old_current:
dbg_log_char ('@')
dbg_log_num (old_current->pc)
dbg_log ("; ")
dbg_log (name)
dbg_log_char (':')
dbg_log_num (line)
dbg_log (": ")
dbg_log (message)
dbg_log_char ('/')
dbg_log_num (n)
dbg_log_char (';')
dbg_log_num (dbg_code.h)
dbg_log (" bad vaddr = ")
unsigned a
cp0_get (CP0_BAD_V_ADDR, a)
dbg_log_num (a)
dbg_log (" epc = ")
cp0_get (CP0_EPC, a)
dbg_log_num (a)
dbg_log_char ('\n')
void panic_impl (unsigned n, unsigned line, char const *name, char const *message):
// Stop all threads.
while first_scheduled:
@ -57,36 +85,12 @@ void panic_impl (unsigned n, unsigned line, char const *name, char const *messag
arch_interrupt_receiver[i]->owner->unrun ()
#ifndef NDEBUG
// If a log capability is registered, run its owner.
panic_message (n, line, name, message)
if dbg_cap.valid () && dbg_cap->target->owner:
#ifndef USE_SERIAL
dbg_cap->target->owner->run ()
#endif
// Use the (now running) log thread to display the message.
dbg_log ("Panic: caller = ")
dbg_log_num (old_current->id, 2)
dbg_log (":")
dbg_log_num ((unsigned)old_current)
if old_current:
dbg_log_char ('@')
dbg_log_num (old_current->pc)
dbg_log ("; ")
dbg_log (name)
dbg_log_char (':')
dbg_log_num (line)
dbg_log (": ")
dbg_log (message)
dbg_log_char ('/')
dbg_log_num (n)
dbg_log_char (';')
dbg_log_num (dbg_code.h)
dbg_log (" bad vaddr = ")
unsigned a
cp0_get (CP0_BAD_V_ADDR, a)
dbg_log_num (a)
dbg_log (" epc = ")
cp0_get (CP0_EPC, a)
dbg_log_num (a)
dbg_log_char ('\n')
// If no log capability is registered, the machine just hangs.
#ifdef USE_SERIAL
arch_reboot ()