mirror of
git://projects.qi-hardware.com/iris.git
synced 2024-10-01 09:29:48 +03:00
129 lines
3.4 KiB
COBOL
129 lines
3.4 KiB
COBOL
#pypp 0
|
|
#define ARCH
|
|
#include "kernel.hh"
|
|
|
|
/// A TLB miss has occurred. This should eventually move to entry.S.
|
|
Thread *tlb_refill (Thread *current, unsigned EntryHi):
|
|
panic (0x88776655, "TLB refill")
|
|
Page *page0 = current->address_space->get_mapping (EntryHi & ~(1 << 12))
|
|
Page *page1 = current->address_space->get_mapping (EntryHi | (1 << 12))
|
|
if (!(EntryHi & (1 << 12)) && !page0) || ((EntryHi & (1 << 12)) && !page1):
|
|
panic (0x22222222, "no page mapped at requested address")
|
|
unsigned low0, low1
|
|
if page0:
|
|
low0 = (unsigned)page0->physical | 0x18 | 0x4 | 0x2
|
|
else
|
|
low0 = 0
|
|
if page1:
|
|
low1 = (unsigned)page1->physical | 0x18 | 0x4 | 0x2
|
|
else
|
|
low1 = 0
|
|
cp0_set (CP0_ENTRY_LO0, low0)
|
|
cp0_set (CP0_ENTRY_LO1, low1)
|
|
__asm__ volatile ("tlbwr")
|
|
return current
|
|
|
|
/// An interrupt which is not an exception has occurred.
|
|
Thread *interrupt (Thread *current):
|
|
unsigned cause
|
|
cp0_get (CP0_CAUSE, cause)
|
|
for unsigned i = 0; i < 8; ++i:
|
|
if cause & (1 << (i + 8)):
|
|
// TODO: Handle interrupt.
|
|
// Disable all interrupts which are not handled.
|
|
unsigned status
|
|
__asm__ volatile ("mfc0 %0, $12" : "=r"(status))
|
|
__asm__ volatile ("mfc0 %0, $13" : "=r"(cause))
|
|
status &= ~(cause & 0x0000ff00)
|
|
__asm__ volatile ("mtc0 %0, $12" :: "r"(status))
|
|
return current
|
|
|
|
/// A general exception has occurred.
|
|
Thread *exception (Thread *current):
|
|
unsigned cause
|
|
led (true, true, true)
|
|
__asm__ volatile ("mfc0 %0, $13" : "=r"(cause))
|
|
switch (cause >> 2) & 0x1f:
|
|
case 0:
|
|
// Interrupt.
|
|
panic (0x11223344, "Interrupt.")
|
|
case 1:
|
|
// TLB modification.
|
|
panic (0x21223344, "TLB modification.")
|
|
case 2:
|
|
unsigned a
|
|
cp0_get (CP0_EPC, a)
|
|
panic (a)
|
|
// TLB load or instruction fetch.
|
|
panic (0x31223344, "TLB load or instruction fetch.")
|
|
case 3:
|
|
// TLB store.
|
|
panic (0x41223344, "TLB store.")
|
|
case 4:
|
|
// Address error load or instruction fetch.
|
|
panic (0x51223344, "Address error load or instruction fetch.")
|
|
case 5:
|
|
// Address error store.
|
|
panic (0x61223344, "Address error store.")
|
|
case 6:
|
|
// Bus error instruction fetch.
|
|
panic (0x71223344, "Bus error instruction fetch.")
|
|
case 7:
|
|
// Bus error load or store.
|
|
panic (0x81223344, "Bus error load or store.")
|
|
case 8:
|
|
// Syscall.
|
|
// DEBUG: allow new exceptions.
|
|
//cp0_set (CP0_STATUS, 0x1000ff00)
|
|
Thread_arch_invoke ()
|
|
return current
|
|
case 9:
|
|
// Breakpoint.
|
|
panic (0x91223344, "Breakpoint.")
|
|
case 10:
|
|
// Reserved instruction.
|
|
panic (0xa1223344, "Reserved instruction.")
|
|
case 11:
|
|
// Coprocessor unusable.
|
|
panic (0xb1223344, "Coprocessor unusable.")
|
|
case 12:
|
|
// Arithmetic overflow.
|
|
panic (0xc1223344, "Arithmetic overflow.")
|
|
case 13:
|
|
// Trap.
|
|
panic (0xe1223344, "Trap.")
|
|
case 15:
|
|
// Floating point exception.
|
|
panic (0xf1223344, "Floating point exception.")
|
|
case 23:
|
|
// Reference to WatchHi/WatchLo address.
|
|
panic (0xf2223344, "Reference to WatchHi/WatchLo address.")
|
|
case 24:
|
|
// Machine check.
|
|
panic (0xf3223344, "Machine check.")
|
|
case 30:
|
|
// Cache error (EJTAG only).
|
|
panic (0xf4223344, "Cache error (EJTAG only).")
|
|
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.
|
|
panic (0xf5223344, "Reserved.")
|
|
return current
|
|
|
|
/// There's a cache error. Big trouble. Probably not worth trying to recover.
|
|
Thread *cache_error (Thread *current):
|
|
panic (0x33333333, "cache error")
|
|
return current
|