cpu: Split frame handling macros to the new header cpu/frame.h
[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  *
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_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 NOP                     asm volatile ("nop")
79
80         #define CPU_REGS_CNT            7
81         #define CPU_BYTE_ORDER          CPU_LITTLE_ENDIAN
82         #define CPU_HARVARD             0
83
84         #if CPU_X86_64
85                 #define CPU_REG_BITS    64
86
87                 #ifdef __WIN64__
88                         /* WIN64 is an IL32-P64 weirdo. */
89                         #define SIZEOF_LONG  4
90                 #endif
91         #else
92                 #define CPU_REG_BITS    32
93         #endif
94
95         /// Valid pointers should be >= than this value (used for debug)
96         #define CPU_RAM_START           0x1000
97
98 #elif CPU_ARM
99
100         #define CPU_REG_BITS           32
101         #define CPU_REGS_CNT           16
102         #define CPU_HARVARD            0
103
104         /// Valid pointers should be >= than this value (used for debug)
105         #define CPU_RAM_START           0x200
106
107         #ifdef __IAR_SYSTEMS_ICC__
108                 #warning Check CPU_BYTE_ORDER
109                 #define CPU_BYTE_ORDER (__BIG_ENDIAN__ ? CPU_BIG_ENDIAN : CPU_LITTLE_ENDIAN)
110
111                 #define NOP            __no_operation()
112
113         #else /* GCC and compatibles */
114
115                 #if defined(__ARMEB__)
116                         #define CPU_BYTE_ORDER CPU_BIG_ENDIAN
117                 #elif defined(__ARMEL__)
118                         #define CPU_BYTE_ORDER CPU_LITTLE_ENDIAN
119                 #else
120                         #error Unable to detect ARM endianness!
121                 #endif
122
123                 #define NOP            asm volatile ("mov r0,r0" ::)
124
125                 #if CONFIG_FAST_MEM
126                         /**
127                          * Function attribute for use with performance critical code.
128                          *
129                          * On the AT91 family, code residing in flash has wait states.
130                          * Moving functions to the data section is a quick & dirty way
131                          * to get them transparently copied to SRAM for zero-wait-state
132                          * operation.
133                          */
134                         #define FAST_FUNC __attribute__((section(".data")))
135
136                         /**
137                          * Data attribute to move constant data to fast memory storage.
138                          *
139                          * \see FAST_FUNC
140                          */
141                         #define FAST_RODATA __attribute__((section(".data")))
142
143                 #else // !CONFIG_FAST_MEM
144                         #define FAST_RODATA /**/
145                         #define FAST_FUNC /**/
146                 #endif
147
148                 /**
149                  * Function attribute to declare an interrupt service routine.
150                  */
151                 #define ISR_FUNC __attribute__((interrupt))
152
153         #endif /* !__IAR_SYSTEMS_ICC_ */
154
155 #elif CPU_PPC
156
157         #define NOP                    asm volatile ("nop" ::)
158
159         #define CPU_REG_BITS           (CPU_PPC32 ? 32 : 64)
160         #define CPU_REGS_CNT           FIXME
161         #define CPU_BYTE_ORDER         (__BIG_ENDIAN__ ? CPU_BIG_ENDIAN : CPU_LITTLE_ENDIAN)
162         #define CPU_HARVARD            0
163
164         /// Valid pointers should be >= than this value (used for debug)
165         #define CPU_RAM_START           0x1000
166
167 #elif CPU_DSP56K
168
169         #define NOP                     asm(nop)
170
171         #define CPU_REG_BITS            16
172         #define CPU_REGS_CNT            FIXME
173         #define CPU_BYTE_ORDER          CPU_BIG_ENDIAN
174         #define CPU_HARVARD             1
175
176         /* Memory is word-addessed in the DSP56K */
177         #define CPU_BITS_PER_CHAR  16
178         #define SIZEOF_SHORT        1
179         #define SIZEOF_INT          1
180         #define SIZEOF_LONG         2
181         #define SIZEOF_PTR          1
182
183         /// Valid pointers should be >= than this value (used for debug)
184         #define CPU_RAM_START           0x200
185
186 #elif CPU_AVR
187
188         #define NOP                     asm volatile ("nop" ::)
189
190         #define CPU_REG_BITS            8
191         #define CPU_REGS_CNT           33 /* Includes SREG */
192         #define CPU_BYTE_ORDER          CPU_LITTLE_ENDIAN
193         #define CPU_HARVARD             1
194
195         /// Valid pointers should be >= than this value (used for debug)
196         #define CPU_RAM_START           0x100
197
198 #else
199         #error No CPU_... defined.
200 #endif
201
202 #ifndef FAST_FUNC
203         /// Function attribute for use with performance critical code.
204         #define FAST_FUNC /* */
205 #endif
206
207 #ifndef FAST_RODATA
208         /// Data attribute to move constant data to fast memory storage.
209         #define FAST_RODATA /* */
210 #endif
211
212 #endif /* CPU_ATTR_H */