1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief V850 CPU Department Source |
---|
5 | * |
---|
6 | * This include file contains information pertaining to the v850 |
---|
7 | * processor. |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * COPYRIGHT (c) 1989-2012. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_SCORE_CPU_H |
---|
20 | #define _RTEMS_SCORE_CPU_H |
---|
21 | |
---|
22 | #ifdef __cplusplus |
---|
23 | extern "C" { |
---|
24 | #endif |
---|
25 | |
---|
26 | #include <rtems/score/basedefs.h> |
---|
27 | #include <rtems/score/v850.h> |
---|
28 | |
---|
29 | /* conditional compilation parameters */ |
---|
30 | |
---|
31 | /** |
---|
32 | * Does the CPU follow the simple vectored interrupt model? |
---|
33 | * |
---|
34 | * If TRUE, then RTEMS allocates the vector table it internally manages. |
---|
35 | * If FALSE, then the BSP is assumed to allocate and manage the vector |
---|
36 | * table |
---|
37 | * |
---|
38 | * Port Specific Information: |
---|
39 | * |
---|
40 | * This port uses the Progammable Interrupt Controller interrupt model. |
---|
41 | */ |
---|
42 | #define CPU_SIMPLE_VECTORED_INTERRUPTS FALSE |
---|
43 | |
---|
44 | /** |
---|
45 | * @def CPU_HARDWARE_FP |
---|
46 | * |
---|
47 | * Does the CPU have hardware floating point? |
---|
48 | * |
---|
49 | * If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported. |
---|
50 | * If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored. |
---|
51 | * |
---|
52 | * If there is a FP coprocessor such as the i387 or mc68881, then |
---|
53 | * the answer is TRUE. |
---|
54 | * |
---|
55 | * The macro name "V850_HAS_FPU" should be made CPU specific. |
---|
56 | * It indicates whether or not this CPU model has FP support. For |
---|
57 | * example, it would be possible to have an i386_nofp CPU model |
---|
58 | * which set this to false to indicate that you have an i386 without |
---|
59 | * an i387 and wish to leave floating point support out of RTEMS. |
---|
60 | */ |
---|
61 | |
---|
62 | /** |
---|
63 | * @def CPU_SOFTWARE_FP |
---|
64 | * |
---|
65 | * Does the CPU have no hardware floating point and GCC provides a |
---|
66 | * software floating point implementation which must be context |
---|
67 | * switched? |
---|
68 | * |
---|
69 | * This feature conditional is used to indicate whether or not there |
---|
70 | * is software implemented floating point that must be context |
---|
71 | * switched. The determination of whether or not this applies |
---|
72 | * is very tool specific and the state saved/restored is also |
---|
73 | * compiler specific. |
---|
74 | * |
---|
75 | * Port Specific Information: |
---|
76 | * |
---|
77 | * Some v850 models do have IEEE hardware floating point support but |
---|
78 | * they do not have any special registers to save or bit(s) which |
---|
79 | * determine if the FPU is enabled. In short, there appears to be nothing |
---|
80 | * related to the floating point operations which impact the RTEMS |
---|
81 | * thread context switch. Thus from an RTEMS perspective, there is really |
---|
82 | * no FPU to manage. |
---|
83 | */ |
---|
84 | #define CPU_HARDWARE_FP FALSE |
---|
85 | #define CPU_SOFTWARE_FP FALSE |
---|
86 | |
---|
87 | /** |
---|
88 | * Are all tasks RTEMS_FLOATING_POINT tasks implicitly? |
---|
89 | * |
---|
90 | * If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed. |
---|
91 | * If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed. |
---|
92 | * |
---|
93 | * So far, the only CPUs in which this option has been used are the |
---|
94 | * HP PA-RISC and PowerPC. On the PA-RISC, The HP C compiler and |
---|
95 | * gcc both implicitly used the floating point registers to perform |
---|
96 | * integer multiplies. Similarly, the PowerPC port of gcc has been |
---|
97 | * seen to allocate floating point local variables and touch the FPU |
---|
98 | * even when the flow through a subroutine (like vfprintf()) might |
---|
99 | * not use floating point formats. |
---|
100 | * |
---|
101 | * If a function which you would not think utilize the FP unit DOES, |
---|
102 | * then one can not easily predict which tasks will use the FP hardware. |
---|
103 | * In this case, this option should be TRUE. |
---|
104 | * |
---|
105 | * If @ref CPU_HARDWARE_FP is FALSE, then this should be FALSE as well. |
---|
106 | * |
---|
107 | * Port Specific Information: |
---|
108 | * |
---|
109 | * This should be false until it has been demonstrated that gcc for the |
---|
110 | * v850 generates FPU code when it is unexpected. But even this would |
---|
111 | * not matter since there are no FP specific registers or bits which |
---|
112 | * would be corrupted if an FP operation occurred in an integer only |
---|
113 | * thread. |
---|
114 | */ |
---|
115 | #define CPU_ALL_TASKS_ARE_FP FALSE |
---|
116 | |
---|
117 | /** |
---|
118 | * Should the IDLE task have a floating point context? |
---|
119 | * |
---|
120 | * If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task |
---|
121 | * and it has a floating point context which is switched in and out. |
---|
122 | * If FALSE, then the IDLE task does not have a floating point context. |
---|
123 | * |
---|
124 | * Setting this to TRUE negatively impacts the time required to preempt |
---|
125 | * the IDLE task from an interrupt because the floating point context |
---|
126 | * must be saved as part of the preemption. |
---|
127 | * |
---|
128 | * Port Specific Information: |
---|
129 | * |
---|
130 | * The IDLE thread should not be using the FPU. Leave this off. |
---|
131 | */ |
---|
132 | #define CPU_IDLE_TASK_IS_FP FALSE |
---|
133 | |
---|
134 | /** |
---|
135 | * Should the saving of the floating point registers be deferred |
---|
136 | * until a context switch is made to another different floating point |
---|
137 | * task? |
---|
138 | * |
---|
139 | * If TRUE, then the floating point context will not be stored until |
---|
140 | * necessary. It will remain in the floating point registers and not |
---|
141 | * disturned until another floating point task is switched to. |
---|
142 | * |
---|
143 | * If FALSE, then the floating point context is saved when a floating |
---|
144 | * point task is switched out and restored when the next floating point |
---|
145 | * task is restored. The state of the floating point registers between |
---|
146 | * those two operations is not specified. |
---|
147 | * |
---|
148 | * If the floating point context does NOT have to be saved as part of |
---|
149 | * interrupt dispatching, then it should be safe to set this to TRUE. |
---|
150 | * |
---|
151 | * Setting this flag to TRUE results in using a different algorithm |
---|
152 | * for deciding when to save and restore the floating point context. |
---|
153 | * The deferred FP switch algorithm minimizes the number of times |
---|
154 | * the FP context is saved and restored. The FP context is not saved |
---|
155 | * until a context switch is made to another, different FP task. |
---|
156 | * Thus in a system with only one FP task, the FP context will never |
---|
157 | * be saved or restored. |
---|
158 | * |
---|
159 | * Port Specific Information: |
---|
160 | * |
---|
161 | * See earlier comments. There is no FPU state to manage. |
---|
162 | */ |
---|
163 | #define CPU_USE_DEFERRED_FP_SWITCH TRUE |
---|
164 | |
---|
165 | #define CPU_ENABLE_ROBUST_THREAD_DISPATCH FALSE |
---|
166 | |
---|
167 | /** |
---|
168 | * Does this port provide a CPU dependent IDLE task implementation? |
---|
169 | * |
---|
170 | * If TRUE, then the routine @ref _CPU_Thread_Idle_body |
---|
171 | * must be provided and is the default IDLE thread body instead of |
---|
172 | * @ref _CPU_Thread_Idle_body. |
---|
173 | * |
---|
174 | * If FALSE, then use the generic IDLE thread body if the BSP does |
---|
175 | * not provide one. |
---|
176 | * |
---|
177 | * This is intended to allow for supporting processors which have |
---|
178 | * a low power or idle mode. When the IDLE thread is executed, then |
---|
179 | * the CPU can be powered down. |
---|
180 | * |
---|
181 | * The order of precedence for selecting the IDLE thread body is: |
---|
182 | * |
---|
183 | * -# BSP provided |
---|
184 | * -# CPU dependent (if provided) |
---|
185 | * -# generic (if no BSP and no CPU dependent) |
---|
186 | * |
---|
187 | * Port Specific Information: |
---|
188 | * |
---|
189 | * There does not appear to be a reason for the v850 port itself to provide |
---|
190 | * a special idle task. |
---|
191 | */ |
---|
192 | #define CPU_PROVIDES_IDLE_THREAD_BODY FALSE |
---|
193 | |
---|
194 | /** |
---|
195 | * Does the stack grow up (toward higher addresses) or down |
---|
196 | * (toward lower addresses)? |
---|
197 | * |
---|
198 | * If TRUE, then the grows upward. |
---|
199 | * If FALSE, then the grows toward smaller addresses. |
---|
200 | * |
---|
201 | * Port Specific Information: |
---|
202 | * |
---|
203 | * The v850 stack grows from high addresses to low addresses. |
---|
204 | */ |
---|
205 | #define CPU_STACK_GROWS_UP FALSE |
---|
206 | |
---|
207 | /* FIXME: Is this the right value? */ |
---|
208 | #define CPU_CACHE_LINE_BYTES 32 |
---|
209 | |
---|
210 | #define CPU_STRUCTURE_ALIGNMENT |
---|
211 | |
---|
212 | /** |
---|
213 | * @ingroup CPUInterrupt |
---|
214 | * The following defines the number of bits actually used in the |
---|
215 | * interrupt field of the task mode. How those bits map to the |
---|
216 | * CPU interrupt levels is defined by the routine @ref _CPU_ISR_Set_level. |
---|
217 | * |
---|
218 | * Port Specific Information: |
---|
219 | * |
---|
220 | * The v850 only has a single bit in the CPU for interrupt disable/enable. |
---|
221 | */ |
---|
222 | #define CPU_MODES_INTERRUPT_MASK 0x00000001 |
---|
223 | |
---|
224 | #define CPU_MAXIMUM_PROCESSORS 32 |
---|
225 | |
---|
226 | /** |
---|
227 | * @defgroup CPUContext Processor Dependent Context Management |
---|
228 | * |
---|
229 | * From the highest level viewpoint, there are 2 types of context to save. |
---|
230 | * |
---|
231 | * -# Interrupt registers to save |
---|
232 | * -# Task level registers to save |
---|
233 | * |
---|
234 | * Since RTEMS handles integer and floating point contexts separately, this |
---|
235 | * means we have the following 3 context items: |
---|
236 | * |
---|
237 | * -# task level context stuff:: Context_Control |
---|
238 | * -# floating point task stuff:: Context_Control_fp |
---|
239 | * -# special interrupt level context :: CPU_Interrupt_frame |
---|
240 | * |
---|
241 | * On some processors, it is cost-effective to save only the callee |
---|
242 | * preserved registers during a task context switch. This means |
---|
243 | * that the ISR code needs to save those registers which do not |
---|
244 | * persist across function calls. It is not mandatory to make this |
---|
245 | * distinctions between the caller/callee saves registers for the |
---|
246 | * purpose of minimizing context saved during task switch and on interrupts. |
---|
247 | * If the cost of saving extra registers is minimal, simplicity is the |
---|
248 | * choice. Save the same context on interrupt entry as for tasks in |
---|
249 | * this case. |
---|
250 | * |
---|
251 | * Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then |
---|
252 | * care should be used in designing the context area. |
---|
253 | * |
---|
254 | * On some CPUs with hardware floating point support, the Context_Control_fp |
---|
255 | * structure will not be used or it simply consist of an array of a |
---|
256 | * fixed number of bytes. This is done when the floating point context |
---|
257 | * is dumped by a "FP save context" type instruction and the format |
---|
258 | * is not really defined by the CPU. In this case, there is no need |
---|
259 | * to figure out the exact format -- only the size. Of course, although |
---|
260 | * this is enough information for RTEMS, it is probably not enough for |
---|
261 | * a debugger such as gdb. But that is another problem. |
---|
262 | * |
---|
263 | * Port Specific Information: |
---|
264 | * |
---|
265 | * On the v850, this port saves special registers and those that are |
---|
266 | * callee saved. |
---|
267 | */ |
---|
268 | /**@{**/ |
---|
269 | |
---|
270 | /** |
---|
271 | * This defines the minimal set of integer and processor state registers |
---|
272 | * that must be saved during a voluntary context switch from one thread |
---|
273 | * to another. |
---|
274 | */ |
---|
275 | typedef struct { |
---|
276 | uint32_t r1; |
---|
277 | /** This field is the stack pointer (e.g. r3). */ |
---|
278 | uint32_t r3_stack_pointer; |
---|
279 | uint32_t r20; |
---|
280 | uint32_t r21; |
---|
281 | uint32_t r22; |
---|
282 | uint32_t r23; |
---|
283 | uint32_t r24; |
---|
284 | uint32_t r25; |
---|
285 | uint32_t r26; |
---|
286 | uint32_t r27; |
---|
287 | uint32_t r28; |
---|
288 | uint32_t r29; |
---|
289 | uint32_t r31; |
---|
290 | uint32_t psw; |
---|
291 | } Context_Control; |
---|
292 | |
---|
293 | /** |
---|
294 | * This macro returns the stack pointer associated with @a _context. |
---|
295 | * |
---|
296 | * @param[in] _context is the thread context area to access |
---|
297 | * |
---|
298 | * @return This method returns the stack pointer. |
---|
299 | */ |
---|
300 | #define _CPU_Context_Get_SP( _context ) \ |
---|
301 | (_context)->r3_stack_pointer |
---|
302 | |
---|
303 | /** |
---|
304 | * This defines the complete set of floating point registers that must |
---|
305 | * be saved during any context switch from one thread to another. |
---|
306 | */ |
---|
307 | typedef struct { |
---|
308 | /** FPU registers are listed here */ |
---|
309 | double some_float_register; |
---|
310 | } Context_Control_fp; |
---|
311 | |
---|
312 | /** |
---|
313 | * This defines the set of integer and processor state registers that must |
---|
314 | * be saved during an interrupt. This set does not include any which are |
---|
315 | * in @ref Context_Control. |
---|
316 | */ |
---|
317 | typedef struct { |
---|
318 | /** This field is a hint that a port will have a number of integer |
---|
319 | * registers that need to be saved when an interrupt occurs or |
---|
320 | * when a context switch occurs at the end of an ISR. |
---|
321 | */ |
---|
322 | uint32_t special_interrupt_register; |
---|
323 | } CPU_Interrupt_frame; |
---|
324 | |
---|
325 | /** @} */ |
---|
326 | |
---|
327 | /** |
---|
328 | * @defgroup CPUInterrupt Processor Dependent Interrupt Management |
---|
329 | */ |
---|
330 | /**@{**/ |
---|
331 | |
---|
332 | /** |
---|
333 | * @ingroup CPUContext |
---|
334 | * The size of the floating point context area. On some CPUs this |
---|
335 | * will not be a "sizeof" because the format of the floating point |
---|
336 | * area is not defined -- only the size is. This is usually on |
---|
337 | * CPUs with a "floating point save context" instruction. |
---|
338 | * |
---|
339 | * Port Specific Information: |
---|
340 | * |
---|
341 | * The v850 does not need a floating point context but this needs to be |
---|
342 | * defined so confdefs.h. |
---|
343 | */ |
---|
344 | /* #define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp ) */ |
---|
345 | #define CPU_CONTEXT_FP_SIZE 0 |
---|
346 | |
---|
347 | /** |
---|
348 | * Amount of extra stack (above minimum stack size) required by |
---|
349 | * MPCI receive server thread. Remember that in a multiprocessor |
---|
350 | * system this thread must exist and be able to process all directives. |
---|
351 | * |
---|
352 | * Port Specific Information: |
---|
353 | * |
---|
354 | * There is no reason to think the v850 needs extra MPCI receive |
---|
355 | * server stack. |
---|
356 | */ |
---|
357 | #define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0 |
---|
358 | |
---|
359 | /** |
---|
360 | * This is defined if the port has a special way to report the ISR nesting |
---|
361 | * level. Most ports maintain the variable @a _ISR_Nest_level. |
---|
362 | */ |
---|
363 | #define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE |
---|
364 | |
---|
365 | /** @} */ |
---|
366 | |
---|
367 | /** |
---|
368 | * @ingroup CPUContext |
---|
369 | * Should be large enough to run all RTEMS tests. This ensures |
---|
370 | * that a "reasonable" small application should not have any problems. |
---|
371 | * |
---|
372 | * Port Specific Information: |
---|
373 | * |
---|
374 | * This should be very conservative on the v850. |
---|
375 | */ |
---|
376 | #define CPU_STACK_MINIMUM_SIZE (1024*4) |
---|
377 | |
---|
378 | #define CPU_SIZEOF_POINTER 4 |
---|
379 | |
---|
380 | /** |
---|
381 | * CPU's worst alignment requirement for data types on a byte boundary. This |
---|
382 | * alignment does not take into account the requirements for the stack. |
---|
383 | * |
---|
384 | * Port Specific Information: |
---|
385 | * |
---|
386 | * There is no apparent reason why this should be larger than 8. |
---|
387 | */ |
---|
388 | #define CPU_ALIGNMENT 8 |
---|
389 | |
---|
390 | /** |
---|
391 | * This number corresponds to the byte alignment requirement for the |
---|
392 | * heap handler. This alignment requirement may be stricter than that |
---|
393 | * for the data types alignment specified by @ref CPU_ALIGNMENT. It is |
---|
394 | * common for the heap to follow the same alignment requirement as |
---|
395 | * @ref CPU_ALIGNMENT. If the @ref CPU_ALIGNMENT is strict enough for |
---|
396 | * the heap, then this should be set to @ref CPU_ALIGNMENT. |
---|
397 | * |
---|
398 | * @note This does not have to be a power of 2 although it should be |
---|
399 | * a multiple of 2 greater than or equal to 2. The requirement |
---|
400 | * to be a multiple of 2 is because the heap uses the least |
---|
401 | * significant field of the front and back flags to indicate |
---|
402 | * that a block is in use or free. So you do not want any odd |
---|
403 | * length blocks really putting length data in that bit. |
---|
404 | * |
---|
405 | * On byte oriented architectures, @ref CPU_HEAP_ALIGNMENT normally will |
---|
406 | * have to be greater or equal to than @ref CPU_ALIGNMENT to ensure that |
---|
407 | * elements allocated from the heap meet all restrictions. |
---|
408 | * |
---|
409 | * Port Specific Information: |
---|
410 | * |
---|
411 | * There is no apparent reason why this should be larger than CPU_ALIGNMENT. |
---|
412 | */ |
---|
413 | #define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT |
---|
414 | |
---|
415 | /** |
---|
416 | * This number corresponds to the byte alignment requirement for memory |
---|
417 | * buffers allocated by the partition manager. This alignment requirement |
---|
418 | * may be stricter than that for the data types alignment specified by |
---|
419 | * @ref CPU_ALIGNMENT. It is common for the partition to follow the same |
---|
420 | * alignment requirement as @ref CPU_ALIGNMENT. If the @ref CPU_ALIGNMENT is |
---|
421 | * strict enough for the partition, then this should be set to |
---|
422 | * @ref CPU_ALIGNMENT. |
---|
423 | * |
---|
424 | * @note This does not have to be a power of 2. It does have to |
---|
425 | * be greater or equal to than @ref CPU_ALIGNMENT. |
---|
426 | * |
---|
427 | * Port Specific Information: |
---|
428 | * |
---|
429 | * There is no apparent reason why this should be larger than CPU_ALIGNMENT. |
---|
430 | */ |
---|
431 | #define CPU_PARTITION_ALIGNMENT CPU_ALIGNMENT |
---|
432 | |
---|
433 | /** |
---|
434 | * This number corresponds to the byte alignment requirement for the |
---|
435 | * stack. This alignment requirement may be stricter than that for the |
---|
436 | * data types alignment specified by @ref CPU_ALIGNMENT. If the |
---|
437 | * @ref CPU_ALIGNMENT is strict enough for the stack, then this should be |
---|
438 | * set to 0. |
---|
439 | * |
---|
440 | * @note This must be a power of 2 either 0 or greater than @ref CPU_ALIGNMENT. |
---|
441 | * |
---|
442 | * Port Specific Information: |
---|
443 | * |
---|
444 | * The v850 has enough RAM where alignment to 16 may be desirable depending |
---|
445 | * on the cache properties. But this remains to be demonstrated. |
---|
446 | */ |
---|
447 | #define CPU_STACK_ALIGNMENT 4 |
---|
448 | |
---|
449 | #define CPU_INTERRUPT_STACK_ALIGNMENT CPU_CACHE_LINE_BYTES |
---|
450 | |
---|
451 | /* |
---|
452 | * ISR handler macros |
---|
453 | */ |
---|
454 | |
---|
455 | /** |
---|
456 | * @addtogroup CPUInterrupt |
---|
457 | */ |
---|
458 | /**@{**/ |
---|
459 | |
---|
460 | /** |
---|
461 | * Disable all interrupts for an RTEMS critical section. The previous |
---|
462 | * level is returned in @a _isr_cookie. |
---|
463 | * |
---|
464 | * @param[out] _isr_cookie will contain the previous level cookie |
---|
465 | * |
---|
466 | * Port Specific Information: |
---|
467 | * |
---|
468 | * On the v850, we need to save the PSW and use "di" to disable interrupts. |
---|
469 | */ |
---|
470 | #define _CPU_ISR_Disable( _isr_cookie ) \ |
---|
471 | do { \ |
---|
472 | unsigned int _psw; \ |
---|
473 | \ |
---|
474 | v850_get_psw( _psw ); \ |
---|
475 | __asm__ __volatile__( "di" ); \ |
---|
476 | _isr_cookie = _psw; \ |
---|
477 | } while (0) |
---|
478 | |
---|
479 | /** |
---|
480 | * Enable interrupts to the previous level (returned by _CPU_ISR_Disable). |
---|
481 | * This indicates the end of an RTEMS critical section. The parameter |
---|
482 | * @a _isr_cookie is not modified. |
---|
483 | * |
---|
484 | * @param[in] _isr_cookie contain the previous level cookie |
---|
485 | * |
---|
486 | * Port Specific Information: |
---|
487 | * |
---|
488 | * On the v850, we simply need to restore the PSW. |
---|
489 | */ |
---|
490 | #define _CPU_ISR_Enable( _isr_cookie ) \ |
---|
491 | do { \ |
---|
492 | unsigned int _psw = (_isr_cookie); \ |
---|
493 | \ |
---|
494 | v850_set_psw( _psw ); \ |
---|
495 | } while (0) |
---|
496 | |
---|
497 | /** |
---|
498 | * This temporarily restores the interrupt to @a _isr_cookie before immediately |
---|
499 | * disabling them again. This is used to divide long RTEMS critical |
---|
500 | * sections into two or more parts. The parameter @a _isr_cookie is not |
---|
501 | * modified. |
---|
502 | * |
---|
503 | * @param[in] _isr_cookie contain the previous level cookie |
---|
504 | * |
---|
505 | * Port Specific Information: |
---|
506 | * |
---|
507 | * This saves at least one instruction over using enable/disable back to back. |
---|
508 | */ |
---|
509 | #define _CPU_ISR_Flash( _isr_cookie ) \ |
---|
510 | do { \ |
---|
511 | unsigned int _psw = (_isr_cookie); \ |
---|
512 | v850_set_psw( _psw ); \ |
---|
513 | __asm__ __volatile__( "di" ); \ |
---|
514 | } while (0) |
---|
515 | |
---|
516 | RTEMS_INLINE_ROUTINE bool _CPU_ISR_Is_enabled( uint32_t level ) |
---|
517 | { |
---|
518 | return ( level & V850_PSW_INTERRUPT_DISABLE_MASK ) |
---|
519 | != V850_PSW_INTERRUPT_DISABLE; |
---|
520 | } |
---|
521 | |
---|
522 | /** |
---|
523 | * This routine and @ref _CPU_ISR_Get_level |
---|
524 | * Map the interrupt level in task mode onto the hardware that the CPU |
---|
525 | * actually provides. Currently, interrupt levels which do not |
---|
526 | * map onto the CPU in a generic fashion are undefined. Someday, |
---|
527 | * it would be nice if these were "mapped" by the application |
---|
528 | * via a callout. For example, m68k has 8 levels 0 - 7, levels |
---|
529 | * 8 - 255 would be available for bsp/application specific meaning. |
---|
530 | * This could be used to manage a programmable interrupt controller |
---|
531 | * via the rtems_task_mode directive. |
---|
532 | * |
---|
533 | * Port Specific Information: |
---|
534 | * |
---|
535 | * On the v850, level 0 is enabled. Non-zero is disabled. |
---|
536 | */ |
---|
537 | #define _CPU_ISR_Set_level( new_level ) \ |
---|
538 | do { \ |
---|
539 | if ( new_level ) \ |
---|
540 | __asm__ __volatile__( "di" ); \ |
---|
541 | else \ |
---|
542 | __asm__ __volatile__( "ei" ); \ |
---|
543 | } while (0) |
---|
544 | |
---|
545 | /** |
---|
546 | * Return the current interrupt disable level for this task in |
---|
547 | * the format used by the interrupt level portion of the task mode. |
---|
548 | * |
---|
549 | * @note This routine usually must be implemented as a subroutine. |
---|
550 | * |
---|
551 | * Port Specific Information: |
---|
552 | * |
---|
553 | * This method is implemented in C on the v850. |
---|
554 | */ |
---|
555 | uint32_t _CPU_ISR_Get_level( void ); |
---|
556 | |
---|
557 | /* end of ISR handler macros */ |
---|
558 | |
---|
559 | /** @} */ |
---|
560 | |
---|
561 | /* Context handler macros */ |
---|
562 | |
---|
563 | /** |
---|
564 | * @ingroup CPUContext |
---|
565 | * Initialize the context to a state suitable for starting a |
---|
566 | * task after a context restore operation. Generally, this |
---|
567 | * involves: |
---|
568 | * |
---|
569 | * - setting a starting address |
---|
570 | * - preparing the stack |
---|
571 | * - preparing the stack and frame pointers |
---|
572 | * - setting the proper interrupt level in the context |
---|
573 | * - initializing the floating point context |
---|
574 | * |
---|
575 | * This routine generally does not set any unnecessary register |
---|
576 | * in the context. The state of the "general data" registers is |
---|
577 | * undefined at task start time. |
---|
578 | * |
---|
579 | * @param[in] _the_context is the context structure to be initialized |
---|
580 | * @param[in] _stack_base is the lowest physical address of this task's stack |
---|
581 | * @param[in] _size is the size of this task's stack |
---|
582 | * @param[in] _isr is the interrupt disable level |
---|
583 | * @param[in] _entry_point is the thread's entry point. This is |
---|
584 | * always @a _Thread_Handler |
---|
585 | * @param[in] _is_fp is TRUE if the thread is to be a floating |
---|
586 | * point thread. This is typically only used on CPUs where the |
---|
587 | * FPU may be easily disabled by software such as on the SPARC |
---|
588 | * where the PSR contains an enable FPU bit. |
---|
589 | * @param[in] tls_area is the thread-local storage (TLS) area |
---|
590 | * |
---|
591 | * Port Specific Information: |
---|
592 | * |
---|
593 | * This method is implemented in C on the v850. |
---|
594 | */ |
---|
595 | void _CPU_Context_Initialize( |
---|
596 | Context_Control *the_context, |
---|
597 | uint32_t *stack_base, |
---|
598 | uint32_t size, |
---|
599 | uint32_t new_level, |
---|
600 | void *entry_point, |
---|
601 | bool is_fp, |
---|
602 | void *tls_area |
---|
603 | ); |
---|
604 | |
---|
605 | /** |
---|
606 | * This routine is responsible for somehow restarting the currently |
---|
607 | * executing task. If you are lucky, then all that is necessary |
---|
608 | * is restoring the context. Otherwise, there will need to be |
---|
609 | * a special assembly routine which does something special in this |
---|
610 | * case. For many ports, simply adding a label to the restore path |
---|
611 | * of @ref _CPU_Context_switch will work. On other ports, it may be |
---|
612 | * possibly to load a few arguments and jump to the restore path. It will |
---|
613 | * not work if restarting self conflicts with the stack frame |
---|
614 | * assumptions of restoring a context. |
---|
615 | * |
---|
616 | * Port Specific Information: |
---|
617 | * |
---|
618 | * On the v850, we require a special entry point to restart a task. |
---|
619 | */ |
---|
620 | #define _CPU_Context_Restart_self( _the_context ) \ |
---|
621 | _CPU_Context_restore( (_the_context) ); |
---|
622 | |
---|
623 | /* XXX this should be possible to remove */ |
---|
624 | #if 0 |
---|
625 | /** |
---|
626 | * This routine initializes the FP context area passed to it to. |
---|
627 | * There are a few standard ways in which to initialize the |
---|
628 | * floating point context. The code included for this macro assumes |
---|
629 | * that this is a CPU in which a "initial" FP context was saved into |
---|
630 | * @a _CPU_Null_fp_context and it simply copies it to the destination |
---|
631 | * context passed to it. |
---|
632 | * |
---|
633 | * Other floating point context save/restore models include: |
---|
634 | * -# not doing anything, and |
---|
635 | * -# putting a "null FP status word" in the correct place in the FP context. |
---|
636 | * |
---|
637 | * @param[in] _destination is the floating point context area |
---|
638 | * |
---|
639 | * Port Specific Information: |
---|
640 | * |
---|
641 | * XXX document implementation including references if appropriate |
---|
642 | */ |
---|
643 | #define _CPU_Context_Initialize_fp( _destination ) \ |
---|
644 | { \ |
---|
645 | } |
---|
646 | #endif |
---|
647 | |
---|
648 | /* end of Context handler macros */ |
---|
649 | |
---|
650 | /* Fatal Error manager macros */ |
---|
651 | |
---|
652 | /** |
---|
653 | * This routine copies _error into a known place -- typically a stack |
---|
654 | * location or a register, optionally disables interrupts, and |
---|
655 | * halts/stops the CPU. |
---|
656 | * |
---|
657 | * Port Specific Information: |
---|
658 | * |
---|
659 | * Move the error code into r10, disable interrupts and halt. |
---|
660 | */ |
---|
661 | #define _CPU_Fatal_halt( _source, _error ) \ |
---|
662 | do { \ |
---|
663 | __asm__ __volatile__ ( "di" ); \ |
---|
664 | __asm__ __volatile__ ( "mov %0, r10; " : "=r" ((_error)) ); \ |
---|
665 | __asm__ __volatile__ ( "halt" ); \ |
---|
666 | } while (0) |
---|
667 | |
---|
668 | /* end of Fatal Error manager macros */ |
---|
669 | |
---|
670 | #define CPU_USE_GENERIC_BITFIELD_CODE TRUE |
---|
671 | |
---|
672 | /* functions */ |
---|
673 | |
---|
674 | /** |
---|
675 | * @brief CPU initialize. |
---|
676 | * This routine performs CPU dependent initialization. |
---|
677 | * |
---|
678 | * Port Specific Information: |
---|
679 | * |
---|
680 | * This is implemented in C. |
---|
681 | * |
---|
682 | * v850 CPU Dependent Source |
---|
683 | */ |
---|
684 | void _CPU_Initialize(void); |
---|
685 | |
---|
686 | /** |
---|
687 | * @addtogroup CPUContext |
---|
688 | */ |
---|
689 | /**@{**/ |
---|
690 | |
---|
691 | /** |
---|
692 | * This routine switches from the run context to the heir context. |
---|
693 | * |
---|
694 | * @param[in] run points to the context of the currently executing task |
---|
695 | * @param[in] heir points to the context of the heir task |
---|
696 | * |
---|
697 | * Port Specific Information: |
---|
698 | * |
---|
699 | * This is implemented in assembly on the v850. |
---|
700 | */ |
---|
701 | void _CPU_Context_switch( |
---|
702 | Context_Control *run, |
---|
703 | Context_Control *heir |
---|
704 | ); |
---|
705 | |
---|
706 | /** |
---|
707 | * This routine is generally used only to restart self in an |
---|
708 | * efficient manner. It may simply be a label in @ref _CPU_Context_switch. |
---|
709 | * |
---|
710 | * @param[in] new_context points to the context to be restored. |
---|
711 | * |
---|
712 | * @note May be unnecessary to reload some registers. |
---|
713 | * |
---|
714 | * Port Specific Information: |
---|
715 | * |
---|
716 | * This is implemented in assembly on the v850. |
---|
717 | */ |
---|
718 | void _CPU_Context_restore( |
---|
719 | Context_Control *new_context |
---|
720 | ) RTEMS_NO_RETURN; |
---|
721 | |
---|
722 | /* XXX this should be possible to remove */ |
---|
723 | #if 0 |
---|
724 | /** |
---|
725 | * This routine saves the floating point context passed to it. |
---|
726 | * |
---|
727 | * @param[in] fp_context_ptr is a pointer to a pointer to a floating |
---|
728 | * point context area |
---|
729 | * |
---|
730 | * @return on output @a *fp_context_ptr will contain the address that |
---|
731 | * should be used with @ref _CPU_Context_restore_fp to restore this context. |
---|
732 | * |
---|
733 | * Port Specific Information: |
---|
734 | * |
---|
735 | * XXX document implementation including references if appropriate |
---|
736 | */ |
---|
737 | void _CPU_Context_save_fp( |
---|
738 | Context_Control_fp **fp_context_ptr |
---|
739 | ); |
---|
740 | #endif |
---|
741 | |
---|
742 | /* XXX this should be possible to remove */ |
---|
743 | #if 0 |
---|
744 | /** |
---|
745 | * This routine restores the floating point context passed to it. |
---|
746 | * |
---|
747 | * @param[in] fp_context_ptr is a pointer to a pointer to a floating |
---|
748 | * point context area to restore |
---|
749 | * |
---|
750 | * @return on output @a *fp_context_ptr will contain the address that |
---|
751 | * should be used with @ref _CPU_Context_save_fp to save this context. |
---|
752 | * |
---|
753 | * Port Specific Information: |
---|
754 | * |
---|
755 | * XXX document implementation including references if appropriate |
---|
756 | */ |
---|
757 | void _CPU_Context_restore_fp( |
---|
758 | Context_Control_fp **fp_context_ptr |
---|
759 | ); |
---|
760 | #endif |
---|
761 | |
---|
762 | static inline void _CPU_Context_volatile_clobber( uintptr_t pattern ) |
---|
763 | { |
---|
764 | /* TODO */ |
---|
765 | } |
---|
766 | |
---|
767 | static inline void _CPU_Context_validate( uintptr_t pattern ) |
---|
768 | { |
---|
769 | while (1) { |
---|
770 | /* TODO */ |
---|
771 | } |
---|
772 | } |
---|
773 | |
---|
774 | /** @} */ |
---|
775 | |
---|
776 | /* FIXME */ |
---|
777 | typedef CPU_Interrupt_frame CPU_Exception_frame; |
---|
778 | |
---|
779 | void _CPU_Exception_frame_print( const CPU_Exception_frame *frame ); |
---|
780 | |
---|
781 | /** |
---|
782 | * @ingroup CPUEndian |
---|
783 | * The following routine swaps the endian format of an unsigned int. |
---|
784 | * It must be static because it is referenced indirectly. |
---|
785 | * |
---|
786 | * This version will work on any processor, but if there is a better |
---|
787 | * way for your CPU PLEASE use it. The most common way to do this is to: |
---|
788 | * |
---|
789 | * swap least significant two bytes with 16-bit rotate |
---|
790 | * swap upper and lower 16-bits |
---|
791 | * swap most significant two bytes with 16-bit rotate |
---|
792 | * |
---|
793 | * Some CPUs have special instructions which swap a 32-bit quantity in |
---|
794 | * a single instruction (e.g. i486). It is probably best to avoid |
---|
795 | * an "endian swapping control bit" in the CPU. One good reason is |
---|
796 | * that interrupts would probably have to be disabled to ensure that |
---|
797 | * an interrupt does not try to access the same "chunk" with the wrong |
---|
798 | * endian. Another good reason is that on some CPUs, the endian bit |
---|
799 | * endianness for ALL fetches -- both code and data -- so the code |
---|
800 | * will be fetched incorrectly. |
---|
801 | * |
---|
802 | * @param[in] value is the value to be swapped |
---|
803 | * @return the value after being endian swapped |
---|
804 | * |
---|
805 | * Port Specific Information: |
---|
806 | * |
---|
807 | * The v850 has a single instruction to swap endianness on a 32 bit quantity. |
---|
808 | */ |
---|
809 | static inline uint32_t CPU_swap_u32( |
---|
810 | uint32_t value |
---|
811 | ) |
---|
812 | { |
---|
813 | unsigned int swapped; |
---|
814 | |
---|
815 | #if (V850_HAS_BYTE_SWAP_INSTRUCTION == 1) |
---|
816 | unsigned int v; |
---|
817 | |
---|
818 | v = value; |
---|
819 | __asm__ __volatile__ ("bsw %0, %1" : "=r" (v), "=&r" (swapped) ); |
---|
820 | #else |
---|
821 | uint32_t byte1, byte2, byte3, byte4; |
---|
822 | |
---|
823 | byte4 = (value >> 24) & 0xff; |
---|
824 | byte3 = (value >> 16) & 0xff; |
---|
825 | byte2 = (value >> 8) & 0xff; |
---|
826 | byte1 = value & 0xff; |
---|
827 | |
---|
828 | swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4; |
---|
829 | #endif |
---|
830 | return swapped; |
---|
831 | } |
---|
832 | |
---|
833 | /** |
---|
834 | * @ingroup CPUEndian |
---|
835 | * This routine swaps a 16 bir quantity. |
---|
836 | * |
---|
837 | * @param[in] value is the value to be swapped |
---|
838 | * @return the value after being endian swapped |
---|
839 | * |
---|
840 | * Port Specific Information: |
---|
841 | * |
---|
842 | * The v850 has a single instruction to swap endianness on a 16 bit quantity. |
---|
843 | */ |
---|
844 | static inline uint16_t CPU_swap_u16( uint16_t value ) |
---|
845 | { |
---|
846 | unsigned int swapped; |
---|
847 | |
---|
848 | #if (V850_HAS_BYTE_SWAP_INSTRUCTION == 1) |
---|
849 | unsigned int v; |
---|
850 | |
---|
851 | v = value; |
---|
852 | __asm__ __volatile__ ("bsh %0, %1" : "=r" (v), "=&r" (swapped) ); |
---|
853 | #else |
---|
854 | swapped = ((value & 0xff) << 8) | ((value >> 8) & 0xff); |
---|
855 | #endif |
---|
856 | return swapped; |
---|
857 | } |
---|
858 | |
---|
859 | typedef uint32_t CPU_Counter_ticks; |
---|
860 | |
---|
861 | uint32_t _CPU_Counter_frequency( void ); |
---|
862 | |
---|
863 | CPU_Counter_ticks _CPU_Counter_read( void ); |
---|
864 | |
---|
865 | static inline CPU_Counter_ticks _CPU_Counter_difference( |
---|
866 | CPU_Counter_ticks second, |
---|
867 | CPU_Counter_ticks first |
---|
868 | ) |
---|
869 | { |
---|
870 | return second - first; |
---|
871 | } |
---|
872 | |
---|
873 | /** Type that can store a 32-bit integer or a pointer. */ |
---|
874 | typedef uintptr_t CPU_Uint32ptr; |
---|
875 | |
---|
876 | #ifdef __cplusplus |
---|
877 | } |
---|
878 | #endif |
---|
879 | |
---|
880 | #endif |
---|