Set correct ram start address for supported ARM.
[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_attr.h"      /* CONFIG_FAST_MEM */
46
47
48 /**
49  * \name Macros for determining CPU endianness.
50  * \{
51  */
52 #define CPU_BIG_ENDIAN    0x1234
53 #define CPU_LITTLE_ENDIAN 0x3412 /* Look twice, pal. This is not a bug. */
54 /*\}*/
55
56 /** Macro to include cpu-specific versions of the headers. */
57 #define CPU_HEADER(module)          PP_STRINGIZE(drv/PP_CAT3(module, _, CPU_ID).h)
58
59 /** Macro to include cpu-specific versions of implementation files. */
60 #define CPU_CSOURCE(module)         PP_STRINGIZE(drv/PP_CAT3(module, _, CPU_ID).c)
61
62
63 #if CPU_I196
64
65         #define NOP                     nop_instruction()
66
67         #define CPU_REG_BITS            16
68         #define CPU_REGS_CNT            16
69         #define CPU_BYTE_ORDER          CPU_LITTLE_ENDIAN
70         #define CPU_HARVARD             0
71
72         /// Valid pointers should be >= than this value (used for debug)
73         #define CPU_RAM_START           0x100
74
75 #elif CPU_X86
76
77         #define CPU_REGS_CNT            7
78         #define CPU_BYTE_ORDER          CPU_LITTLE_ENDIAN
79         #define CPU_HARVARD             0
80
81         #if CPU_X86_64
82                 #define CPU_REG_BITS    64
83
84                 #ifdef __WIN64__
85                         /* WIN64 is an IL32-P64 weirdo. */
86                         #define SIZEOF_LONG  4
87                 #endif
88         #else
89                 #define CPU_REG_BITS    32
90         #endif
91
92         /// Valid pointers should be >= than this value (used for debug)
93         #define CPU_RAM_START      0x1000
94
95         #ifdef __GNUC__
96                 #define NOP         asm volatile ("nop")
97                 #define BREAKPOINT  asm volatile ("int3" ::)
98         #endif
99
100 #elif CPU_ARM
101
102         #define CPU_REG_BITS           32
103         #define CPU_REGS_CNT           16
104         #define CPU_HARVARD            0
105
106         /// Valid pointers should be >= than this value (used for debug)
107         #if CPU_ARM_AT91
108                 #define CPU_RAM_START           0x00200000
109         #else
110                 #warning Fix CPU_RAM_START address for your ARM, default value set to 0x200
111                 #define CPU_RAM_START           0x200
112
113         #ifdef __IAR_SYSTEMS_ICC__
114                 #warning Check CPU_BYTE_ORDER
115                 #define CPU_BYTE_ORDER (__BIG_ENDIAN__ ? CPU_BIG_ENDIAN : CPU_LITTLE_ENDIAN)
116
117                 #define NOP            __no_operation()
118
119         #else /* GCC and compatibles */
120
121                 #if defined(__ARMEB__)
122                         #define CPU_BYTE_ORDER CPU_BIG_ENDIAN
123                 #elif defined(__ARMEL__)
124                         #define CPU_BYTE_ORDER CPU_LITTLE_ENDIAN
125                 #else
126                         #error Unable to detect ARM endianness!
127                 #endif
128
129                 #define NOP            asm volatile ("mov r0,r0" ::)
130                 #define BREAKPOINT  /* asm("bkpt 0") DOES NOT WORK */
131
132                 #if CONFIG_FAST_MEM
133                         /**
134                          * Function attribute for use with performance critical code.
135                          *
136                          * On the AT91 family, code residing in flash has wait states.
137                          * Moving functions to the data section is a quick & dirty way
138                          * to get them transparently copied to SRAM for zero-wait-state
139                          * operation.
140                          */
141                         #define FAST_FUNC __attribute__((section(".data")))
142
143                         /**
144                          * Data attribute to move constant data to fast memory storage.
145                          *
146                          * \see FAST_FUNC
147                          */
148                         #define FAST_RODATA __attribute__((section(".data")))
149
150                 #else // !CONFIG_FAST_MEM
151                         #define FAST_RODATA /**/
152                         #define FAST_FUNC /**/
153                 #endif
154
155                 /**
156                  * Function attribute to declare an interrupt service routine.
157                  */
158                 #define ISR_FUNC __attribute__((interrupt))
159
160         #endif /* !__IAR_SYSTEMS_ICC_ */
161
162 #elif CPU_PPC
163
164         #define CPU_REG_BITS           (CPU_PPC32 ? 32 : 64)
165         #define CPU_REGS_CNT           FIXME
166         #define CPU_BYTE_ORDER         (__BIG_ENDIAN__ ? CPU_BIG_ENDIAN : CPU_LITTLE_ENDIAN)
167         #define CPU_HARVARD            0
168
169         /// Valid pointers should be >= than this value (used for debug)
170         #define CPU_RAM_START          0x1000
171
172         #ifdef __GNUC__
173             #define NOP         asm volatile ("nop" ::)
174                 #define BREAKPOINT  asm volatile ("twge 2,2" ::)
175         #endif
176
177 #elif CPU_DSP56K
178
179         #define CPU_REG_BITS            16
180         #define CPU_REGS_CNT            FIXME
181         #define CPU_BYTE_ORDER          CPU_BIG_ENDIAN
182         #define CPU_HARVARD             1
183
184         /* Memory is word-addessed in the DSP56K */
185         #define CPU_BITS_PER_CHAR  16
186         #define SIZEOF_SHORT        1
187         #define SIZEOF_INT          1
188         #define SIZEOF_LONG         2
189         #define SIZEOF_PTR          1
190
191         /// Valid pointers should be >= than this value (used for debug)
192         #define CPU_RAM_START       0x200
193
194         #define NOP                     asm(nop)
195         #define BREAKPOINT              asm(debug)
196
197 #elif CPU_AVR
198
199         #define NOP                     asm volatile ("nop" ::)
200
201         #define CPU_REG_BITS            8
202         #define CPU_REGS_CNT           33 /* Includes SREG */
203         #define CPU_BYTE_ORDER          CPU_LITTLE_ENDIAN
204         #define CPU_HARVARD             1
205
206         /// Valid pointers should be >= than this value (used for debug)
207         #if CPU_AVR_ATMEGA8 || CPU_AVR_ATMEGA32 || CPU_AVR_ATMEGA103
208                 #define CPU_RAM_START       0x60
209         #elif CPU_AVR_ATMEGA64 || CPU_AVR_ATMEGA128 || CPU_AVR_ATMEGA168
210                 #define CPU_RAM_START       0x100
211         #elif CPU_AVR_ATMEGA1281
212                 #define CPU_RAM_START       0x200
213         #else
214                 #warning Fix CPU_RAM_START address for your AVR, default value set to 0x100
215                 #define CPU_RAM_START       0x100
216
217 #else
218         #error No CPU_... defined.
219 #endif
220
221 #ifndef BREAKPOINT
222 #define BREAKPOINT /* nop */
223 #endif
224
225 #ifndef FAST_FUNC
226         /// Function attribute for use with performance critical code.
227         #define FAST_FUNC /* */
228 #endif
229
230 #ifndef FAST_RODATA
231         /// Data attribute to move constant data to fast memory storage.
232         #define FAST_RODATA /* */
233 #endif
234
235 #endif /* CPU_ATTR_H */