-
Notifications
You must be signed in to change notification settings - Fork 2
/
interrupts.c
146 lines (132 loc) · 4.46 KB
/
interrupts.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
########################################################################
# This file is part of WRAMPmon, the WRAMP monitor programe.
#
# Copyright (C) 2019 The University of Waikato, Hamilton, New Zealand.
#
# 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 <https://www.gnu.org/licenses/>.
########################################################################
*/
#include "commands.h"
#include "utils.h"
extern breakpoint brk_point[MAX_BREAKPOINTS];
void handle_interrupt(unsigned int estat, unsigned int cctrl, unsigned int ear)
{
int i;
save_serial();
if (estat & 0x4000) { // break exception
// If we just did a single step
if (step_mode == true && step_break_addr == (ear - 1)) {
// Backup so that when we restart we execute this instruction
program_counter--;
if (step_break_mode == true) {
// Replace the breakpoint instruction
*(unsigned int *)cont_addr = BREAK_INSN;
}
// Replace the old instruction
*(unsigned int *)step_break_addr = step_old_insn;
step_mode = false;
if (cont_mode == true) {
cont_mode = false;
*(unsigned int *)cont_addr = BREAK_INSN;
enable_ints();
start_program(program_counter);
return; // redundant
}
// Display the instruction we have just executed
printf("EXECUTED: ");
printf("0x%05x ", step_insn_addr);
if (step_break_mode == true) {
for (i = 0 ; i < MAX_BREAKPOINTS ; i++) {
if (brk_point[i].addr == step_insn_addr) {
printf("%08x", brk_point[i].insn);
printf(" !BRK! ");
disassemble(brk_point[i].addr, brk_point[i].insn);
break;
}
}
if (i == MAX_BREAKPOINTS) {
printf("%08x", *(unsigned int *)step_insn_addr);
printf(" ");
disassemble(step_insn_addr, cont_insn);
}
}
else {
printf("%08x", *(unsigned int *)step_insn_addr);
printf(" ");
disassemble(step_insn_addr, *(unsigned int *)step_insn_addr);
}
printf("\n");
printf("NEXT INSN: ");
i = 0;
if (*(unsigned int *)program_counter == BREAK_INSN) {
for (i = 0 ; i < MAX_BREAKPOINTS ; i++) {
if (brk_point[i].addr == program_counter) {
printf("0x%05x %08x", brk_point[i].addr, brk_point[i].insn);
printf(" !BRK! ");
disassemble(brk_point[i].addr, brk_point[i].insn);
printf("\n");
break;
}
}
}
if (*(unsigned int *)program_counter != BREAK_INSN || i == MAX_BREAKPOINTS) {
printf("0x%05x %08x ", program_counter, *(unsigned int *)program_counter);
disassemble(program_counter, *(unsigned int *)program_counter);
printf("\n");
}
step_break_mode = false;
// Return and reenter the monitor
return;
}
// This exception has been caused by a break instruction
// We should check to see if it is one of our breakpoints
for (i = 0 ; i < MAX_BREAKPOINTS ; i++) {
if (brk_point[i].addr == (ear - 1)) {
program_counter--;
// Yep, this is one of ours.
printf("BREAKPOINT: ");
printf("0x%05x %08x", brk_point[i].addr, brk_point[i].insn);
printf(" !BRK! ");
disassemble(brk_point[i].addr, brk_point[i].insn);
printf("\n");
dump_regs();
return;
}
}
}
if (estat & 0x2000) { // syscall exception
// printf("Program completed.\n");
program_counter = program_start_addr;
return;
}
if (estat & 0x1000) { // gpf
printf("\nGPF: $ear = 0x%08x $estat = 0x%08x $cctrl = 0x%08x\n", ear, estat, cctrl);
dump_regs();
return;
}
if (estat & 0x8000) { // arithmetic
printf("\nARITHMETIC: $ear = 0x%08x $estat = 0x%08x $cctrl = 0x%08x\n", ear, estat, cctrl);
dump_regs();
return;
}
if (estat & 0x4000) { // unexpected breakpoint
printf("\nBREAK: $ear = 0x%08x $estat = 0x%08x $cctrl = 0x%08x\n", ear, estat, cctrl);
dump_regs();
return;
}
// Here we should really restore the serial port settings
printf("\nINTERRUPT: $ear = 0x%08x $estat = 0x%08x $cctrl = 0x%08x\n", ear, estat, cctrl);
dump_regs();
}