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.
22 * Read and write arbitrary memory through the debug port
25 #define MOV_dptr_data16 0x90
27 static uint8_t memory_init[] = {
28 3, MOV_dptr_data16, 0, 0,
34 #define MOV_a_data 0x74
35 #define MOVX_atdptr_a 0xf0
36 #define MOVX_a_atdptr 0xe0
39 static uint8_t write8[] = {
47 static uint8_t read8[] = {
54 ccdbg_write_memory(struct ccdbg *dbg, uint16_t addr, uint8_t *bytes, int nbytes)
56 memory_init[HIGH_START] = addr >> 8;
57 memory_init[LOW_START] = addr;
58 (void) ccdbg_execute(dbg, memory_init);
59 while (nbytes-- > 0) {
60 write8[DATA_BYTE] = *bytes++;
61 ccdbg_execute(dbg, write8);
67 ccdbg_read_memory(struct ccdbg *dbg, uint16_t addr, uint8_t *bytes, int nbytes)
69 memory_init[HIGH_START] = addr >> 8;
70 memory_init[LOW_START] = addr;
71 (void) ccdbg_execute(dbg, memory_init);
73 *bytes++ = ccdbg_execute(dbg, read8);
78 ccdbg_write_hex(struct ccdbg *dbg, struct hex_file *hex)
81 struct hex_record *record;
83 for (i = 0; i < hex->nrecord; i++) {
84 record = hex->records[i];
85 if (record->type == HEX_RECORD_EOF)
87 printf("Write %d bytes at 0x%04x\n",
88 record->length, record->address);
89 ccdbg_write_memory(dbg, record->address,
90 record->data, record->length);