Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /***********************************************************************
  2.  *
  3.  *  avra - Assembler for the Atmel AVR microcontroller series
  4.  *
  5.  *  Copyright (C) 1998-2010 Jon Anders Haugum, Tobias Weber, Jerry Jacobs
  6.  *
  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.
  11.  *
  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.
  16.  *
  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.
  21.  *
  22.  *
  23.  *  Authors of avra can be reached at:
  24.  *     email: jonah@omegav.ntnu.no, tobiw@suprafluid.com
  25.  *     www: http://sourceforge.net/projects/avra
  26.  *
  27.  */
  28.  
  29.  
  30. #include <stdlib.h>
  31. #include <string.h>
  32.  
  33. #include "misc.h"
  34. #include "avra.h"
  35. #include "device.h"
  36.  
  37. #define DEV_VAR    "__DEVICE__" // Device var name
  38. #define FLASH_VAR  "__FLASH_SIZE__"     // Flash size var name
  39. #define EEPROM_VAR "__EEPROM_SIZE__"    // EEPROM size var name
  40. #define RAM_VAR    "__RAM_SIZE__"       // RAM size var name
  41. #define DEV_PREFIX "__"         // Device name prefix
  42. #define DEV_SUFFIX "__"         // Device name suffix
  43. #define DEF_DEV_NAME "DEFAULT"  // Default device name (without prefix/suffix)
  44. #define MAX_DEV_NAME 32         // Max device name length
  45.  
  46.  
  47. struct device device_list[] =
  48. {
  49.   /*        Name, Flash(words),RAM start, RAM size, EEPROM, flags */
  50.   {         NULL,     4194304,      0x60,  8388608,  65536, 0}, // Total instructions: 137
  51.   /* ATtiny Series */
  52.   // ATtiny4
  53.   // ATtiny5
  54.   // ATtiny9
  55.   {   "ATtiny10",         512,      0x00,        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},
  56.   {   "ATtiny11",         512,      0x00,        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},
  57.   {   "ATtiny12",         512,      0x00,        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},
  58.   {   "ATtiny13",         512,      0x60,       64,     64, DF_NO_MUL|DF_NO_JMP|DF_NO_ELPM|DF_NO_ESPM|DF_NO_EICALL|DF_NO_EIJMP},
  59.   {   "ATtiny13A",        512,      0x60,       64,     64, DF_NO_MUL|DF_NO_JMP|DF_NO_ELPM|DF_NO_ESPM|DF_NO_EICALL|DF_NO_EIJMP},
  60.   {   "ATtiny15",         512,      0x00,        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},
  61.   // ATtiny20
  62.   {   "ATtiny22",        1024,      0x60,      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},
  63.   {   "ATtiny24",        1024,      0x60,      128,    128, DF_NO_MUL|DF_NO_JMP|DF_NO_ELPM|DF_NO_ESPM|DF_NO_EICALL|DF_NO_EIJMP},
  64.   {   "ATtiny24A",       1024,      0x60,      128,    128, DF_NO_MUL|DF_NO_JMP|DF_NO_ELPM|DF_NO_ESPM|DF_NO_EICALL|DF_NO_EIJMP},
  65.   {   "ATtiny25",        1024,      0x60,      128,    128, DF_NO_MUL|DF_NO_JMP|DF_NO_ELPM|DF_NO_ESPM|DF_NO_EICALL|DF_NO_EIJMP},
  66.   {   "ATtiny26",        1024,      0x60,      128,    128, DF_NO_MUL|DF_NO_JMP|DF_NO_ELPM|DF_NO_SPM|DF_NO_ESPM|DF_NO_MOVW|DF_NO_BREAK|DF_NO_EICALL|DF_NO_EIJMP},
  67.   {   "ATtiny28",        1024,      0x00,        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},
  68.   // ATtiny43U
  69.   {   "ATtiny44",        2048,      0x60,      256,    256, DF_NO_MUL|DF_NO_JMP|DF_NO_ELPM|DF_NO_ESPM|DF_NO_EICALL|DF_NO_EIJMP},
  70.   {   "ATtiny44A",       2048,      0x60,      256,    256, DF_NO_MUL|DF_NO_JMP|DF_NO_ELPM|DF_NO_ESPM|DF_NO_EICALL|DF_NO_EIJMP},
  71.   {   "ATtiny45",        2048,      0x60,      256,    256, DF_NO_MUL|DF_NO_JMP|DF_NO_ELPM|DF_NO_ESPM|DF_NO_EICALL|DF_NO_EIJMP},
  72.   {   "ATtiny84",        4096,      0x60,      512,    512, DF_NO_MUL|DF_NO_JMP|DF_NO_ELPM|DF_NO_ESPM|DF_NO_EICALL|DF_NO_EIJMP},
  73.   {   "ATtiny85",        4096,      0x60,      512,    512, DF_NO_MUL|DF_NO_JMP|DF_NO_ELPM|DF_NO_ESPM|DF_NO_EICALL|DF_NO_EIJMP},
  74.   // ATtiny87
  75.   // ATtiny167
  76.   // ATtiny261A
  77.   // ATtiny461A
  78.   // ATtiny861A
  79.   { "ATtiny2313",        1024,      0x60,      128,    128, DF_NO_MUL|DF_NO_JMP|DF_NO_ELPM|DF_NO_ESPM|DF_NO_EICALL|DF_NO_EIJMP},
  80.   { "ATtiny2313A",       1024,      0x60,      128,    128, DF_NO_MUL|DF_NO_JMP|DF_NO_ELPM|DF_NO_ESPM|DF_NO_EICALL|DF_NO_EIJMP},
  81.   { "ATtiny4313",        2048,      0x60,      256,    256, DF_NO_MUL|DF_NO_JMP|DF_NO_ELPM|DF_NO_ESPM|DF_NO_EICALL|DF_NO_EIJMP},
  82.   /* AT90 series */
  83.   {  "AT90S1200",         512,      0x00,        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)
  84.   {  "AT90S2313",        1024,      0x60,      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},
  85.   {  "AT90S2323",        1024,      0x60,      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},
  86.   {  "AT90S2333",        1024,      0x60,      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},
  87.   {  "AT90S2343",        1024,      0x60,      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},
  88.   {  "AT90S4414",        2048,      0x60,      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},
  89.   {  "AT90S4433",        2048,      0x60,      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},
  90.   {  "AT90S4434",        2048,      0x60,      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},
  91.   {  "AT90S8515",        4096,      0x60,      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
  92.   {  "AT90C8534",        4096,      0x60,      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},
  93.   {  "AT90S8535",        4096,      0x60,      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},
  94.   /* AT90USB series*/
  95.   // AT90USB168
  96.   // AT90USB1287
  97.   /* ATmega series */
  98.   {    "ATmega8",        4096,      0x60,     1024,    512, DF_NO_JMP|DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
  99.   {  "ATmega161",        8192,      0x60,     1024,    512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
  100.   {  "ATmega162",        8192,     0x100,     1024,    512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
  101.   {  "ATmega163",        8192,      0x60,     1024,    512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
  102.   {   "ATmega16",        8192,      0x60,     1024,    512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
  103.   {  "ATmega323",       16384,      0x60,     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)
  104.   { "ATmega328P",       16384,     0x100,     2048,   1024, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
  105.   {   "ATmega32",       16384,      0x60,     2048,   1024, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
  106.   {  "ATmega603",       32768,      0x60,     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},
  107.   {  "ATmega103",       65536,      0x60,     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
  108.   {  "ATmega104",       65536,      0x60,     4096,   4096, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ESPM}, // Old name for mega128
  109.   {  "ATmega128",       65536,     0x100,     4096,   4096, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ESPM}, // 137 - EICALL - EIJMP - ESPM = 134 (Data sheet says 133 but it's wrong)
  110.   {   "ATmega48",        2048,     0x100,      512,    256, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
  111.   {   "ATmega88",        4096,     0x100,     1024,    512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
  112.   {  "ATmega168",        8192,     0x100,     1024,    512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
  113.   { "ATmega8515",        8192,      0x60,      512,    512, DF_NO_EICALL|DF_NO_EIJMP|DF_NO_ELPM|DF_NO_ESPM},
  114.   /* Other */
  115.   {      "AT94K",        8192,      0x60,    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
  116.   {NULL, 0, 0, 0, 0}
  117. };
  118.  
  119. static int LastDevice=0;
  120.  
  121. /*********************************************/
  122. /* Define vars for device in LastDevice   */
  123. /*********************************************/
  124.  
  125. static void def_dev(struct prog_info *pi)
  126. {
  127.    def_var(pi,DEV_VAR,LastDevice);
  128.    def_var(pi,FLASH_VAR,device_list[LastDevice].flash_size);
  129.    def_var(pi,EEPROM_VAR,device_list[LastDevice].eeprom_size);
  130.    def_var(pi,RAM_VAR,device_list[LastDevice].ram_size);
  131. }
  132.  
  133. struct device *get_device(struct prog_info *pi, char *name)
  134. {
  135.         int i = 1;
  136.  
  137.     LastDevice = 0;
  138.         if(name == NULL) {
  139.         def_dev(pi);
  140.             return(&device_list[0]);
  141.         }
  142.         while(device_list[i].name) {
  143.                 if(!nocase_strcmp(name, device_list[i].name)) {
  144.                         LastDevice=i;
  145.             def_dev(pi);
  146.                         return(&device_list[i]);
  147.                 }
  148.                 i++;
  149.         }
  150.         def_dev(pi);
  151.         return(NULL);
  152. }
  153.  
  154. // Pre-define devices. B.A. : Return value change from void to int
  155. int predef_dev(struct prog_info *pi)
  156. {
  157.         int i;
  158.         char temp[MAX_DEV_NAME+1];
  159.         def_dev(pi);
  160.         for (i=0;(!i)||(device_list[i].name);i++) {
  161.                 strncpy(temp,DEV_PREFIX,MAX_DEV_NAME);
  162.                 if (!i) strncat(temp,DEF_DEV_NAME,MAX_DEV_NAME);
  163.                 else strncat(temp,device_list[i].name,MAX_DEV_NAME);
  164.                 strncat(temp,DEV_SUFFIX,MAX_DEV_NAME);
  165.                 /* B.A. : New. Forward references allowed. But check, if everything is ok ... */
  166.                 if(pi->pass==PASS_1) { /* Pass 1 */
  167.       if(test_constant(pi,temp,NULL)!=NULL) {
  168.         fprintf(stderr,"Error: Can't define symbol %s twice. Please don't use predefined symbols !\n", temp);
  169.         return(False);
  170.       }
  171.       if(def_const(pi, temp, i)==False)
  172.         return(False);
  173.           } else { /* Pass 2 */
  174.                         int j;
  175.                         if(get_constant(pi, temp, &j)==False) {   /* Defined in Pass 1 and now missing ? */
  176.             fprintf(stderr,"Constant %s is missing in pass 2\n",temp);
  177.               return(False);
  178.                         }
  179.                   if(i != j) {
  180.               fprintf(stderr,"Constant %s changed value from %d in pass1 to %d in pass 2\n",temp,j,i);
  181.               return(False);
  182.                         }
  183.                         /* OK. definition is unchanged */
  184.           }
  185.         }
  186.         return(True);
  187. }
  188.  
  189. void list_devices()
  190. {
  191.   int i = 1;
  192.   printf("Device name | Flash size | RAM start | RAM size | EEPROM size |  Supported\n"
  193.          "            |  (words)   | (bytes)   | (bytes)  |   (bytes)   | instructions\n"
  194.          "------------+------------+-----------+----------+-------------+--------------\n"
  195.          " (default)  |    %7d |    0x%04x |  %7d |       %5d |          %3d\n",
  196.          device_list[0].flash_size,
  197.          device_list[0].ram_start,
  198.          device_list[0].ram_size,
  199.          device_list[0].eeprom_size,
  200.          count_supported_instructions(device_list[0].flag));
  201.   while(device_list[i].name) {
  202.     printf(" %-10s |    %7d |    0x%04x |  %7d |       %5d |          %3d\n",
  203.            device_list[i].name,
  204.            device_list[i].flash_size,
  205.            device_list[i].ram_start,
  206.            device_list[i].ram_size,
  207.            device_list[i].eeprom_size,
  208.            count_supported_instructions(device_list[i].flag));
  209.     i++;
  210.   }
  211. }
  212.  
  213. /* end of device.c */
  214.  
  215.