1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-07-01 01:29:31 +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 ret->slot[i].caps = NULL
return ret return ret
void kCaps::init (unsigned size): void kCaps::init (unsigned s):
first_slot.thread = NULL first_slot.thread = NULL
size = size size = s
for unsigned i = 0; i < size; ++i: for unsigned i = 0; i < s; ++i:
set (i, NULL, 0, kCapRef (), NULL) set (i, NULL, 0, kCapRef (), NULL)
kCaps *kMemory::alloc_caps (unsigned size): kCaps *kMemory::alloc_caps (unsigned size):

View File

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

View File

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

View File

@ -76,7 +76,6 @@ kCapRef kThread::find_capability (unsigned code, bool *copy):
unsigned num = c & 0xffff unsigned num = c & 0xffff
if s >= slots || !slot[s].caps || num >= slot[s].caps->size: if s >= slots || !slot[s].caps || num >= slot[s].caps->size:
if c != CAP_NONE: if c != CAP_NONE:
dpanic (code, "debug")
dbg_log_num ((unsigned)old_current) dbg_log_num ((unsigned)old_current)
dbg_log (": invalid capability ") dbg_log (": invalid capability ")
dbg_log_num (code) dbg_log_num (code)
@ -90,6 +89,7 @@ kCapRef kThread::find_capability (unsigned code, bool *copy):
else: else:
dbg_log ("no caps") dbg_log ("no caps")
dbg_log_char ('\n') dbg_log_char ('\n')
dpanic (code, "debug")
return kCapRef () return kCapRef ()
return kCapRef (slot[s].caps, num) 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 kPage_arch_update_mapping (kPage *page)
void arch_register_interrupt (unsigned num, kReceiverP r) void arch_register_interrupt (unsigned num, kReceiverP r)
void arch_reboot () void arch_reboot ()
void arch_uncache_page (unsigned page)
bool kMemory::map (kPage *page, unsigned address, bool readonly = false): bool kMemory::map (kPage *page, unsigned address, bool readonly = false):
return kMemory_arch_map (this, page, address, readonly) return kMemory_arch_map (this, page, address, readonly)
@ -323,6 +324,6 @@ void kCapability::invoke (kCapability::Context *c):
::invoke (target, protected_data, c) ::invoke (target, protected_data, c)
#define assert(x) do { if (!(x)) panic (__LINE__, "assertion failed"); } while (0) #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 #endif

View File

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

View File

