driver-avr.c revision 1.1
1/* Subroutines for the gcc driver.
2   Copyright (C) 2009 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#include <stdlib.h>
26
27/* Current architecture.  */
28const struct base_arch_s *avr_current_arch = NULL;
29
30/* Current device.  */
31const struct mcu_type_s *avr_current_device = NULL;
32
33/* Initialize avr_current_arch and avr_current_device variables.  */
34
35static void
36avr_set_current_device (const char *name)
37{
38
39 if (NULL != avr_current_arch)
40   return;
41
42  for (avr_current_device = avr_mcu_types; avr_current_device->name;
43       avr_current_device++)
44    {
45      if (strcmp (avr_current_device->name, name) == 0)
46        break;
47    }
48
49  avr_current_arch = &avr_arch_types[avr_current_device->arch];
50}
51
52/* Returns command line parameters that describe the device architecture.  */
53
54const char *
55avr_device_to_arch (int argc, const char **argv)
56{
57  if (0 == argc)
58    return;
59
60  avr_set_current_device (argv[0]);
61
62  return concat ("-m ", avr_current_arch->arch_name, NULL);
63}
64
65/* Returns command line parameters that describe start of date section.  */
66
67const char *
68avr_device_to_data_start (int argc, const char **argv)
69{
70  unsigned long data_section_start;
71  char data_section_start_str[16];
72
73  if (0 == argc)
74    return;
75
76  avr_set_current_device (argv[0]);
77
78  if (avr_current_device->data_section_start
79      == avr_current_arch->default_data_section_start)
80    return NULL;
81
82  data_section_start = 0x800000 + avr_current_device->data_section_start;
83
84  snprintf (data_section_start_str, sizeof(data_section_start_str) - 1,
85            "0x%lX", data_section_start);
86
87  return concat ("-Tdata ", data_section_start_str, NULL);
88}
89
90/* Returns command line parameters that describe the device startfile.  */
91
92const char *
93avr_device_to_startfiles (int argc, const char **argv)
94{
95  if (0 == argc)
96    return;
97
98  avr_set_current_device (argv[0]);
99
100  return concat ("crt", avr_current_device->library_name, ".o%s", NULL);
101}
102
103/* Returns command line parameters that describe the device library.  */
104
105const char *
106avr_device_to_devicelib (int argc, const char **argv)
107{
108  if (0 == argc)
109    return;
110
111  avr_set_current_device (argv[0]);
112
113  return concat ("-l", avr_current_device->library_name, NULL);
114}
115
116