misc: Fixed a couple of typos in comments
[simavr] / simavr / sim / sim_core.h
1 /*
2         sim_core.h
3
4         Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
5
6         This file is part of simavr.
7
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.
12
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.
17
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/>.
20  */
21
22 #ifndef SIM_CORE_H_
23 #define SIM_CORE_H_
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 /*
30  * Instruction decoder, run ONE instruction
31  */
32 avr_flashaddr_t avr_run_one(avr_t * avr);
33
34 /*
35  * These are for internal access to the stack (for interrupts)
36  */
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);
40
41 #if CONFIG_SIMAVR_TRACE
42
43 /*
44  * Get a "pretty" register name
45  */
46 const char * avr_regname(uint8_t reg);
47
48 /* 
49  * DEBUG bits follow 
50  * These will disappear when gdb arrives
51  */
52 void avr_dump_state(avr_t * avr);
53
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':' ');\
56                                 printf("\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]);\
59                                 printf("\n");\
60                 }
61
62
63 #if AVR_STACK_WATCH
64 #define DUMP_STACK() \
65                 for (int i = avr->trace_data->stack_frame_index; i; i--) {\
66                         int pci = i-1;\
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);\
71                 }
72 #else
73 #define DUMP_STACK()
74 #endif
75
76 #define CRASH()  {\
77                 DUMP_REG();\
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);\
83                 }\
84                 printf("Stack Ptr %04x/%04x = %d \n", _avr_sp_get(avr), avr->ramend, avr->ramend - _avr_sp_get(avr));\
85                 DUMP_STACK();\
86                 avr_sadly_crashed(avr, 0);\
87         }
88 #else /* CONFIG_SIMAVR_TRACE */
89
90 #define CRASH() { \
91                 avr_sadly_crashed(avr, 0);\
92         }
93 #define DUMP_STACK()
94 #define DUMP_REG();
95
96 #endif 
97
98 #ifdef __cplusplus
99 };
100 #endif
101
102 #endif /* SIM_CORE_H_ */