5f5217f03ca3ac3297085411368d95246dd34ef5
[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(".ramfunc")))
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(".ramfunc")))
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_STM32 || 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         /*
194          * Function attribute to move it into ram memory.
195          */
196         #define RAM_FUNC __attribute__((section(".ramfunc")))
197
198 #elif CPU_PPC
199
200         #define CPU_REG_BITS           (CPU_PPC32 ? 32 : 64)
201         #define CPU_REGS_CNT           FIXME
202         #define CPU_BYTE_ORDER         (__BIG_ENDIAN__ ? CPU_BIG_ENDIAN : CPU_LITTLE_ENDIAN)
203         #define CPU_HARVARD            0
204
205         /// Valid pointers should be >= than this value (used for debug)
206         #define CPU_RAM_START          0x1000
207
208         #ifdef __GNUC__
209             #define NOP         asm volatile ("nop" ::)
210                 #define BREAKPOINT  asm volatile ("twge 2,2" ::)
211         #endif
212
213 #elif CPU_DSP56K
214
215         #define CPU_REG_BITS            16
216         #define CPU_REGS_CNT            FIXME
217         #define CPU_BYTE_ORDER          CPU_BIG_ENDIAN
218         #define CPU_HARVARD             1
219
220         /* Memory is word-addessed in the DSP56K */
221         #define CPU_BITS_PER_CHAR  16
222         #define SIZEOF_SHORT        1
223         #define SIZEOF_INT          1
224         #define SIZEOF_LONG         2
225         #define SIZEOF_PTR          1
226
227         /// Valid pointers should be >= than this value (used for debug)
228         #define CPU_RAM_START       0x200
229
230         #define NOP                     asm(nop)
231         #define BREAKPOINT              asm(debug)
232
233 #elif CPU_AVR
234
235         #define NOP                     asm volatile ("nop" ::)
236
237         #define CPU_REG_BITS            8
238         #define CPU_REGS_CNT           33 /* Includes SREG */
239         #define CPU_BYTE_ORDER          CPU_LITTLE_ENDIAN
240         #define CPU_HARVARD             1
241
242         /// Valid pointers should be >= than this value (used for debug)
243         #if CPU_AVR_ATMEGA8 || CPU_AVR_ATMEGA32 || CPU_AVR_ATMEGA103
244                 #define CPU_RAM_START       0x60
245         #elif CPU_AVR_ATMEGA64 || CPU_AVR_ATMEGA128 || CPU_AVR_ATMEGA168 || CPU_AVR_ATMEGA328P
246                 #define CPU_RAM_START       0x100
247         #elif CPU_AVR_ATMEGA1281 || CPU_AVR_ATMEGA1280 || CPU_AVR_ATMEGA2560
248                 #define CPU_RAM_START       0x200
249         #else
250                 #warning Fix CPU_RAM_START address for your AVR, default value set to 0x100
251                 #define CPU_RAM_START       0x100
252         #endif
253
254 #elif CPU_MSP430
255
256         #define CPU_REG_BITS            16
257         #define CPU_REGS_CNT            12
258         #define CPU_BYTE_ORDER          CPU_LITTLE_ENDIAN
259         #define CPU_HARVARD                     0
260
261         /// Valid pointers should be >= than this value (used for debug)
262         #define CPU_RAM_START           0x200
263
264         #define NOP                     __asm__ __volatile__ ("nop")
265
266 #else
267         #error No CPU_... defined.
268 #endif
269
270 #ifndef BREAKPOINT
271 #define BREAKPOINT /* nop */
272 #endif
273
274 #ifndef FAST_FUNC
275         /// Function attribute for use with performance critical code.
276         #define FAST_FUNC /* */
277 #endif
278
279 #ifndef FAST_RODATA
280         /// Data attribute to move constant data to fast memory storage.
281         #define FAST_RODATA /* */
282 #endif
283
284 #ifndef PAUSE
285         /// Generic PAUSE implementation.
286         #define PAUSE   {NOP; MEMORY_BARRIER;}
287 #endif
288
289 #endif /* CPU_ATTR_H */