1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-07-07 20:13:52 +03:00
iris/interrupts.ccp

127 lines
3.4 KiB
Plaintext
Raw Normal View History

2009-05-11 01:28:12 +03:00
#pypp 0
2009-05-22 23:48:49 +03:00
#define ARCH
2009-05-11 01:28:12 +03:00
#include "kernel.hh"
/// A TLB miss has occurred. This is the slow version. It is only used
/// when k0 or k1 is not 0, or when an error occurs.
/// Otherwise, the ultra-fast code in entry.S is used.
2009-05-23 21:55:31 +03:00
Thread *tlb_refill ():
//panic (0x88776655, "TLB refill")
if !directory:
panic (0x44449999, "No directory")
2009-05-23 21:55:31 +03:00
unsigned EntryHi
cp0_get (CP0_ENTRY_HI, EntryHi)
unsigned *t = directory[EntryHi >> 21]
if !t:
panic (0x99992222, "No page table")
// - 2 instead of - 1 means reset bit 0
unsigned idx = (EntryHi >> 12) & ((1 << 9) - 2)
cp0_set (CP0_ENTRY_LO0, t[idx])
cp0_set (CP0_ENTRY_LO1, t[idx + 1])
2009-05-22 23:48:49 +03:00
__asm__ volatile ("tlbwr")
2009-05-11 01:28:12 +03:00
return current
/// An interrupt which is not an exception has occurred.
2009-05-23 21:55:31 +03:00
Thread *interrupt ():
2009-05-25 01:31:35 +03:00
panic (0x88877722, "Interrupt")
2009-05-27 19:33:05 +03:00
unsigned cause, status
2009-05-22 23:48:49 +03:00
cp0_get (CP0_CAUSE, cause)
2009-05-27 19:33:05 +03:00
cp0_get (CP0_STATUS, status)
2009-05-20 23:07:56 +03:00
for unsigned i = 0; i < 8; ++i:
if cause & (1 << (i + 8)):
2009-05-27 19:33:05 +03:00
// Disable the interrupt while handling it.
status &= ~(1 << (i + 8))
// Send message to interrupt handler.
if arch_interrupt_receiver[i]:
unsigned data[4] = {0, 0, 0, 0}
Capability *cap[4] = {NULL, NULL, NULL, NULL}
bool copy[4] = {false, false, false, false}
arch_interrupt_receiver[i]->send_message (i, data, cap, copy)
2009-05-11 01:28:12 +03:00
return current
/// A general exception has occurred.
2009-05-23 21:55:31 +03:00
Thread *exception ():
2009-05-20 23:07:56 +03:00
unsigned cause
2009-05-23 21:55:31 +03:00
cp0_get (CP0_CAUSE, cause)
2009-05-27 15:38:52 +03:00
//dbg_send (cause >> 2, 5)
2009-05-20 23:07:56 +03:00
switch (cause >> 2) & 0x1f:
case 0:
2009-05-25 01:31:35 +03:00
// Interrupt. This shouldn't happen, since CAUSE[IV] == 1.
panic (0x11223344, "Interrupt on exception vector.")
2009-05-20 23:07:56 +03:00
case 1:
// TLB modification.
2009-05-22 23:48:49 +03:00
panic (0x21223344, "TLB modification.")
2009-05-20 23:07:56 +03:00
case 2:
// TLB load or instruction fetch.
2009-05-22 23:48:49 +03:00
panic (0x31223344, "TLB load or instruction fetch.")
2009-05-20 23:07:56 +03:00
case 3:
// TLB store.
2009-05-22 23:48:49 +03:00
panic (0x41223344, "TLB store.")
2009-05-20 23:07:56 +03:00
case 4:
// Address error load or instruction fetch.
2009-05-22 23:48:49 +03:00
panic (0x51223344, "Address error load or instruction fetch.")
2009-05-20 23:07:56 +03:00
case 5:
// Address error store.
2009-05-22 23:48:49 +03:00
panic (0x61223344, "Address error store.")
2009-05-20 23:07:56 +03:00
case 6:
// Bus error instruction fetch.
2009-05-22 23:48:49 +03:00
panic (0x71223344, "Bus error instruction fetch.")
2009-05-20 23:07:56 +03:00
case 7:
// Bus error load or store.
2009-05-22 23:48:49 +03:00
panic (0x81223344, "Bus error load or store.")
2009-05-20 23:07:56 +03:00
case 8:
// Syscall.
2009-05-23 21:55:31 +03:00
arch_invoke ()
2009-05-27 15:38:52 +03:00
break
2009-05-20 23:07:56 +03:00
case 9:
// Breakpoint.
2009-05-22 23:48:49 +03:00
panic (0x91223344, "Breakpoint.")
2009-05-20 23:07:56 +03:00
case 10:
// Reserved instruction.
2009-05-22 23:48:49 +03:00
panic (0xa1223344, "Reserved instruction.")
2009-05-20 23:07:56 +03:00
case 11:
// Coprocessor unusable.
2009-05-22 23:48:49 +03:00
panic (0xb1223344, "Coprocessor unusable.")
2009-05-20 23:07:56 +03:00
case 12:
// Arithmetic overflow.
2009-05-22 23:48:49 +03:00
panic (0xc1223344, "Arithmetic overflow.")
2009-05-20 23:07:56 +03:00
case 13:
// Trap.
2009-05-22 23:48:49 +03:00
panic (0xe1223344, "Trap.")
2009-05-20 23:07:56 +03:00
case 15:
// Floating point exception.
2009-05-22 23:48:49 +03:00
panic (0xf1223344, "Floating point exception.")
2009-05-20 23:07:56 +03:00
case 23:
// Reference to WatchHi/WatchLo address.
2009-05-22 23:48:49 +03:00
panic (0xf2223344, "Reference to WatchHi/WatchLo address.")
2009-05-20 23:07:56 +03:00
case 24:
// Machine check.
2009-05-22 23:48:49 +03:00
panic (0xf3223344, "Machine check.")
2009-05-20 23:07:56 +03:00
case 30:
// Cache error (EJTAG only).
2009-05-22 23:48:49 +03:00
panic (0xf4223344, "Cache error (EJTAG only).")
2009-05-20 23:07:56 +03:00
case 14:
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
case 22:
case 25:
case 26:
case 27:
case 28:
case 29:
case 31:
// Reserved.
2009-05-23 21:55:31 +03:00
panic (0xf5223344, "Reserved exception code")
default:
panic (0xf6223344, "Impossible exception code")
2009-05-11 01:28:12 +03:00
return current
/// There's a cache error. Big trouble. Probably not worth trying to recover.
2009-05-23 21:55:31 +03:00
Thread *cache_error ():
2009-05-11 01:28:12 +03:00
panic (0x33333333, "cache error")
return current