2 * Copyright © 2008 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 static uint8_t save_acc[] = {
26 static uint8_t save_sfr[] = {
28 #define SAVE_SFR_ADDR 2
38 static struct sfr_state sfrs[CC_STATE_NSFR] = {
39 { SFR_DPL0, CC_STATE_DP, "dpl0" },
40 { SFR_DPH0, CC_STATE_DP, "dph0" },
41 { SFR_DPL1, CC_STATE_DP, "dpl1" },
42 { SFR_DPH1, CC_STATE_DP, "dph1" },
43 { PSW(0), CC_STATE_PSW, "psw" },
47 ccdbg_state_save(struct ccdbg *dbg, struct ccstate *state, unsigned int mask)
52 if (mask & CC_STATE_ACC)
53 state->acc = ccdbg_execute(dbg, save_acc);
54 for (i = 0; i < CC_STATE_NSFR; i++) {
55 if (sfrs[i].mask & mask) {
56 save_sfr[SAVE_SFR_ADDR] = sfrs[i].address;
57 state->sfr[i] = ccdbg_execute(dbg, save_sfr);
64 static uint8_t restore_sfr[] = {
65 3, MOV_direct_data, 0, 0,
66 #define RESTORE_SFR_ADDR 2
67 #define RESTORE_SFR_DATA 3
71 static uint8_t restore_acc[] = {
73 #define RESTORE_ACC_DATA 2
78 ccdbg_state_restore(struct ccdbg *dbg, struct ccstate *state)
81 for (i = CC_STATE_NSFR - 1; i >= 0; i--) {
82 if (sfrs[i].mask & state->mask) {
83 restore_sfr[RESTORE_SFR_ADDR] = sfrs[i].address;
84 restore_sfr[RESTORE_SFR_DATA] = state->sfr[i];
85 ccdbg_execute(dbg, restore_sfr);
88 if (state->mask & CC_STATE_ACC) {
89 restore_acc[RESTORE_ACC_DATA] = state->acc;
90 ccdbg_execute(dbg, restore_acc);
97 ccdbg_state_replace(uint16_t sfr_addr, uint8_t sfr, char *name,
98 uint16_t addr, uint8_t *bytes, int nbytes)
102 if (addr <= sfr_addr && sfr_addr < addr + nbytes) {
103 fprintf(stderr, "replacing %s at 0x%04x - read 0x%02x saved 0x%02x\n",
104 name, sfr_addr, bytes[sfr_addr - addr], sfr);
105 bytes[sfr_addr - addr] = sfr;
110 ccdbg_state_replace_xmem(struct ccdbg *dbg, struct ccstate *state,
111 uint16_t addr, uint8_t *bytes, int nbytes)
114 if (state->mask & CC_STATE_ACC)
115 ccdbg_state_replace(ACC(0), state->acc, "acc",
116 addr, bytes, nbytes);
117 for (i = 0; i < CC_STATE_NSFR; i++)
118 if (state->mask & sfrs[i].mask)
119 ccdbg_state_replace(sfrs[i].address, state->sfr[i],
120 sfrs[i].name, addr, bytes, nbytes);
124 ccdbg_state_replace_sfr(struct ccdbg *dbg, struct ccstate *state,
125 uint8_t addr, uint8_t *bytes, int nbytes)
127 ccdbg_state_replace_xmem(dbg, state, (uint16_t) addr + 0xdf00, bytes, nbytes);