1
/***********************************************************************
3
* avra - Assembler for the Atmel AVR microcontroller series
5
* Copyright (C) 1998-2004 Jon Anders Haugum, Tobias Weber
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; see the file COPYING. If not, write to
19
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
23
* Authors of avra can be reached at:
24
* email: jonah@omegav.ntnu.no, tobiw@suprafluid.com
25
* www: http://sourceforge.net/projects/avra
29
* Added ATtiny26 to struct device device_list[].
30
* Updated FLASH memory size for other ATtiny parts.
31
* ATtiny10, 11, 12, 15 Flash s/b 512 words.
32
* ATtiny 28, 22 Flash s/b 1024 words.
37
* Added ATtiny13 and ATtiny2313 to struct device device_list[].
42
* Added ATmega48, ATmega88 and ATmega168 to struct device device_list[].
53
#define DEV_VAR "__DEVICE__" // Device var name
54
#define FLASH_VAR "__FLASH_SIZE__" // Flash size var name
55
#define EEPROM_VAR "__EEPROM_SIZE__" // EEPROM size var name
56
#define RAM_VAR "__RAM_SIZE__" // RAM size var name
57
#define DEV_PREFIX "__" // Device name prefix
58
#define DEV_SUFFIX "__" // Device name suffix
59
#define DEF_DEV_NAME "DEFAULT" // Default device name (without prefix/suffix)
60
#define MAX_DEV_NAME 32 // Max device name length
62
// Name, Flash, RAM, EEPROM, flags
63
// Name, Flash(words), RAM, EEPROM, flags
64
struct device device_list[] =
66
{ NULL, 4194304, 8388608, 65536, 0}, // Total instructions: 137
67
{"AT90S1200", 512, 0, 64, DF_NO_MUL|DF_NO_JMP|DF_TINY1X|DF_NO_XREG|DF_NO_YREG|DF_NO_LPM|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP}, // 137 - MUL(6) - JMP(2) - TINY(10)
68
{"ATtiny10", 512, 0, 0, DF_NO_MUL|DF_NO_JMP|DF_TINY1X|DF_NO_XREG|DF_NO_YREG|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
69
{"ATtiny11", 512, 0, 0, DF_NO_MUL|DF_NO_JMP|DF_TINY1X|DF_NO_XREG|DF_NO_YREG|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
70
{"ATtiny12", 512, 0, 64, DF_NO_MUL|DF_NO_JMP|DF_TINY1X|DF_NO_XREG|DF_NO_YREG|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
71
{"ATtiny13", 512, 64, 64, DF_NO_MUL|DF_NO_JMP|DF_NO_ELPM|DF_NO_ESPM|DF_NO_EICALL|DF_NO_EIJMP},
72
{"ATtiny15", 512, 0, 64, DF_NO_MUL|DF_NO_JMP|DF_TINY1X|DF_NO_XREG|DF_NO_YREG|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
73
{"ATtiny28", 1024, 0, 0, DF_NO_MUL|DF_NO_JMP|DF_TINY1X|DF_NO_XREG|DF_NO_YREG|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
74
{"ATtiny22", 1024, 128, 128, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
75
{"ATtiny26", 1024, 128, 128, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
76
{"ATtiny2313", 1024, 128, 128, DF_NO_MUL|DF_NO_JMP|DF_NO_ELPM|DF_NO_ESPM|DF_NO_EICALL|DF_NO_EIJMP},
77
{"AT90S2313", 1024, 128, 128, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
78
{"AT90S2323", 1024, 128, 128, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
79
{"AT90S2333", 1024, 128, 128, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
80
{"AT90S2343", 1024, 128, 128, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
81
{"AT90S4414", 2048, 256, 256, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
82
{"AT90S4433", 2048, 128, 256, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
83
{"AT90S4434", 2048, 256, 256, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
84
{"AT90S8515", 4096, 512, 512, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP}, // 137 - MUL(6) - JMP(2) - LPM_X(2) - ELPM(3) - SPM - ESPM - MOVW - BREAK - EICALL - EIJMP = 118
85
{"AT90C8534", 4096, 256, 512, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
86
{"AT90S8535", 4096, 512, 512, DF_NO_MUL|DF_NO_JMP|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
87
{"ATmega8", 4096, 1024, 512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
88
{"ATmega161", 8192, 1024, 512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
89
{"ATmega162", 8192, 1024, 512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
90
{"ATmega163", 8192, 1024, 512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
91
{"ATmega16", 8192, 1024, 512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
92
{"ATmega323", 16384, 2048, 1024, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM}, // 137 - EICALL - EIJMP - ELPM(3) - ESPM = 131 (Data sheet says 130 but it's wrong)
93
{"ATmega32", 16384, 2048, 1024, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
94
{"ATmega603", 32768, 4096, 2048, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_MUL|DF_NO_MOVW|DF_NO_LPM_X|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_BREAK},
95
{"ATmega103", 65536, 4096, 4096, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_MUL|DF_NO_MOVW|DF_NO_LPM_X|DF_NO_ELPM_X|DF_NO_SPM|DF_NO_ESPM|DF_NO_BREAK}, // 137 - EICALL - EIJMP - MUL(6) - MOVW - LPM_X(2) - ELPM_X(2) - SPM - ESPM - BREAK = 121
96
{"ATmega104", 65536, 4096, 4096, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ESPM}, // Old name for mega128
97
{"ATmega128", 65536, 4096, 4096, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ESPM}, // 137 - EICALL - EIJMP - ESPM = 134 (Data sheet says 133 but it's wrong)
98
{"AT94K", 8192, 16384, 0, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_BREAK}, // 137 - EICALL - EIJMP - ELPM(3) - SPM - ESPM - BREAK = 129
99
{"ATmega48", 2048, 512, 256, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
100
{"ATmega88", 4096, 1024, 512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
101
{"ATmega168", 8192, 1024, 512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
105
static int LastDevice=0;
107
static int def_var(struct prog_info *pi, char *name, int value)
111
for(label = pi->first_variable; label; label = label->next)
112
if(!nocase_strcmp(label->name, name)) {
113
label->value = value;
116
label = malloc(sizeof(struct label));
118
print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL);
122
if(pi->last_variable)
123
pi->last_variable->next = label;
125
pi->first_variable = label;
126
pi->last_variable = label;
127
label->name = malloc(strlen(name) + 1);
129
print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL);
132
strcpy(label->name, name);
133
label->value = value;
137
/*********************************************/
138
/* Define vars for device in LastDevice */
139
/*********************************************/
141
static void def_dev(struct prog_info *pi)
143
def_var(pi,DEV_VAR,LastDevice);
144
def_var(pi,FLASH_VAR,device_list[LastDevice].flash_size);
145
def_var(pi,EEPROM_VAR,device_list[LastDevice].eeprom_size);
146
def_var(pi,RAM_VAR,device_list[LastDevice].ram_size);
149
struct device *get_device(struct prog_info *pi, char *name)
156
return(&device_list[0]);
158
while(device_list[i].name) {
159
if(!nocase_strcmp(name, device_list[i].name)) {
162
return(&device_list[i]);
170
static int def_const(struct prog_info *pi, const char *name, int value)
174
label = malloc(sizeof(struct label));
176
print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL);
180
if(pi->last_constant)
181
pi->last_constant->next = label;
183
pi->first_constant = label;
184
pi->last_constant = label;
185
label->name = malloc(strlen(name) + 1);
187
print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL);
190
strcpy(label->name, name);
191
label->value = value;
195
// Pre-define devices
196
void predef_dev(struct prog_info *pi)
199
char temp[MAX_DEV_NAME+1];
203
for (i=0;(!i)||(device_list[i].name);i++) {
204
strncpy(temp,DEV_PREFIX,MAX_DEV_NAME);
205
if (!i) strncat(temp,DEF_DEV_NAME,MAX_DEV_NAME);
206
else strncat(temp,device_list[i].name,MAX_DEV_NAME);
207
strncat(temp,DEV_SUFFIX,MAX_DEV_NAME);
208
def_const(pi,temp,i);
215
printf("Device name | Flash size | RAM size | EEPROM size | Supported\n"
216
" | (words) | (bytes) | (bytes) | instructions\n"
217
"------------+------------+----------+-------------+--------------\n"
218
" (default) | %7d | %7d | %5d | %3d\n",
219
device_list[0].flash_size, device_list[0].ram_size, device_list[0].eeprom_size,
220
count_supported_instructions(device_list[0].flag));
221
while(device_list[i].name) {
222
printf(" %-10s | %7d | %7d | %5d | %3d\n", device_list[i].name,
223
device_list[i].flash_size, device_list[i].ram_size,
224
device_list[i].eeprom_size, count_supported_instructions(device_list[i].flag));
229
/* end of device.c */