1 /* Subroutines for the gcc driver.
2 Copyright (C) 2015-2025 Free Software Foundation, Inc.
3 Contributed by Georg-Johann Lay <avr@gjlay.de>
5 This file is part of GCC.
7 GCC 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 3, or (at your option)
12 GCC 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 GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #define IN_TARGET_CODE 1
25 #include "coretypes.h"
26 #include "diagnostic.h"
28 #include "msp430-devices.h"
30 /* This spec function is called if the user has provided an -mmcu option without
31 an -mcpu option. It will place the correct -mcpu option for the given -mmcu
32 onto the command line, to ensure the correct ISA multilib is selected. */
34 msp430_select_cpu (int argc
, const char ** argv
)
38 error ("expected an argument to %<msp430_select_cpu%>");
41 msp430_extract_mcu_data (argv
[0]);
42 if (extracted_mcu_data
.name
!= NULL
)
44 switch (extracted_mcu_data
.revision
)
46 case 0: return "-mcpu=msp430";
47 case 1: return "-mcpu=msp430x";
48 case 2: return "-mcpu=msp430xv2";
53 /* MCU wasn't found, the compiler proper will warn about this. */
57 /* Spec function to set a global variable to a specific value in the driver.
58 The first argument is the variable name, and the second is the value to set
60 Currently only "msp430_warn_devices_csv" and "msp430_devices_csv_loc" are
62 The intention is that we can take a "Target" option and set the variable
63 associated with it in the driver as well. Whilst the driver sees "Target"
64 options, it does not set the variables associated with that option. */
66 msp430_set_driver_var (int argc
, const char ** argv
)
69 error ("%<msp430_set_driver_var%> expects 2 arguments");
70 else if (strcmp (argv
[0], "msp430_warn_devices_csv") == 0)
71 msp430_warn_devices_csv
= atoi (argv
[1]);
72 else if (strcmp (argv
[0], "msp430_devices_csv_loc") == 0)
73 msp430_devices_csv_loc
= argv
[1];
75 error ("unhandled arguments %qs and %qs to %<msp430_set_driver_var%>",
80 /* Implement spec function `msp430_hwmult_libĀ“. */
83 msp430_select_hwmult_lib (int argc ATTRIBUTE_UNUSED
,
84 const char ** argv ATTRIBUTE_UNUSED
)
91 if (strcasecmp (argv
[0], "default"))
92 error ("unexpected argument to %<msp430_select_hwmult_lib%>: %s", argv
[0]);
96 /* We can get three or more arguments passed to this function.
97 This happens when the same option is repeated on the command line.
99 msp430-elf-gcc -mhwmult=none -mhwmult=16bit foo.c
100 We have to use the last argument as our selector. */
101 if (strcasecmp (argv
[0], "hwmult") == 0)
103 static struct hwmult_options
109 { "none", "-lmul_none" },
110 { "auto", "-lmul_AUTO" }, /* Should not see this one... */
111 { "16bit", "-lmul_16" },
112 { "32bit", "-lmul_32" },
113 { "f5series", "-lmul_f5" }
116 for (i
= ARRAY_SIZE (hwmult_options
); i
--;)
117 if (strcasecmp (argv
[argc
- 1], hwmult_options
[i
].name
) == 0)
118 return hwmult_options
[i
].lib
;
120 else if (strcasecmp (argv
[0], "mcu") == 0)
122 msp430_extract_mcu_data (argv
[argc
- 1]);
123 if (extracted_mcu_data
.name
!= NULL
)
125 switch (extracted_mcu_data
.hwmpy
)
127 case 0: return "-lmul_none";
129 case 1: return "-lmul_16";
130 case 4: return "-lmul_32";
131 case 8: return "-lmul_f5";
133 /* We have already checked the hwmpy values for
134 validity in msp430_extract_mcu_data. */
141 error ("unexpected first argument to %<msp430_select_hwmult_lib%>: %s",
146 error ("%<msp430_select_hwmult_lib%> needs one or more arguments");
153 /* Spec function. Used to place the path to the MSP430-GCC support files
154 on the command line, prefixed with "-L", so the linker finds the linker
155 scripts in that directory. */
157 msp430_get_linker_devices_include_path (int argc ATTRIBUTE_UNUSED
,
158 const char **argv ATTRIBUTE_UNUSED
)
160 char *devices_csv_path
;
161 if (msp430_check_env_var_for_devices (&devices_csv_path
))
163 return concat ("-L", msp430_dirname (devices_csv_path
), NULL
);
166 /* Spec function. Propagate -m{code,data}-region= to the linker, unless the
167 lower region has been specified without -muse-lower-region-prefix also being
170 msp430_propagate_region_opt (int argc
, const char **argv
)
172 if (strcmp (argv
[0], "lower") != 0)
174 else if ((argc
== 2) && (strcmp (argv
[1], "-muse-lower-region-prefix") == 0))
175 return argv
[0]; /* argv[0] == "lower". */