2015-06-28 08:10:45 +08:00
|
|
|
// This is free and unencumbered software released into the public domain.
|
2015-07-02 16:49:35 +08:00
|
|
|
//
|
2015-06-28 08:10:45 +08:00
|
|
|
// Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
|
|
// distribute this software, either in source code form or as a compiled
|
|
|
|
// binary, for any purpose, commercial or non-commercial, and by any
|
|
|
|
// means.
|
2015-06-27 04:02:22 +08:00
|
|
|
|
|
|
|
#include "firmware.h"
|
|
|
|
|
|
|
|
uint32_t *irq(uint32_t *regs, uint32_t irqs)
|
|
|
|
{
|
2015-07-02 16:46:21 +08:00
|
|
|
static unsigned int ext_irq_4_count = 0;
|
|
|
|
static unsigned int ext_irq_5_count = 0;
|
|
|
|
static unsigned int timer_irq_count = 0;
|
2015-06-27 04:02:22 +08:00
|
|
|
|
|
|
|
if ((irqs & (1<<4)) != 0) {
|
|
|
|
ext_irq_4_count++;
|
|
|
|
// print_str("[EXT-IRQ-4]");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((irqs & (1<<5)) != 0) {
|
|
|
|
ext_irq_5_count++;
|
|
|
|
// print_str("[EXT-IRQ-5]");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((irqs & 1) != 0) {
|
|
|
|
timer_irq_count++;
|
|
|
|
// print_str("[TIMER-IRQ]");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((irqs & 6) != 0)
|
|
|
|
{
|
2016-05-31 22:57:45 +08:00
|
|
|
uint32_t pc = regs[0] - 2;
|
2015-11-19 11:02:00 +08:00
|
|
|
uint16_t *instr_hwords = (uint16_t*)pc;
|
2016-05-31 22:57:45 +08:00
|
|
|
uint32_t instr = *(uint16_t*)pc;
|
|
|
|
|
|
|
|
if ((*instr_hwords & 3) == 3) {
|
|
|
|
pc -= 2;
|
|
|
|
instr = (instr << 16) | *(uint16_t*)pc;
|
|
|
|
} else {
|
|
|
|
int cnt_3 = 0;
|
|
|
|
while ((*(--instr_hwords) & 3) == 3 && cnt_3 < 20) cnt_3++;
|
|
|
|
if ((cnt_3 & 1) != 0) {
|
|
|
|
pc -= 2;
|
|
|
|
instr = (instr << 16) | *(uint16_t*)pc;
|
|
|
|
}
|
|
|
|
}
|
2015-06-27 04:02:22 +08:00
|
|
|
|
|
|
|
print_str("\n");
|
|
|
|
print_str("------------------------------------------------------------\n");
|
|
|
|
|
|
|
|
if ((irqs & 2) != 0) {
|
2016-05-31 22:57:45 +08:00
|
|
|
if (instr == 0x00100073 || instr == 0x9002) {
|
2015-06-27 04:02:22 +08:00
|
|
|
print_str("SBREAK instruction at 0x");
|
2015-11-19 21:01:16 +08:00
|
|
|
print_hex(pc, 8);
|
2015-06-27 04:02:22 +08:00
|
|
|
print_str("\n");
|
|
|
|
} else {
|
|
|
|
print_str("Illegal Instruction at 0x");
|
2015-11-19 21:01:16 +08:00
|
|
|
print_hex(pc, 8);
|
2015-06-27 04:02:22 +08:00
|
|
|
print_str(": 0x");
|
2015-11-19 21:01:16 +08:00
|
|
|
print_hex(instr, ((instr & 3) == 3) ? 8 : 4);
|
2015-06-27 04:02:22 +08:00
|
|
|
print_str("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((irqs & 4) != 0) {
|
|
|
|
print_str("Bus error in Instruction at 0x");
|
2015-11-19 21:01:16 +08:00
|
|
|
print_hex(pc, 8);
|
2015-06-27 04:02:22 +08:00
|
|
|
print_str(": 0x");
|
2015-11-19 21:01:16 +08:00
|
|
|
print_hex(instr, ((instr & 3) == 3) ? 8 : 4);
|
2015-06-27 04:02:22 +08:00
|
|
|
print_str("\n");
|
|
|
|
}
|
|
|
|
|
2015-07-04 17:47:43 +08:00
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
for (int k = 0; k < 4; k++)
|
2015-06-27 04:02:22 +08:00
|
|
|
{
|
|
|
|
int r = i + k*8;
|
|
|
|
|
|
|
|
if (r == 0) {
|
|
|
|
print_str("pc ");
|
|
|
|
} else
|
|
|
|
if (r < 10) {
|
|
|
|
print_chr('x');
|
|
|
|
print_chr('0' + r);
|
|
|
|
print_chr(' ');
|
|
|
|
print_chr(' ');
|
|
|
|
} else
|
|
|
|
if (r < 20) {
|
|
|
|
print_chr('x');
|
|
|
|
print_chr('1');
|
|
|
|
print_chr('0' + r - 10);
|
|
|
|
print_chr(' ');
|
|
|
|
} else
|
|
|
|
if (r < 30) {
|
|
|
|
print_chr('x');
|
|
|
|
print_chr('2');
|
|
|
|
print_chr('0' + r - 20);
|
|
|
|
print_chr(' ');
|
|
|
|
} else {
|
|
|
|
print_chr('x');
|
|
|
|
print_chr('3');
|
|
|
|
print_chr('0' + r - 30);
|
|
|
|
print_chr(' ');
|
|
|
|
}
|
|
|
|
|
2015-11-19 21:01:16 +08:00
|
|
|
print_hex(regs[r], 8);
|
2015-06-27 04:02:22 +08:00
|
|
|
print_str(k == 3 ? "\n" : " ");
|
|
|
|
}
|
|
|
|
|
|
|
|
print_str("------------------------------------------------------------\n");
|
|
|
|
|
|
|
|
print_str("Number of fast external IRQs counted: ");
|
|
|
|
print_dec(ext_irq_4_count);
|
|
|
|
print_str("\n");
|
|
|
|
|
|
|
|
print_str("Number of slow external IRQs counted: ");
|
|
|
|
print_dec(ext_irq_5_count);
|
|
|
|
print_str("\n");
|
|
|
|
|
|
|
|
print_str("Number of timer IRQs counted: ");
|
|
|
|
print_dec(timer_irq_count);
|
|
|
|
print_str("\n");
|
|
|
|
|
2015-07-04 17:47:19 +08:00
|
|
|
__asm__ volatile ("sbreak");
|
2015-06-27 04:02:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return regs;
|
|
|
|
}
|
|
|
|
|