4 Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
6 This file is part of simavr.
8 simavr is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 simavr is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with simavr. If not, see <http://www.gnu.org/licenses/>.
30 * Instruction decoder, run ONE instruction
32 avr_flashaddr_t avr_run_one(avr_t * avr);
35 * These are for internal access to the stack (for interrupts)
37 uint16_t _avr_sp_get(avr_t * avr);
38 void _avr_sp_set(avr_t * avr, uint16_t sp);
39 void _avr_push16(avr_t * avr, uint16_t v);
41 #if CONFIG_SIMAVR_TRACE
44 * Get a "pretty" register name
46 const char * avr_regname(uint8_t reg);
50 * These will disappear when gdb arrives
52 void avr_dump_state(avr_t * avr);
54 #define DUMP_REG() { \
55 for (int i = 0; i < 32; i++) printf("%s=%02x%c", avr_regname(i), avr->data[i],i==15?'\n':' ');\
57 uint16_t y = avr->data[R_YL] | (avr->data[R_YH]<<8);\
58 for (int i = 0; i < 20; i++) printf("Y+%02d=%02x ", i, avr->data[y+i]);\
64 #define DUMP_STACK() \
65 for (int i = avr->trace_data->stack_frame_index; i; i--) {\
67 printf("\e[31m*** %04x: %-25s sp %04x\e[0m\n",\
68 avr->trace_data->stack_frame[pci].pc, \
69 avr->trace_data->codeline ? avr->trace_data->codeline[avr->trace_data->stack_frame[pci].pc>>1]->symbol : "unknown", \
70 avr->trace_data->stack_frame[pci].sp);\
78 printf("*** CYCLE %" PRI_avr_cycle_count "PC %04x\n", avr->cycle, avr->pc);\
79 for (int i = OLD_PC_SIZE-1; i > 0; i--) {\
80 int pci = (avr->trace_data->old_pci + i) & 0xf;\
81 printf("\e[31m*** %04x: %-25s RESET -%d; sp %04x\e[0m\n",\
82 avr->trace_data->old[pci].pc, avr->trace_data->codeline ? avr->trace_data->codeline[avr->trace_data->old[pci].pc>>1]->symbol : "unknown", OLD_PC_SIZE-i, avr->trace_data->old[pci].sp);\
84 printf("Stack Ptr %04x/%04x = %d \n", _avr_sp_get(avr), avr->ramend, avr->ramend - _avr_sp_get(avr));\
86 avr_sadly_crashed(avr, 0);\
88 #else /* CONFIG_SIMAVR_TRACE */
91 avr_sadly_crashed(avr, 0);\
102 #endif /* SIM_CORE_H_ */