driver-avr.c revision 1.3
1/* Subroutines for the gcc driver. 2 Copyright (C) 2009-2013 Free Software Foundation, Inc. 3 Contributed by Anatoly Sokolov <aesok@post.ru> 4 5This file is part of GCC. 6 7GCC is free software; you can redistribute it and/or modify 8it under the terms of the GNU General Public License as published by 9the Free Software Foundation; either version 3, or (at your option) 10any later version. 11 12GCC is distributed in the hope that it will be useful, 13but WITHOUT ANY WARRANTY; without even the implied warranty of 14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15GNU General Public License for more details. 16 17You should have received a copy of the GNU General Public License 18along with GCC; see the file COPYING3. If not see 19<http://www.gnu.org/licenses/>. */ 20 21#include "config.h" 22#include "system.h" 23#include "coretypes.h" 24#include "tm.h" 25 26/* Current architecture. */ 27const avr_arch_t *avr_current_arch = NULL; 28 29/* Current device. */ 30const avr_mcu_t *avr_current_device = NULL; 31 32/* Initialize avr_current_arch and avr_current_device variables. */ 33 34static void 35avr_set_current_device (const char *name) 36{ 37 38 if (NULL != avr_current_arch) 39 return; 40 41 for (avr_current_device = avr_mcu_types; avr_current_device->name; 42 avr_current_device++) 43 { 44 if (strcmp (avr_current_device->name, name) == 0) 45 break; 46 } 47 48 avr_current_arch = &avr_arch_types[avr_current_device->arch]; 49} 50 51/* Returns command line parameters to pass to as. */ 52 53const char* 54avr_device_to_as (int argc, const char **argv) 55{ 56 if (0 == argc) 57 return NULL; 58 59 avr_set_current_device (argv[0]); 60 61 return concat ("-mmcu=", avr_current_arch->arch_name, 62 avr_current_device->errata_skip ? "" : " -mno-skip-bug", 63 NULL); 64} 65 66/* Returns command line parameters to pass to ld. */ 67 68const char* 69avr_device_to_ld (int argc, const char **argv) 70{ 71 if (0 == argc) 72 return NULL; 73 74 avr_set_current_device (argv[0]); 75 76 return concat ("-m ", avr_current_arch->arch_name, NULL); 77} 78 79/* Returns command line parameters that describe start of date section. */ 80 81const char * 82avr_device_to_data_start (int argc, const char **argv) 83{ 84 unsigned long data_section_start; 85 char data_section_start_str[16]; 86 87 if (0 == argc) 88 return NULL; 89 90 avr_set_current_device (argv[0]); 91 92 if (avr_current_device->data_section_start 93 == avr_current_arch->default_data_section_start) 94 return NULL; 95 96 data_section_start = 0x800000 + avr_current_device->data_section_start; 97 98 snprintf (data_section_start_str, sizeof(data_section_start_str) - 1, 99 "0x%lX", data_section_start); 100 101 return concat ("-Tdata ", data_section_start_str, NULL); 102} 103 104/* Returns command line parameters that describe the device startfile. */ 105 106const char * 107avr_device_to_startfiles (int argc, const char **argv) 108{ 109 if (0 == argc) 110 return NULL; 111 112 avr_set_current_device (argv[0]); 113 114 return concat ("crt", avr_current_device->library_name, ".o%s", NULL); 115} 116 117/* Returns command line parameters that describe the device library. */ 118 119const char * 120avr_device_to_devicelib (int argc, const char **argv) 121{ 122 if (0 == argc) 123 return NULL; 124 125 avr_set_current_device (argv[0]); 126 127 return concat ("-l", avr_current_device->library_name, NULL); 128} 129 130const char* 131avr_device_to_sp8 (int argc, const char **argv) 132{ 133 if (0 == argc) 134 return NULL; 135 136 avr_set_current_device (argv[0]); 137 138 /* Leave "avr2" and "avr25" alone. These two architectures are 139 the only ones that mix devices with 8-bit SP and 16-bit SP. 140 -msp8 is set by mmultilib machinery. */ 141 142 if (avr_current_device->macro == NULL 143 && (avr_current_device->arch == ARCH_AVR2 144 || avr_current_device->arch == ARCH_AVR25)) 145 return ""; 146 147 return avr_current_device->short_sp 148 ? "-msp8" 149 : "%<msp8"; 150} 151