@ -115,6 +115,7 @@ void kMemory_arch_init (kMemory *mem):
mem->arch.shadow = NULL mem->arch.shadow = NULL
void kMemory_arch_free (kMemory *mem): void kMemory_arch_free (kMemory *mem):
//dbg_log_line ()
while mem->arch.first_page_table: while mem->arch.first_page_table:
mem->unmap (mem->arch.first_page_table->first_page->page, mem->arch.first_page_table->first_page->mapping) 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: if (kMemory *)asids[mem->arch.asid] == mem:
@ -125,6 +126,7 @@ void kMemory_arch_free (kMemory *mem):
mem->zfree ((unsigned)mem->arch.directory) mem->zfree ((unsigned)mem->arch.directory)
static arch_page_table *alloc_page_table (kMemory *mem): 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) arch_page_table *ret = (arch_page_table *)mem->search_free (sizeof (arch_page_table), (void **)&mem->arch.first_page_table)
if !ret: if !ret:
return NULL return NULL
@ -132,6 +134,7 @@ static arch_page_table *alloc_page_table (kMemory *mem):
return ret return ret
static arch_page *alloc_page (kMemory *mem, arch_page_table *t): 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) arch_page *ret = (arch_page *)mem->search_free (sizeof (arch_page), (void **)&t->first_page)
if !ret: if !ret:
return NULL return NULL
@ -142,6 +145,7 @@ static arch_page *alloc_page (kMemory *mem, arch_page_table *t):
return ret return ret
static void free_page_table (arch_page_table *t, unsigned idx): static void free_page_table (arch_page_table *t, unsigned idx):
//dbg_log_line ()
kMemory *mem = t->address_space kMemory *mem = t->address_space
mem->zfree ((unsigned)mem->arch.directory[idx]) mem->zfree ((unsigned)mem->arch.directory[idx])
mem->arch.directory[idx] = NULL mem->arch.directory[idx] = NULL
@ -154,6 +158,7 @@ static void free_page_table (arch_page_table *t, unsigned idx):
mem->arch.shadow = NULL mem->arch.shadow = NULL
static void tlb_reset (unsigned address, unsigned asid, unsigned value): static void tlb_reset (unsigned address, unsigned asid, unsigned value):
//dbg_log_line ()
cp0_set (CP0_ENTRY_HI, address | asid) cp0_set (CP0_ENTRY_HI, address | asid)
__asm__ volatile ("tlbp") __asm__ volatile ("tlbp")
unsigned idx unsigned idx
@ -166,9 +171,10 @@ static void tlb_reset (unsigned address, unsigned asid, unsigned value):
__asm__ volatile ("tlbwi") __asm__ volatile ("tlbwi")
static void free_page (arch_page_table *t, arch_page *p): static void free_page (arch_page_table *t, arch_page *p):
dbg_log ("free page ") //dbg_log_line ()
dbg_log_num ((unsigned)p) if !p:
dbg_log_char ('\n') dpanic (0, "freeing page 0")
return
if p->prev_mapped: if p->prev_mapped:
p->prev_mapped->next_mapped = p->next_mapped p->prev_mapped->next_mapped = p->next_mapped
else: else:
@ -182,6 +188,7 @@ static void free_page (arch_page_table *t, arch_page *p):
free_page_table (t, idx) free_page_table (t, idx)
static unsigned make_entry_lo (kPage *page, bool readonly): static unsigned make_entry_lo (kPage *page, bool readonly):
//dbg_log_line ()
if !page->frame: if !page->frame:
return 0 return 0
unsigned flags unsigned flags
@ -195,6 +202,7 @@ static unsigned make_entry_lo (kPage *page, bool readonly):
return ((page->frame & ~0x80000000) >> 6) | flags return ((page->frame & ~0x80000000) >> 6) | flags
bool kMemory_arch_map (kMemory *mem, kPage *page, unsigned address, bool readonly): bool kMemory_arch_map (kMemory *mem, kPage *page, unsigned address, bool readonly):
//dbg_log_line ()
if address >= 0x80000000: if address >= 0x80000000:
panic (0x32134293, "trying to map to kernel address") panic (0x32134293, "trying to map to kernel address")
return false return false
@ -238,6 +246,15 @@ bool kMemory_arch_map (kMemory *mem, kPage *page, unsigned address, bool readonl
return false return false
unsigned idx = (address >> 12) & ((1 << 9) - 1) unsigned idx = (address >> 12) & ((1 << 9) - 1)
if table[idx]: 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) mem->unmap ((kPage *)table[idx + 0x200], address)
table[idx] = make_entry_lo (page, readonly) table[idx] = make_entry_lo (page, readonly)
table[idx + 0x200] = (unsigned)p table[idx + 0x200] = (unsigned)p
@ -250,6 +267,7 @@ bool kMemory_arch_map (kMemory *mem, kPage *page, unsigned address, bool readonl
return true return true
void kMemory_arch_unmap (kMemory *mem, kPage *page, unsigned address): void kMemory_arch_unmap (kMemory *mem, kPage *page, unsigned address):
//dbg_log_line ()
unsigned didx = address >> 21 unsigned didx = address >> 21
unsigned tidx = (address >> 12) & ((1 << 9) - 1) unsigned tidx = (address >> 12) & ((1 << 9) - 1)
unsigned *table = mem->arch.directory[didx] unsigned *table = mem->arch.directory[didx]
@ -260,6 +278,7 @@ void kMemory_arch_unmap (kMemory *mem, kPage *page, unsigned address):
free_page (t, p) free_page (t, p)
kPage *kMemory_arch_get_mapping (kMemory *mem, unsigned address, bool *readonly): kPage *kMemory_arch_get_mapping (kMemory *mem, unsigned address, bool *readonly):
//dbg_log_line ()
if address >= 0x80000000 || !mem->arch.directory: if address >= 0x80000000 || !mem->arch.directory:
return NULL return NULL
unsigned *table = mem->arch.directory[address >> 21] 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 return page->page
void kPage_arch_update_mapping (kPage *page): void kPage_arch_update_mapping (kPage *page):
//dbg_log_line ()
if !page->arch.first_mapped: if !page->arch.first_mapped:
return return
kMemory *as = page->address_space kMemory *as = page->address_space
@ -290,6 +310,11 @@ void kPage_arch_update_mapping (kPage *page):
as->arch.directory[de][te] = t as->arch.directory[de][te] = t
tlb_reset (p->mapping & ~1, as->arch.asid, 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): void arch_register_interrupt (unsigned num, kReceiver *r):
arch_interrupt_receiver[num] = r arch_interrupt_receiver[num] = r
// And enable or disable the interrupt. // 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. // Initialize the kernel, finish by falling into the idle task.
void init (unsigned mem): void init (unsigned mem):
#ifndef NDEBUG
// Initialize board-specific things. // Initialize board-specific things.
board_init () board_init ()
#endif
must_wait = false must_wait = false
// Initialize kernel variables to empty. // Initialize kernel variables to empty.
unsigned count = init_memory (mem) unsigned count = init_memory (mem)

View File

@ -45,6 +45,34 @@ void dbg_log_num (unsigned num, unsigned digits):
return return
#if 1 || defined (NDEBUG) #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): void panic_impl (unsigned n, unsigned line, char const *name, char const *message):
// Stop all threads. // Stop all threads.
while first_scheduled: 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 () arch_interrupt_receiver[i]->owner->unrun ()
#ifndef NDEBUG #ifndef NDEBUG
// If a log capability is registered, run its owner. // If a log capability is registered, run its owner.
panic_message (n, line, name, message)
if dbg_cap.valid () && dbg_cap->target->owner: if dbg_cap.valid () && dbg_cap->target->owner:
#ifndef USE_SERIAL #ifndef USE_SERIAL
dbg_cap->target->owner->run () dbg_cap->target->owner->run ()
#endif #endif
// Use the (now running) log thread to display the message. // 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. // If no log capability is registered, the machine just hangs.
#ifdef USE_SERIAL #ifdef USE_SERIAL
arch_reboot () arch_reboot ()