mirror of
git://projects.qi-hardware.com/iris.git
synced 2024-10-01 10:57:17 +03:00
72 lines
2.2 KiB
COBOL
72 lines
2.2 KiB
COBOL
#pypp 0
|
|
// 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/>.
|
|
|
|
#define ARCH
|
|
#include "kernel.hh"
|
|
|
|
void dbg_log_char (unsigned ch):
|
|
if !dbg_cap:
|
|
return
|
|
Capability::Context c
|
|
for unsigned i = 0; i < 4; ++i:
|
|
c.cap[i] = NULL
|
|
c.copy[i] = false
|
|
c.data[i] = 0
|
|
c.data[0] = ch
|
|
dbg_cap->invoke (&c)
|
|
if dbg_cap->target->owner:
|
|
current = dbg_cap->target->owner
|
|
|
|
void dbg_log (char const *str):
|
|
while *str:
|
|
dbg_log_char (*str++)
|
|
|
|
void dbg_send (unsigned code, unsigned bits):
|
|
if bits > 32:
|
|
bits = 32
|
|
char const *encode = "0123456789abcdef"
|
|
dbg_log_char ('[')
|
|
dbg_log_char (encode[(bits >> 4) & 0xf])
|
|
dbg_log_char (encode[bits & 0xf])
|
|
dbg_log_char (':')
|
|
for unsigned i = 0; i < 8; ++i:
|
|
dbg_log_char (encode[(code >> (4 * (7 - i))) & 0xf])
|
|
dbg_log_char (']')
|
|
return
|
|
|
|
void panic (unsigned n, char const *message):
|
|
Thread *who = current
|
|
// Stop all threads.
|
|
while first_scheduled:
|
|
first_scheduled->unrun ()
|
|
for Receiver *r = first_alarm; r; r = r->next_alarm:
|
|
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 ()
|
|
// If a log capability is registered, run its owner.
|
|
if dbg_cap && dbg_cap->target->owner:
|
|
dbg_cap->target->owner->run ()
|
|
// Use the (now running) log thread to display the message.
|
|
dbg_log ("Panic: ")
|
|
dbg_send (n)
|
|
dbg_log (message)
|
|
dbg_log_char ('\n')
|
|
// If no log capability is registered, the machine just hangs.
|