1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-11-16 19:05:22 +02:00
iris/panic.ccp

250 lines
6.8 KiB
Plaintext
Raw Normal View History

2009-05-11 01:28:12 +03:00
#pypp 0
2009-06-01 15:26:42 +03:00
// Iris: micro-kernel for a capability-based operating system.
// panic.ccp: Stop running and try to notify the user of the problem.
// Copyright 2009 Bas Wijnen <wijnen@debian.org>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2009-07-23 13:06:32 +03:00
#define ARCH
2009-05-11 01:28:12 +03:00
#include "kernel.hh"
#ifdef USE_SERIAL
2010-01-24 22:34:24 +02:00
void kdebug (unsigned ch):
while !(UART0_LSR & UARTLSR_TDRQ):
UART0_TDR = ch
#else
2010-01-24 22:34:24 +02:00
void kdebug (unsigned ch):
2009-12-26 15:17:06 +02:00
if !dbg_cap.valid () || dbg_code.l:
2009-07-23 13:06:32 +03:00
return
2009-08-24 22:02:35 +03:00
kCapability::Context c
2009-07-23 13:06:32 +03:00
c.data[0] = ch
2009-09-06 12:04:09 +03:00
++dbg_code.l
2009-07-23 13:06:32 +03:00
dbg_cap->invoke (&c)
2009-09-06 12:04:09 +03:00
--dbg_code.l
#endif
2009-07-23 13:06:32 +03:00
2010-01-24 22:34:24 +02:00
void kdebug (char const *str):
2009-07-23 13:06:32 +03:00
while *str:
2010-01-24 22:34:24 +02:00
kdebug (*str++)
2009-07-23 13:06:32 +03:00
2010-01-24 22:34:24 +02:00
void kdebug_num (unsigned num, unsigned digits):
2009-07-23 13:06:32 +03:00
char const *encode = "0123456789abcdef"
2009-09-01 20:00:46 +03:00
for unsigned i = 0; i < digits; ++i:
2010-01-24 22:34:24 +02:00
kdebug (encode[(num >> (4 * ((digits - 1) - i))) & 0xf])
2009-07-23 13:06:32 +03:00
return
2009-09-06 12:04:09 +03:00
#if 1 || defined (NDEBUG)
2010-01-24 22:34:24 +02:00
static void print_addr (char const *t, unsigned addr, bool last = false):
kdebug (t)
kdebug_num (addr)
#if 0
2010-01-18 06:01:59 +02:00
unsigned de = addr >> 21
unsigned te = (addr >> 12) & ((1 << 9) - 1)
if de < 0x400 && old_current && old_current->address_space->arch.directory && old_current->address_space->arch.directory[de]:
2010-01-24 22:34:24 +02:00
kdebug ("; EntryLo = ")
kdebug_num (old_current->address_space->arch.directory[de]->entrylo[te])
2010-01-18 06:01:59 +02:00
else:
2010-01-24 22:34:24 +02:00
kdebug ("; no directory or page table")
if old_current && de < 0x400:
2010-01-18 06:01:59 +02:00
cp0_set (CP0_ENTRY_HI, (addr & (PAGE_MASK << 1)) | old_current->address_space->arch.asid)
__asm__ volatile ("tlbp")
unsigned idx, hi
cp0_get (CP0_INDEX, idx)
2010-01-24 22:34:24 +02:00
kdebug ("; tlb index: ")
2010-01-18 06:01:59 +02:00
if idx & (1 << 31):
2010-01-24 22:34:24 +02:00
kdebug ("none\n")
2010-01-18 06:01:59 +02:00
else:
2010-01-18 07:45:52 +02:00
__asm__ volatile ("tlbr")
2010-01-24 22:34:24 +02:00
kdebug_num (idx, 2)
kdebug ("; EntryLo = ")
2010-01-18 06:01:59 +02:00
unsigned lo
cp0_get (CP0_ENTRY_LO0, lo)
2010-01-24 22:34:24 +02:00
kdebug_num (lo)
kdebug (":")
2010-01-18 06:01:59 +02:00
cp0_get (CP0_ENTRY_LO1, lo)
2010-01-24 22:34:24 +02:00
kdebug_num (lo)
kdebug ("\n")
else:
kdebug ('\n')
if addr >= 0x80000000 && addr < 0xc0000000:
2010-01-18 06:01:59 +02:00
for int i = -4; i < 4; ++i:
2010-01-24 22:34:24 +02:00
kdebug (" ")
kdebug_num (((unsigned *)addr)[i])
kdebug ("\n")
#else
kdebug (last ? "\n" : "; ")
2010-01-24 22:34:24 +02:00
#endif
2010-01-18 06:01:59 +02:00
2010-01-16 17:13:54 +02:00
static void panic_message (unsigned n, const char *line, char const *name, char const *message):
2010-08-22 23:03:06 +03:00
kdebug ("**********************************************************************\n")
2010-01-18 06:01:59 +02:00
unsigned vaddr, epc
cp0_get (CP0_BAD_V_ADDR, vaddr)
cp0_get (CP0_EPC, epc)
#if 1
unsigned addr
print_addr ("BadVAddr: ", vaddr)
if old_current:
print_addr ("PC: ", old_current->pc)
2010-01-24 22:34:24 +02:00
print_addr ("epc: ", epc, true)
2010-01-18 06:01:59 +02:00
#endif
2010-01-24 22:34:24 +02:00
kdebug ("Panic: caller = ")
2009-12-30 23:41:45 +02:00
if old_current:
2010-01-24 22:34:24 +02:00
kdebug_num (old_current->id, 2)
kdebug (":")
kdebug_num ((unsigned)old_current)
2009-12-30 23:41:45 +02:00
if old_current:
2010-01-24 22:34:24 +02:00
kdebug ('@')
kdebug_num (old_current->pc)
kdebug ("\nregisters: sp=")
kdebug_num (old_current->sp)
kdebug (" at=")
kdebug_num (old_current->arch.at)
kdebug ("\nv=")
kdebug_num (old_current->arch.v[0])
kdebug (" ")
kdebug_num (old_current->arch.v[1])
kdebug ("\na=")
for unsigned i = 0; i < 4; ++i:
kdebug_num (old_current->arch.a[i])
kdebug (" ")
kdebug ("\nt=")
for unsigned i = 0; i < 10; ++i:
kdebug_num (old_current->arch.t[i])
kdebug (" ")
kdebug ("\ns=")
for unsigned i = 0; i < 8; ++i:
kdebug_num (old_current->arch.s[i])
kdebug (" ")
kdebug ("\ngp=")
kdebug_num (old_current->arch.gp)
kdebug (" fp=")
kdebug_num (old_current->arch.fp)
kdebug (" ra=")
kdebug_num (old_current->arch.ra)
kdebug ("\nhi=")
kdebug_num (old_current->arch.hi)
kdebug (" lo=")
kdebug_num (old_current->arch.lo)
kdebug ("\nk=")
kdebug_num (old_current->arch.k[0])
kdebug (" ")
kdebug_num (old_current->arch.k[1])
kdebug ('\n')
2010-01-24 22:34:24 +02:00
kdebug ("; ")
kdebug (name)
kdebug (':')
kdebug (line)
kdebug (": ")
kdebug (message)
kdebug ('/')
kdebug_num (n)
kdebug ("; debug: ")
kdebug_num (dbg_code.h)
kdebug (':')
kdebug_num (dbg_code.l)
kdebug ('\n')
kdebug ("debug buffer (most recently pushed at end):")
2010-01-24 22:34:24 +02:00
unsigned b = dbg_buffer_head
for unsigned i = 0; i < 8; ++i:
2010-01-24 22:34:24 +02:00
kdebug ('\n')
for unsigned j = 0; j < 4; ++j:
2010-01-24 22:34:24 +02:00
kdebug (' ')
kdebug_num (dbg_buffer[b])
++b
if b == 32:
b = 0
kdebug ('\n')
if old_current:
kdebug ("Attempt to print *pc:\n")
unsigned page = old_current->pc & PAGE_MASK
unsigned start = old_current->pc & ~(4 * 4 - 1)
for int i = -4; i < 8; ++i:
kdebug_num (start + i * 4 * 4)
kdebug (" ==>")
for unsigned j = 0; j < 4; ++j:
kdebug (' ')
unsigned addr = start + (i * 4 + j) * 4
if (addr & PAGE_MASK) == page:
kdebug_num (*(unsigned *)addr)
else:
kdebug ("--------")
kdebug ('\n')
2009-12-30 23:41:45 +02:00
2010-01-16 17:13:54 +02:00
void panic_impl (unsigned n, const char *line, char const *name, char const *message):
2009-07-23 13:06:32 +03:00
// Stop all threads.
while first_scheduled:
first_scheduled->unrun ()
2009-08-24 22:02:35 +03:00
for kReceiver *r = first_alarm; r; r = r->next_alarm:
2009-07-23 13:06:32 +03:00
if r->owner:
r->owner->unrun ()
for unsigned i = 0; i < 32; ++i:
if arch_interrupt_receiver[i] && arch_interrupt_receiver[i]->owner:
arch_interrupt_receiver[i]->owner->unrun ()
2009-08-24 22:02:35 +03:00
#ifndef NDEBUG
2009-12-30 23:41:45 +02:00
panic_message (n, line, name, message)
2010-01-31 10:26:23 +02:00
// If a log capability is registered, run its owner.
2010-01-24 22:34:24 +02:00
#ifndef USE_SERIAL
2009-08-24 22:02:35 +03:00
if dbg_cap.valid () && dbg_cap->target->owner:
2009-07-23 13:06:32 +03:00
dbg_cap->target->owner->run ()
// Use the (now running) log thread to display the message.
2009-07-24 15:25:53 +03:00
// If no log capability is registered, the machine just hangs.
2010-01-24 22:34:24 +02:00
#else
2009-10-04 20:47:20 +03:00
arch_reboot ()
#endif
2009-08-24 22:02:35 +03:00
#endif
#ifndef NDEBUG
void dbg_send (unsigned num, unsigned bits):
2010-01-24 22:34:24 +02:00
kdebug ("Warning: ")
kdebug_num (num)
kdebug ('/')
kdebug_num (bits)
kdebug ('\n')
2009-08-24 22:02:35 +03:00
#endif
#else
void delay (unsigned ms):
for unsigned t = 0; t < 8000 * ms; ++t:
GPIO_GPDIR (0) = GPIO_GPDIR (0)
void set_leds (bool a, bool b):
gpio_as_output (GPIO_NUM_PORT, GPIO_NUM)
gpio_as_output (GPIO_CAPS_PORT, GPIO_CAPS)
if a:
GPIO_GPDR (GPIO_NUM_PORT) &= ~(1 << GPIO_NUM)
else:
GPIO_GPDR (GPIO_NUM_PORT) |= 1 << GPIO_NUM
if b:
GPIO_GPDR (GPIO_CAPS_PORT) &= ~(1 << GPIO_CAPS)
else:
GPIO_GPDR (GPIO_CAPS_PORT) |= 1 << GPIO_CAPS
2009-08-24 22:02:35 +03:00
void dbg_send (unsigned n, unsigned bits):
for unsigned i = 0; i < bits; ++i:
bool v = n & (1 << (bits - 1))
set_leds (v, !v)
delay (350)
set_leds (false, false)
delay (150)
n <<= 1
set_leds (true, true)
delay (50)
set_leds (false, false)
delay (50)
2010-01-16 17:13:54 +02:00
void panic_impl (unsigned n, const char *line, char const *name, char const *message):
unsigned epc
cp0_get (CP0_EPC, epc)
2009-08-24 22:02:35 +03:00
dbg_send (epc, 32)
while true:
2009-08-24 22:02:35 +03:00
dbg_send (n, 32)
#endif