1 |
dpavlin |
24 |
/* |
2 |
|
|
* Copyright (C) 2006 Anders Gavare. All rights reserved. |
3 |
|
|
* |
4 |
|
|
* Redistribution and use in source and binary forms, with or without |
5 |
|
|
* modification, are permitted provided that the following conditions are met: |
6 |
|
|
* |
7 |
|
|
* 1. Redistributions of source code must retain the above copyright |
8 |
|
|
* notice, this list of conditions and the following disclaimer. |
9 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
10 |
|
|
* notice, this list of conditions and the following disclaimer in the |
11 |
|
|
* documentation and/or other materials provided with the distribution. |
12 |
|
|
* 3. The name of the author may not be used to endorse or promote products |
13 |
|
|
* derived from this software without specific prior written permission. |
14 |
|
|
* |
15 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
16 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
19 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
20 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
21 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
22 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
23 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
24 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 |
|
|
* SUCH DAMAGE. |
26 |
|
|
* |
27 |
|
|
* |
28 |
|
|
* $Id: dev_avr.c,v 1.4 2006/03/05 16:20:24 debug Exp $ |
29 |
|
|
* |
30 |
|
|
* AVR I/O and register area. |
31 |
|
|
* |
32 |
|
|
* NOTE: The dyntrans system usually translates in/out instructions so that |
33 |
|
|
* cpu->cd.avr.xxx is accessed directly (where xxx is the right i/o register). |
34 |
|
|
* This device is only here in case these addresses are reached using load/ |
35 |
|
|
* stores to low memory addresses. |
36 |
|
|
*/ |
37 |
|
|
|
38 |
|
|
#include <stdio.h> |
39 |
|
|
#include <stdlib.h> |
40 |
|
|
#include <string.h> |
41 |
|
|
|
42 |
|
|
#include "cpu.h" |
43 |
|
|
#include "device.h" |
44 |
|
|
#include "devices.h" |
45 |
|
|
#include "machine.h" |
46 |
|
|
#include "memory.h" |
47 |
|
|
#include "misc.h" |
48 |
|
|
|
49 |
|
|
|
50 |
|
|
/* #define debug fatal */ |
51 |
|
|
|
52 |
|
|
|
53 |
|
|
struct avr_data { |
54 |
|
|
int dummy; |
55 |
|
|
}; |
56 |
|
|
|
57 |
|
|
|
58 |
|
|
DEVICE_ACCESS(avr) |
59 |
|
|
{ |
60 |
|
|
uint64_t idata = 0, odata = 0; |
61 |
|
|
/* struct avr_data *d = extra; */ |
62 |
|
|
|
63 |
|
|
if (writeflag == MEM_WRITE) |
64 |
|
|
idata = memory_readmax64(cpu, data, len); |
65 |
|
|
|
66 |
|
|
switch (relative_addr) { |
67 |
|
|
|
68 |
|
|
case 0x11: /* ddrd */ |
69 |
|
|
if (writeflag == MEM_WRITE) |
70 |
|
|
cpu->cd.avr.ddrd = idata; |
71 |
|
|
else |
72 |
|
|
odata = cpu->cd.avr.ddrd; |
73 |
|
|
break; |
74 |
|
|
|
75 |
|
|
case 0x12: /* portd */ |
76 |
|
|
if (writeflag == MEM_WRITE) |
77 |
|
|
cpu->cd.avr.portd_write = idata; |
78 |
|
|
else |
79 |
|
|
odata = cpu->cd.avr.portd_read; |
80 |
|
|
break; |
81 |
|
|
|
82 |
|
|
case 0x14: /* ddrc */ |
83 |
|
|
if (writeflag == MEM_WRITE) |
84 |
|
|
cpu->cd.avr.ddrc = idata; |
85 |
|
|
else |
86 |
|
|
odata = cpu->cd.avr.ddrc; |
87 |
|
|
break; |
88 |
|
|
|
89 |
|
|
case 0x15: /* portc */ |
90 |
|
|
if (writeflag == MEM_WRITE) |
91 |
|
|
cpu->cd.avr.portc_write = idata; |
92 |
|
|
else |
93 |
|
|
odata = cpu->cd.avr.portc_read; |
94 |
|
|
break; |
95 |
|
|
|
96 |
|
|
case 0x17: /* ddrb */ |
97 |
|
|
if (writeflag == MEM_WRITE) |
98 |
|
|
cpu->cd.avr.ddrb = idata; |
99 |
|
|
else |
100 |
|
|
odata = cpu->cd.avr.ddrb; |
101 |
|
|
break; |
102 |
|
|
|
103 |
|
|
case 0x1a: /* ddrc */ |
104 |
|
|
if (writeflag == MEM_WRITE) |
105 |
|
|
cpu->cd.avr.ddra = idata; |
106 |
|
|
else |
107 |
|
|
odata = cpu->cd.avr.ddra; |
108 |
|
|
break; |
109 |
|
|
|
110 |
|
|
case 0x3d: /* spl */ |
111 |
|
|
if (writeflag == MEM_WRITE) { |
112 |
|
|
cpu->cd.avr.sp &= 0xff00; |
113 |
|
|
cpu->cd.avr.sp |= (idata & 0xff); |
114 |
|
|
} else { |
115 |
|
|
odata = cpu->cd.avr.sp & 0xff; |
116 |
|
|
} |
117 |
|
|
break; |
118 |
|
|
|
119 |
|
|
case 0x3e: /* sph */ |
120 |
|
|
if (writeflag == MEM_WRITE) { |
121 |
|
|
cpu->cd.avr.sp &= 0xff; |
122 |
|
|
cpu->cd.avr.sp |= ((idata & 0xff) << 8); |
123 |
|
|
} else { |
124 |
|
|
odata = (cpu->cd.avr.sp >> 8) & 0xff; |
125 |
|
|
} |
126 |
|
|
break; |
127 |
|
|
|
128 |
|
|
default:debug("AVR: addr=0x%02x, len=%i, idata=%i\n", |
129 |
|
|
(int)relative_addr, (int)len, (int)idata); |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
if (writeflag == MEM_READ) |
133 |
|
|
memory_writemax64(cpu, data, len, odata); |
134 |
|
|
|
135 |
|
|
return 1; |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
|
139 |
|
|
DEVINIT(avr) |
140 |
|
|
{ |
141 |
|
|
struct avr_data *d; |
142 |
|
|
d = malloc(sizeof(struct avr_data)); |
143 |
|
|
if (d == NULL) { |
144 |
|
|
fprintf(stderr, "out of memory\n"); |
145 |
|
|
exit(1); |
146 |
|
|
} |
147 |
|
|
memset(d, 0, sizeof(struct avr_data)); |
148 |
|
|
|
149 |
|
|
memory_device_register(devinit->machine->memory, devinit->name, |
150 |
|
|
devinit->addr, 0x60, dev_avr_access, d, DM_DEFAULT, NULL); |
151 |
|
|
|
152 |
|
|
return 1; |
153 |
|
|
} |
154 |
|
|
|