2017-05-01 13:39:55 +00:00
|
|
|
#include "include/regs.h"
|
2017-04-30 19:15:41 +00:00
|
|
|
#include <base.hpp>
|
2017-07-29 08:53:39 +00:00
|
|
|
#include <irq.hpp>
|
2017-04-30 19:15:41 +00:00
|
|
|
void print_regdump(cpu_state *state) {
|
|
|
|
(*out << "r0: ").puti(state->r0);
|
|
|
|
(*out << " r1: ").puti(state->r1);
|
|
|
|
(*out << " r2: ").puti(state->r2);
|
|
|
|
(*out << " r3: ").puti(state->r3);
|
|
|
|
(*out << " r4: ").puti(state->r4);
|
|
|
|
(*out << " r5: ").puti(state->r5);
|
2017-05-01 13:39:55 +00:00
|
|
|
(*out << " r6: ").puti(state->r6);
|
|
|
|
(*out << " r7: ").puti(state->r7);
|
|
|
|
(*out << " r8: ").puti(state->r8);
|
|
|
|
(*out << " r9: ").puti(state->r9);
|
|
|
|
(*out << " r10: ").puti(state->r10);
|
|
|
|
(*out << " r11: ").puti(state->r11);
|
|
|
|
(*out << " r12: ").puti(state->r12);
|
|
|
|
(*out << " pc: ").puti(state->pc);
|
2017-05-20 20:04:22 +00:00
|
|
|
(*out << " cpsr: ").puti(state->cpsr);
|
|
|
|
(*out << " sp: ").puti(state->sp);
|
|
|
|
(*out << " lr: ").puti(state->lr);
|
|
|
|
(*out << " returnAddr: ").puti(state->returnAddr);
|
2017-05-01 13:39:55 +00:00
|
|
|
*out << "\n";
|
|
|
|
}
|
2017-12-09 18:09:47 +00:00
|
|
|
extern "C" void panic2(const char *msg, cpu_state *state);
|
2017-05-01 13:39:55 +00:00
|
|
|
extern "C" cpu_state *handleINT(int number, cpu_state *state) {
|
|
|
|
*out << "Interrupt";
|
|
|
|
out->puti(number);
|
|
|
|
*out << " occurred!\n";
|
2017-07-29 08:53:39 +00:00
|
|
|
switch(number) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
if(state->cpsr & 0x20)
|
|
|
|
state->returnAddr -= 2;
|
|
|
|
else
|
|
|
|
state->returnAddr -= 4;
|
2017-05-01 13:39:55 +00:00
|
|
|
}
|
2017-07-29 08:53:39 +00:00
|
|
|
cpu_state *new_cpu = state;
|
|
|
|
switch(number) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
new_cpu = (cpu_state*)irqs->handleIRQ(new_cpu);
|
|
|
|
case 4:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic2("Unhandled CPU exception!", state);
|
2017-05-01 13:39:55 +00:00
|
|
|
}
|
2017-07-29 08:53:39 +00:00
|
|
|
return new_cpu;
|
2017-05-01 13:39:55 +00:00
|
|
|
}
|
2017-12-09 18:09:47 +00:00
|
|
|
extern "C" void panic2(const char *msg, cpu_state *state) {
|
2017-05-01 13:39:55 +00:00
|
|
|
out->setColor(Color::RED);
|
|
|
|
*out << "KERNEL PANIC: " << msg << "\n";
|
|
|
|
print_regdump(state);
|
|
|
|
for (;;)
|
|
|
|
;
|
2017-04-30 19:15:41 +00:00
|
|
|
}
|