Disable the debugging traces
[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 /*
26  * Instruction decoder, run ONE instruction
27  */
28 uint16_t avr_run_one(avr_t * avr);
29
30 /*
31  * These are for internal access to the stack (for interrupts)
32  */
33 uint16_t _avr_sp_get(avr_t * avr);
34 void _avr_sp_set(avr_t * avr, uint16_t sp);
35 void _avr_push16(avr_t * avr, uint16_t v);
36
37 #if CONFIG_SIMAVR_TRACE
38
39 /*
40  * Get a "pretty" register name
41  */
42 const char * avr_regname(uint8_t reg);
43
44 /* 
45  * DEBUG bits follow 
46  * These will diseapear when gdb arrives
47  */
48 void avr_dump_state(avr_t * avr);
49
50 #define DUMP_REG() { \
51                                 for (int i = 0; i < 32; i++) printf("%s=%02x%c", avr_regname(i), avr->data[i],i==15?'\n':' ');\
52                                 printf("\n");\
53                                 uint16_t y = avr->data[R_YL] | (avr->data[R_YH]<<8);\
54                                 for (int i = 0; i < 20; i++) printf("Y+%02d=%02x ", i, avr->data[y+i]);\
55                                 printf("\n");\
56                 }
57
58
59 #if AVR_STACK_WATCH
60 #define DUMP_STACK() \
61                 for (int i = avr->stack_frame_index; i; i--) {\
62                         int pci = i-1;\
63                         printf("\e[31m*** %04x: %-25s sp %04x\e[0m\n",\
64                                         avr->stack_frame[pci].pc, avr->codeline[avr->stack_frame[pci].pc>>1]->symbol, avr->stack_frame[pci].sp);\
65                 }
66 #else
67 #define DUMP_STACK()
68 #endif
69
70 #define CRASH()  {\
71                 DUMP_REG();\
72                 printf("*** CYCLE %lld PC %04x\n", avr->cycle, avr->pc);\
73                 for (int i = OLD_PC_SIZE-1; i > 0; i--) {\
74                         int pci = (avr->old_pci + i) & 0xf;\
75                         printf("\e[31m*** %04x: %-25s RESET -%d; sp %04x\e[0m\n",\
76                                         avr->old[pci].pc, avr->codeline[avr->old[pci].pc>>1]->symbol, OLD_PC_SIZE-i, avr->old[pci].sp);\
77                 }\
78                 printf("Stack Ptr %04x/%04x = %d \n", _avr_sp_get(avr), avr->ramend, avr->ramend - _avr_sp_get(avr));\
79                 DUMP_STACK();\
80                 avr_sadly_crashed(avr, 0);\
81         }
82 #else /* CONFIG_SIMAVR_TRACE */
83
84 #define CRASH() { \
85                 avr_sadly_crashed(avr, 0);\
86         }
87 #define DUMP_STACK()
88 #define DUMP_REG();
89
90 #endif 
91
92 #endif /* SIM_CORE_H_ */