1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-11-16 21:23:42 +02:00
iris/panic.ccp

166 lines
4.5 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
void dbg_log_char (unsigned ch):
while !(UART0_LSR & UARTLSR_TDRQ):
UART0_TDR = ch
#else
2009-07-23 13:06:32 +03:00
void dbg_log_char (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
void dbg_log (char const *str):
while *str:
dbg_log_char (*str++)
2009-09-01 20:00:46 +03:00
void dbg_log_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:
dbg_log_char (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-16 17:13:54 +02:00
static void panic_message (unsigned n, const char *line, char const *name, char const *message):
2010-01-17 11:01:42 +02:00
//unsigned addr
//cp0_get (CP0_BAD_V_ADDR, addr)
//unsigned de = addr >> 21
//unsigned te = (addr >> 12) & ((1 << 9) - 1)
//dbg_log_num ((unsigned)old_current->address_space->arch.directory[de]->page[te])
//dbg_log (":")
//dbg_log_num (old_current->address_space->arch.directory[de]->entrylo[te])
//dbg_log ("\n")
//__asm__ volatile ("tlbp")
//unsigned idx, hi
//cp0_get (CP0_INDEX, idx)
//dbg_log_num (idx)
//dbg_log (":")
//cp0_get (CP0_ENTRY_HI, hi)
//dbg_log_num (hi)
//dbg_log (":")
//unsigned lo
//cp0_get (CP0_ENTRY_LO0, lo)
//dbg_log_num (lo)
//dbg_log (":")
//cp0_get (CP0_ENTRY_LO1, lo)
//dbg_log_num (lo)
//dbg_log ("\n")
2009-12-30 23:41:45 +02:00
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 (':')
2010-01-16 17:13:54 +02:00
dbg_log (line)
2009-12-30 23:41:45 +02:00
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')
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-07-23 13:06:32 +03:00
// If a log capability is registered, run its owner.
2009-12-30 23:41:45 +02:00
panic_message (n, line, name, message)
2009-08-24 22:02:35 +03:00
if dbg_cap.valid () && dbg_cap->target->owner:
2009-09-30 00:48:33 +03:00
#ifndef USE_SERIAL
2009-07-23 13:06:32 +03:00
dbg_cap->target->owner->run ()
2009-09-30 00:48:33 +03:00
#endif
2009-07-23 13:06:32 +03:00
// 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.
2009-10-04 20:47:20 +03:00
#ifdef USE_SERIAL
arch_reboot ()
#endif
2009-08-24 22:02:35 +03:00
#endif
#ifndef NDEBUG
void dbg_send (unsigned num, unsigned bits):
dbg_log ("Warning: ")
dbg_log_num (num)
dbg_log_char ('/')
dbg_log_num (bits)
dbg_log_char ('\n')
#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