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