Change filename and macros from AT91SAM3.. to SAM3.. to conform to Atmel's official...
[bertos.git] / bertos / cpu / attr.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2004, 2005, 2006, 2007, 2008 Develer S.r.l. (http://www.develer.com/)
30  * Copyright 2004 Giovanni Bajo
31  * -->
32  *
33  * \brief CPU-specific attributes.
34  *
35  * \author Giovanni Bajo <rasky@develer.com>
36  * \author Bernie Innocenti <bernie@codewiz.org>
37  * \author Stefano Fedrigo <aleph@develer.com>
38  * \author Francesco Sacchi <batt@develer.com>
39  */
40 #ifndef CPU_ATTR_H
41 #define CPU_ATTR_H
42
43 #include "detect.h"
44
45 #include "cfg/cfg_proc.h"      /* CONFIG_KERN_PREEMPT */
46 #include "cfg/cfg_attr.h"      /* CONFIG_FAST_MEM */
47
48
49 /**
50  * \name Macros for determining CPU endianness.
51  * \{
52  */
53 #define CPU_BIG_ENDIAN    0x1234
54 #define CPU_LITTLE_ENDIAN 0x3412 /* Look twice, pal. This is not a bug. */
55 /*\}*/
56
57 /** Macro to include cpu-specific versions of the headers. */
58 #define CPU_HEADER(module)          PP_STRINGIZE(drv/PP_CAT3(module, _, CPU_ID).h)
59
60 /** Macro to include cpu-specific versions of implementation files. */
61 #define CPU_CSOURCE(module)         PP_STRINGIZE(drv/PP_CAT3(module, _, CPU_ID).c)
62
63
64 #if CPU_I196
65
66         #define NOP                     nop_instruction()
67
68         #define CPU_REG_BITS            16
69         #define CPU_REGS_CNT            16
70         #define CPU_BYTE_ORDER          CPU_LITTLE_ENDIAN
71         #define CPU_HARVARD             0
72
73         /// Valid pointers should be >= than this value (used for debug)
74         #define CPU_RAM_START           0x100
75
76 #elif CPU_X86
77
78         #define CPU_REGS_CNT            7
79         #define CPU_BYTE_ORDER          CPU_LITTLE_ENDIAN
80         #define CPU_HARVARD             0
81
82         #if CPU_X86_64
83                 #define CPU_REG_BITS    64
84
85                 #ifdef __WIN64__
86                         /* WIN64 is an IL32-P64 weirdo. */
87                         #define SIZEOF_LONG  4
88                 #endif
89         #else
90                 #define CPU_REG_BITS    32
91         #endif
92
93         /// Valid pointers should be >= than this value (used for debug)
94         #define CPU_RAM_START      0x1000
95
96         #ifdef __GNUC__
97                 #define NOP         asm volatile ("nop")
98                 /* This is a good thing to insert into busy-wait loops. */
99                 #define PAUSE       asm volatile ("rep; nop" ::: "memory")
100                 #define BREAKPOINT  asm volatile ("int3" ::)
101         #endif
102
103 #elif CPU_ARM
104
105         #define CPU_REG_BITS           32
106         #define CPU_REGS_CNT           16
107         #define CPU_HARVARD            0
108
109         /// Valid pointers should be >= than this value (used for debug)
110         #if CPU_ARM_AT91
111                 #define CPU_RAM_START           0x00200000
112         #elif CPU_ARM_LPC2
113                 #define CPU_RAM_START           0x40000000
114         #else
115                 #warning Fix CPU_RAM_START address for your ARM, default value set to 0x200
116                 #define CPU_RAM_START           0x200
117         #endif
118
119         #ifdef __IAR_SYSTEMS_ICC__
120                 #warning Check CPU_BYTE_ORDER
121                 #define CPU_BYTE_ORDER (__BIG_ENDIAN__ ? CPU_BIG_ENDIAN : CPU_LITTLE_ENDIAN)
122
123                 #define NOP            __no_operation()
124
125         #else /* GCC and compatibles */
126
127                 #if defined(__ARMEB__)
128                         #define CPU_BYTE_ORDER CPU_BIG_ENDIAN
129                 #elif defined(__ARMEL__)
130                         #define CPU_BYTE_ORDER CPU_LITTLE_ENDIAN
131                 #else
132                         #error Unable to detect ARM endianness!
133                 #endif
134
135                 #define NOP            asm volatile ("mov r0,r0" ::)
136                 #define BREAKPOINT  /* asm("bkpt 0") DOES NOT WORK */
137
138                 #if CONFIG_FAST_MEM
139                         /**
140                          * Function attribute for use with performance critical code.
141                          *
142                          * On the AT91 family, code residing in flash has wait states.
143                          * Moving functions to the data section is a quick & dirty way
144                          * to get them transparently copied to SRAM for zero-wait-state
145                          * operation.
146                          */
147                         #define FAST_FUNC __attribute__((section(".data")))
148
149                         /**
150                          * Data attribute to move constant data to fast memory storage.
151                          *
152                          * \see FAST_FUNC
153                          */
154                         #define FAST_RODATA __attribute__((section(".data")))
155
156                 #else // !CONFIG_FAST_MEM
157                         #define FAST_RODATA /**/
158                         #define FAST_FUNC /**/
159                 #endif
160
161                 /*
162                  * Function attribute to move it into ram memory.
163                  */
164                 #define RAM_FUNC __attribute__((section(".data")))
165
166         #endif /* !__IAR_SYSTEMS_ICC_ */
167 #elif CPU_CM3
168
169         #define CPU_REG_BITS           32
170         #define CPU_REGS_CNT           16
171         #define CPU_HARVARD            0
172
173         /// Valid pointers should be >= than this value (used for debug)
174         #if (CPU_CM3_LM3S1968 || CPU_CM3_LM3S8962 || CPU_CM3_STM32F103RB || CPU_CM3_SAM3)
175                 #define CPU_RAM_START 0x20000000
176         #else
177                 #warning Fix CPU_RAM_START address for your Cortex-M3, default value set to 0x20000000
178                 #define CPU_RAM_START 0x20000000
179         #endif
180
181         #if defined(__ARMEB__)
182                 #define CPU_BYTE_ORDER CPU_BIG_ENDIAN
183         #elif defined(__ARMEL__)
184                 #define CPU_BYTE_ORDER CPU_LITTLE_ENDIAN
185         #else
186                 #error Unable to detect Cortex-M3 endianess!
187         #endif
188
189         #define NOP         asm volatile ("nop")
190         #define PAUSE       asm volatile ("wfi" ::: "memory")
191         #define BREAKPOINT  /* asm("bkpt 0") DOES NOT WORK */
192
193 #elif CPU_PPC
194
195         #define CPU_REG_BITS           (CPU_PPC32 ? 32 : 64)
196         #define CPU_REGS_CNT           FIXME
197         #define CPU_BYTE_ORDER         (__BIG_ENDIAN__ ? CPU_BIG_ENDIAN : CPU_LITTLE_ENDIAN)
198         #define CPU_HARVARD            0
199
200         /// Valid pointers should be >= than this value (used for debug)
201         #define CPU_RAM_START          0x1000
202
203         #ifdef __GNUC__
204             #define NOP         asm volatile ("nop" ::)
205                 #define BREAKPOINT  asm volatile ("twge 2,2" ::)
206         #endif
207
208 #elif CPU_DSP56K
209
210         #define CPU_REG_BITS            16
211         #define CPU_REGS_CNT            FIXME
212         #define CPU_BYTE_ORDER          CPU_BIG_ENDIAN
213         #define CPU_HARVARD             1
214
215         /* Memory is word-addessed in the DSP56K */
216         #define CPU_BITS_PER_CHAR  16
217         #define SIZEOF_SHORT        1
218         #define SIZEOF_INT          1
219         #define SIZEOF_LONG         2
220         #define SIZEOF_PTR          1
221
222         /// Valid pointers should be >= than this value (used for debug)
223         #define CPU_RAM_START       0x200
224
225         #define NOP                     asm(nop)
226         #define BREAKPOINT              asm(debug)
227
228 #elif CPU_AVR
229
230         #define NOP                     asm volatile ("nop" ::)
231
232         #define CPU_REG_BITS            8
233         #define CPU_REGS_CNT           33 /* Includes SREG */
234         #define CPU_BYTE_ORDER          CPU_LITTLE_ENDIAN
235         #define CPU_HARVARD             1
236
237         /// Valid pointers should be >= than this value (used for debug)
238         #if CPU_AVR_ATMEGA8 || CPU_AVR_ATMEGA32 || CPU_AVR_ATMEGA103
239                 #define CPU_RAM_START       0x60
240         #elif CPU_AVR_ATMEGA64 || CPU_AVR_ATMEGA128 || CPU_AVR_ATMEGA168 || CPU_AVR_ATMEGA328P
241                 #define CPU_RAM_START       0x100
242         #elif CPU_AVR_ATMEGA1281 || CPU_AVR_ATMEGA1280
243                 #define CPU_RAM_START       0x200
244         #else
245                 #warning Fix CPU_RAM_START address for your AVR, default value set to 0x100
246                 #define CPU_RAM_START       0x100
247         #endif
248
249 #elif CPU_MSP430
250
251         #define CPU_REG_BITS            16
252         #define CPU_REGS_CNT            12
253         #define CPU_BYTE_ORDER          CPU_LITTLE_ENDIAN
254         #define CPU_HARVARD                     0
255
256         /// Valid pointers should be >= than this value (used for debug)
257         #define CPU_RAM_START               0x200
258
259         #define NOP                     __asm__ __volatile__ ("nop")
260
261 #else
262         #error No CPU_... defined.
263 #endif
264
265 #ifndef BREAKPOINT
266 #define BREAKPOINT /* nop */
267 #endif
268
269 #ifndef FAST_FUNC
270         /// Function attribute for use with performance critical code.
271         #define FAST_FUNC /* */
272 #endif
273
274 #ifndef FAST_RODATA
275         /// Data attribute to move constant data to fast memory storage.
276         #define FAST_RODATA /* */
277 #endif
278
279 #ifndef PAUSE
280         /// Generic PAUSE implementation.
281         #define PAUSE   {NOP; MEMORY_BARRIER;}
282 #endif
283
284 #endif /* CPU_ATTR_H */