[ac7d5ef0] | 1 | /* cpu.h |
---|
| 2 | * |
---|
| 3 | * This include file contains information pertaining to the HP |
---|
| 4 | * PA-RISC processor (Level 1.1). |
---|
| 5 | * |
---|
| 6 | * COPYRIGHT (c) 1994 by Division Incorporated |
---|
| 7 | * |
---|
| 8 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
| 9 | * without any express or implied warranty: |
---|
| 10 | * permission to use, copy, modify, and distribute this file |
---|
| 11 | * for any purpose is hereby granted without fee, provided that |
---|
| 12 | * the above copyright notice and this notice appears in all |
---|
| 13 | * copies, and that the name of Division Incorporated not be |
---|
| 14 | * used in advertising or publicity pertaining to distribution |
---|
| 15 | * of the software without specific, written prior permission. |
---|
| 16 | * Division Incorporated makes no representations about the |
---|
| 17 | * suitability of this software for any purpose. |
---|
| 18 | * |
---|
| 19 | * $Id$ |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #ifndef __CPU_h |
---|
| 23 | #define __CPU_h |
---|
| 24 | |
---|
| 25 | #ifdef __cplusplus |
---|
| 26 | extern "C" { |
---|
| 27 | #endif |
---|
| 28 | |
---|
| 29 | #include <setjmp.h> |
---|
[88d594a] | 30 | #include <rtems/unix.h> |
---|
| 31 | #ifndef ASM |
---|
| 32 | #include <rtems/unixtypes.h> |
---|
| 33 | #endif |
---|
[ac7d5ef0] | 34 | |
---|
| 35 | /* conditional compilation parameters */ |
---|
| 36 | |
---|
| 37 | /* |
---|
| 38 | * Should the calls to _Thread_Enable_dispatch be inlined? |
---|
| 39 | * |
---|
| 40 | * If TRUE, then they are inlined. |
---|
| 41 | * If FALSE, then a subroutine call is made. |
---|
| 42 | * |
---|
| 43 | * Basically this is an example of the classic trade-off of size |
---|
| 44 | * versus speed. Inlining the call (TRUE) typically increases the |
---|
| 45 | * size of RTEMS while speeding up the enabling of dispatching. |
---|
| 46 | * [NOTE: In general, the _Thread_Dispatch_disable_level will |
---|
| 47 | * only be 0 or 1 unless you are in an interrupt handler and that |
---|
| 48 | * interrupt handler invokes the executive.] When not inlined |
---|
| 49 | * something calls _Thread_Enable_dispatch which in turns calls |
---|
| 50 | * _Thread_Dispatch. If the enable dispatch is inlined, then |
---|
| 51 | * one subroutine call is avoided entirely.] |
---|
| 52 | */ |
---|
| 53 | |
---|
| 54 | #define CPU_INLINE_ENABLE_DISPATCH FALSE |
---|
| 55 | |
---|
| 56 | /* |
---|
| 57 | * Should the body of the search loops in _Thread_queue_Enqueue_priority |
---|
| 58 | * be unrolled one time? In unrolled each iteration of the loop examines |
---|
| 59 | * two "nodes" on the chain being searched. Otherwise, only one node |
---|
| 60 | * is examined per iteration. |
---|
| 61 | * |
---|
| 62 | * If TRUE, then the loops are unrolled. |
---|
| 63 | * If FALSE, then the loops are not unrolled. |
---|
| 64 | * |
---|
| 65 | * The primary factor in making this decision is the cost of disabling |
---|
| 66 | * and enabling interrupts (_ISR_Flash) versus the cost of rest of the |
---|
| 67 | * body of the loop. On some CPUs, the flash is more expensive than |
---|
| 68 | * one iteration of the loop body. In this case, it might be desirable |
---|
| 69 | * to unroll the loop. It is important to note that on some CPUs, this |
---|
| 70 | * code is the longest interrupt disable period in RTEMS. So it is |
---|
| 71 | * necessary to strike a balance when setting this parameter. |
---|
| 72 | */ |
---|
| 73 | |
---|
| 74 | #define CPU_UNROLL_ENQUEUE_PRIORITY TRUE |
---|
| 75 | |
---|
| 76 | /* |
---|
| 77 | * Does RTEMS manage a dedicated interrupt stack in software? |
---|
| 78 | * |
---|
| 79 | * If TRUE, then a stack is allocated in _Interrupt_Manager_initialization. |
---|
| 80 | * If FALSE, nothing is done. |
---|
| 81 | * |
---|
| 82 | * If the CPU supports a dedicated interrupt stack in hardware, |
---|
| 83 | * then it is generally the responsibility of the BSP to allocate it |
---|
| 84 | * and set it up. |
---|
| 85 | * |
---|
| 86 | * If the CPU does not support a dedicated interrupt stack, then |
---|
| 87 | * the porter has two options: (1) execute interrupts on the |
---|
| 88 | * stack of the interrupted task, and (2) have RTEMS manage a dedicated |
---|
| 89 | * interrupt stack. |
---|
| 90 | * |
---|
| 91 | * If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE. |
---|
| 92 | * |
---|
| 93 | * Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and |
---|
| 94 | * CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is |
---|
| 95 | * possible that both are FALSE for a particular CPU. Although it |
---|
| 96 | * is unclear what that would imply about the interrupt processing |
---|
| 97 | * procedure on that CPU. |
---|
| 98 | */ |
---|
| 99 | |
---|
| 100 | #define CPU_HAS_SOFTWARE_INTERRUPT_STACK FALSE |
---|
| 101 | |
---|
| 102 | /* |
---|
| 103 | * Does this CPU have hardware support for a dedicated interrupt stack? |
---|
| 104 | * |
---|
| 105 | * If TRUE, then it must be installed during initialization. |
---|
| 106 | * If FALSE, then no installation is performed. |
---|
| 107 | * |
---|
| 108 | * If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE. |
---|
| 109 | * |
---|
| 110 | * Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and |
---|
| 111 | * CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE. It is |
---|
| 112 | * possible that both are FALSE for a particular CPU. Although it |
---|
| 113 | * is unclear what that would imply about the interrupt processing |
---|
| 114 | * procedure on that CPU. |
---|
| 115 | */ |
---|
| 116 | |
---|
| 117 | #define CPU_HAS_HARDWARE_INTERRUPT_STACK TRUE |
---|
| 118 | |
---|
| 119 | /* |
---|
| 120 | * Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager? |
---|
| 121 | * |
---|
| 122 | * If TRUE, then the memory is allocated during initialization. |
---|
| 123 | * If FALSE, then the memory is allocated during initialization. |
---|
| 124 | * |
---|
| 125 | * This should be TRUE if CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE |
---|
| 126 | * or CPU_INSTALL_HARDWARE_INTERRUPT_STACK is TRUE. |
---|
| 127 | */ |
---|
| 128 | |
---|
| 129 | #define CPU_ALLOCATE_INTERRUPT_STACK FALSE |
---|
| 130 | |
---|
| 131 | /* |
---|
| 132 | * Does the CPU have hardware floating point? |
---|
| 133 | * |
---|
| 134 | * If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported. |
---|
| 135 | * If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored. |
---|
| 136 | * |
---|
| 137 | * If there is a FP coprocessor such as the i387 or mc68881, then |
---|
| 138 | * the answer is TRUE. |
---|
| 139 | * |
---|
| 140 | * The macro name "NO_CPU_HAS_FPU" should be made CPU specific. |
---|
| 141 | * It indicates whether or not this CPU model has FP support. For |
---|
| 142 | * example, it would be possible to have an i386_nofp CPU model |
---|
| 143 | * which set this to false to indicate that you have an i386 without |
---|
| 144 | * an i387 and wish to leave floating point support out of RTEMS. |
---|
| 145 | */ |
---|
| 146 | |
---|
| 147 | #define CPU_HARDWARE_FP TRUE |
---|
| 148 | |
---|
| 149 | /* |
---|
| 150 | * Are all tasks RTEMS_FLOATING_POINT tasks implicitly? |
---|
| 151 | * |
---|
| 152 | * If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed. |
---|
| 153 | * If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed. |
---|
| 154 | * |
---|
| 155 | * So far, the only CPU in which this option has been used is the |
---|
| 156 | * HP PA-RISC. The HP C compiler and gcc both implicitly use the |
---|
| 157 | * floating point registers to perform integer multiplies. If |
---|
| 158 | * a function which you would not think utilize the FP unit DOES, |
---|
| 159 | * then one can not easily predict which tasks will use the FP hardware. |
---|
| 160 | * In this case, this option should be TRUE. |
---|
| 161 | * |
---|
| 162 | * If CPU_HARDWARE_FP is FALSE, then this should be FALSE as well. |
---|
| 163 | */ |
---|
| 164 | |
---|
| 165 | #define CPU_ALL_TASKS_ARE_FP FALSE |
---|
| 166 | |
---|
| 167 | /* |
---|
| 168 | * Should the IDLE task have a floating point context? |
---|
| 169 | * |
---|
| 170 | * If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task |
---|
| 171 | * and it has a floating point context which is switched in and out. |
---|
| 172 | * If FALSE, then the IDLE task does not have a floating point context. |
---|
| 173 | * |
---|
| 174 | * Setting this to TRUE negatively impacts the time required to preempt |
---|
| 175 | * the IDLE task from an interrupt because the floating point context |
---|
| 176 | * must be saved as part of the preemption. |
---|
| 177 | */ |
---|
| 178 | |
---|
| 179 | #define CPU_IDLE_TASK_IS_FP FALSE |
---|
| 180 | |
---|
| 181 | /* |
---|
| 182 | * Should the saving of the floating point registers be deferred |
---|
| 183 | * until a context switch is made to another different floating point |
---|
| 184 | * task? |
---|
| 185 | * |
---|
| 186 | * If TRUE, then the floating point context will not be stored until |
---|
| 187 | * necessary. It will remain in the floating point registers and not |
---|
| 188 | * disturned until another floating point task is switched to. |
---|
| 189 | * |
---|
| 190 | * If FALSE, then the floating point context is saved when a floating |
---|
| 191 | * point task is switched out and restored when the next floating point |
---|
| 192 | * task is restored. The state of the floating point registers between |
---|
| 193 | * those two operations is not specified. |
---|
| 194 | * |
---|
| 195 | * If the floating point context does NOT have to be saved as part of |
---|
| 196 | * interrupt dispatching, then it should be safe to set this to TRUE. |
---|
| 197 | * |
---|
| 198 | * Setting this flag to TRUE results in using a different algorithm |
---|
| 199 | * for deciding when to save and restore the floating point context. |
---|
| 200 | * The deferred FP switch algorithm minimizes the number of times |
---|
| 201 | * the FP context is saved and restored. The FP context is not saved |
---|
| 202 | * until a context switch is made to another, different FP task. |
---|
| 203 | * Thus in a system with only one FP task, the FP context will never |
---|
| 204 | * be saved or restored. |
---|
| 205 | */ |
---|
| 206 | |
---|
| 207 | #define CPU_USE_DEFERRED_FP_SWITCH TRUE |
---|
| 208 | |
---|
| 209 | /* |
---|
| 210 | * Does this port provide a CPU dependent IDLE task implementation? |
---|
| 211 | * |
---|
| 212 | * If TRUE, then the routine _CPU_Internal_threads_Idle_thread_body |
---|
| 213 | * must be provided and is the default IDLE thread body instead of |
---|
| 214 | * _Internal_threads_Idle_thread_body. |
---|
| 215 | * |
---|
| 216 | * If FALSE, then use the generic IDLE thread body if the BSP does |
---|
| 217 | * not provide one. |
---|
| 218 | * |
---|
| 219 | * This is intended to allow for supporting processors which have |
---|
| 220 | * a low power or idle mode. When the IDLE thread is executed, then |
---|
| 221 | * the CPU can be powered down. |
---|
| 222 | * |
---|
| 223 | * The order of precedence for selecting the IDLE thread body is: |
---|
| 224 | * |
---|
| 225 | * 1. BSP provided |
---|
| 226 | * 2. CPU dependent (if provided) |
---|
| 227 | * 3. generic (if no BSP and no CPU dependent) |
---|
| 228 | */ |
---|
| 229 | |
---|
| 230 | #define CPU_PROVIDES_IDLE_THREAD_BODY TRUE |
---|
| 231 | |
---|
| 232 | /* |
---|
| 233 | * Does the stack grow up (toward higher addresses) or down |
---|
| 234 | * (toward lower addresses)? |
---|
| 235 | * |
---|
| 236 | * If TRUE, then the grows upward. |
---|
| 237 | * If FALSE, then the grows toward smaller addresses. |
---|
| 238 | */ |
---|
| 239 | |
---|
| 240 | #if defined(hppa1_1) |
---|
| 241 | #define CPU_STACK_GROWS_UP TRUE |
---|
| 242 | #elif defined(sparc) |
---|
| 243 | #define CPU_STACK_GROWS_UP FALSE |
---|
| 244 | #else |
---|
| 245 | #error "unknown CPU!!" |
---|
| 246 | #endif |
---|
| 247 | |
---|
| 248 | |
---|
| 249 | /* |
---|
| 250 | * The following is the variable attribute used to force alignment |
---|
| 251 | * of critical RTEMS structures. On some processors it may make |
---|
| 252 | * sense to have these aligned on tighter boundaries than |
---|
| 253 | * the minimum requirements of the compiler in order to have as |
---|
| 254 | * much of the critical data area as possible in a cache line. |
---|
| 255 | * |
---|
| 256 | * The placement of this macro in the declaration of the variables |
---|
| 257 | * is based on the syntactically requirements of the GNU C |
---|
| 258 | * "__attribute__" extension. For example with GNU C, use |
---|
| 259 | * the following to force a structures to a 32 byte boundary. |
---|
| 260 | * |
---|
| 261 | * __attribute__ ((aligned (32))) |
---|
| 262 | * |
---|
| 263 | * NOTE: Currently only the Priority Bit Map table uses this feature. |
---|
| 264 | * To benefit from using this, the data must be heavily |
---|
| 265 | * used so it will stay in the cache and used frequently enough |
---|
| 266 | * in the executive to justify turning this on. |
---|
| 267 | */ |
---|
| 268 | |
---|
| 269 | #define CPU_STRUCTURE_ALIGNMENT __attribute__ ((aligned (32))) |
---|
| 270 | |
---|
| 271 | /* |
---|
| 272 | * The following defines the number of bits actually used in the |
---|
| 273 | * interrupt field of the task mode. How those bits map to the |
---|
| 274 | * CPU interrupt levels is defined by the routine _CPU_ISR_Set_level(). |
---|
| 275 | */ |
---|
| 276 | |
---|
| 277 | #define CPU_MODES_INTERRUPT_MASK 0x00000001 |
---|
| 278 | |
---|
| 279 | #define CPU_NAME "UNIX" |
---|
| 280 | |
---|
| 281 | /* |
---|
| 282 | * Processor defined structures |
---|
| 283 | * |
---|
| 284 | * Examples structures include the descriptor tables from the i386 |
---|
| 285 | * and the processor control structure on the i960ca. |
---|
| 286 | */ |
---|
| 287 | |
---|
| 288 | /* may need to put some structures here. */ |
---|
| 289 | |
---|
| 290 | #if defined(hppa1_1) |
---|
| 291 | /* |
---|
| 292 | * Word indices within a jmp_buf structure |
---|
| 293 | */ |
---|
| 294 | |
---|
| 295 | #ifdef RTEMS_NEWLIB |
---|
| 296 | #define RP_OFF 6 |
---|
| 297 | #define SP_OFF 2 |
---|
| 298 | #define R3_OFF 10 |
---|
| 299 | #define R4_OFF 11 |
---|
| 300 | #define R5_OFF 12 |
---|
| 301 | #define R6_OFF 13 |
---|
| 302 | #define R7_OFF 14 |
---|
| 303 | #define R8_OFF 15 |
---|
| 304 | #define R9_OFF 16 |
---|
| 305 | #define R10_OFF 17 |
---|
| 306 | #define R11_OFF 18 |
---|
| 307 | #define R12_OFF 19 |
---|
| 308 | #define R13_OFF 20 |
---|
| 309 | #define R14_OFF 21 |
---|
| 310 | #define R15_OFF 22 |
---|
| 311 | #define R16_OFF 23 |
---|
| 312 | #define R17_OFF 24 |
---|
| 313 | #define R18_OFF 25 |
---|
| 314 | #define DP_OFF 26 |
---|
| 315 | #endif |
---|
| 316 | |
---|
| 317 | #ifdef RTEMS_UNIXLIB |
---|
| 318 | #define RP_OFF 0 |
---|
| 319 | #define SP_OFF 1 |
---|
| 320 | #define R3_OFF 4 |
---|
| 321 | #define R4_OFF 5 |
---|
| 322 | #define R5_OFF 6 |
---|
| 323 | #define R6_OFF 7 |
---|
| 324 | #define R7_OFF 8 |
---|
| 325 | #define R8_OFF 9 |
---|
| 326 | #define R9_OFF 10 |
---|
| 327 | #define R10_OFF 11 |
---|
| 328 | #define R11_OFF 12 |
---|
| 329 | #define R12_OFF 13 |
---|
| 330 | #define R13_OFF 14 |
---|
| 331 | #define R14_OFF 15 |
---|
| 332 | #define R15_OFF 16 |
---|
| 333 | #define R16_OFF 17 |
---|
| 334 | #define R17_OFF 18 |
---|
| 335 | #define R18_OFF 19 |
---|
| 336 | #define DP_OFF 20 |
---|
| 337 | #endif |
---|
| 338 | #endif |
---|
| 339 | |
---|
| 340 | #if defined(sparc) |
---|
| 341 | |
---|
| 342 | /* |
---|
| 343 | * Word indices within a jmp_buf structure |
---|
| 344 | */ |
---|
| 345 | |
---|
| 346 | #ifdef RTEMS_NEWLIB |
---|
| 347 | #define ADDR_ADJ_OFFSET -8 |
---|
| 348 | #define SP_OFF 0 |
---|
| 349 | #define RP_OFF 1 |
---|
| 350 | #define FP_OFF 2 |
---|
| 351 | #endif |
---|
| 352 | |
---|
| 353 | #ifdef RTEMS_UNIXLIB |
---|
| 354 | #define ADDR_ADJ_OFFSET 0 |
---|
| 355 | #define G0_OFF 0 |
---|
| 356 | #define SP_OFF 1 |
---|
| 357 | #define RP_OFF 2 |
---|
| 358 | #define FP_OFF 3 |
---|
| 359 | #define I7_OFF 4 |
---|
| 360 | #endif |
---|
| 361 | |
---|
| 362 | #endif |
---|
| 363 | |
---|
| 364 | /* |
---|
| 365 | * Contexts |
---|
| 366 | * |
---|
| 367 | * Generally there are 2 types of context to save. |
---|
| 368 | * 1. Interrupt registers to save |
---|
| 369 | * 2. Task level registers to save |
---|
| 370 | * |
---|
| 371 | * This means we have the following 3 context items: |
---|
| 372 | * 1. task level context stuff:: Context_Control |
---|
| 373 | * 2. floating point task stuff:: Context_Control_fp |
---|
| 374 | * 3. special interrupt level context :: Context_Control_interrupt |
---|
| 375 | * |
---|
| 376 | * On some processors, it is cost-effective to save only the callee |
---|
| 377 | * preserved registers during a task context switch. This means |
---|
| 378 | * that the ISR code needs to save those registers which do not |
---|
| 379 | * persist across function calls. It is not mandatory to make this |
---|
| 380 | * distinctions between the caller/callee saves registers for the |
---|
| 381 | * purpose of minimizing context saved during task switch and on interrupts. |
---|
| 382 | * If the cost of saving extra registers is minimal, simplicity is the |
---|
| 383 | * choice. Save the same context on interrupt entry as for tasks in |
---|
| 384 | * this case. |
---|
| 385 | * |
---|
| 386 | * Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then |
---|
| 387 | * care should be used in designing the context area. |
---|
| 388 | * |
---|
| 389 | * On some CPUs with hardware floating point support, the Context_Control_fp |
---|
| 390 | * structure will not be used or it simply consist of an array of a |
---|
| 391 | * fixed number of bytes. This is done when the floating point context |
---|
| 392 | * is dumped by a "FP save context" type instruction and the format |
---|
| 393 | * is not really defined by the CPU. In this case, there is no need |
---|
| 394 | * to figure out the exact format -- only the size. Of course, although |
---|
| 395 | * this is enough information for RTEMS, it is probably not enough for |
---|
| 396 | * a debugger such as gdb. But that is another problem. |
---|
| 397 | */ |
---|
| 398 | |
---|
| 399 | typedef struct { |
---|
| 400 | jmp_buf regs; |
---|
| 401 | } Context_Control; |
---|
| 402 | |
---|
| 403 | typedef struct { |
---|
| 404 | } Context_Control_fp; |
---|
| 405 | |
---|
| 406 | typedef struct { |
---|
| 407 | } CPU_Interrupt_frame; |
---|
| 408 | |
---|
| 409 | |
---|
| 410 | /* |
---|
| 411 | * The following table contains the information required to configure |
---|
| 412 | * the XXX processor specific parameters. |
---|
| 413 | * |
---|
| 414 | * NOTE: The interrupt_stack_size field is required if |
---|
| 415 | * CPU_ALLOCATE_INTERRUPT_STACK is defined as TRUE. |
---|
| 416 | * |
---|
| 417 | * The pretasking_hook, predriver_hook, and postdriver_hook, |
---|
| 418 | * and the do_zero_of_workspace fields are required on ALL CPUs. |
---|
| 419 | */ |
---|
| 420 | |
---|
| 421 | typedef struct { |
---|
| 422 | void (*pretasking_hook)( void ); |
---|
| 423 | void (*predriver_hook)( void ); |
---|
| 424 | void (*postdriver_hook)( void ); |
---|
| 425 | void (*idle_task)( void ); |
---|
| 426 | boolean do_zero_of_workspace; |
---|
| 427 | unsigned32 interrupt_stack_size; |
---|
| 428 | unsigned32 extra_system_initialization_stack; |
---|
| 429 | } rtems_cpu_table; |
---|
| 430 | |
---|
| 431 | /* |
---|
| 432 | * This variable is optional. It is used on CPUs on which it is difficult |
---|
| 433 | * to generate an "uninitialized" FP context. It is filled in by |
---|
| 434 | * _CPU_Initialize and copied into the task's FP context area during |
---|
| 435 | * _CPU_Context_Initialize. |
---|
| 436 | */ |
---|
| 437 | |
---|
| 438 | EXTERN Context_Control_fp _CPU_Null_fp_context; |
---|
| 439 | |
---|
| 440 | /* |
---|
| 441 | * On some CPUs, RTEMS supports a software managed interrupt stack. |
---|
| 442 | * This stack is allocated by the Interrupt Manager and the switch |
---|
| 443 | * is performed in _ISR_Handler. These variables contain pointers |
---|
| 444 | * to the lowest and highest addresses in the chunk of memory allocated |
---|
| 445 | * for the interrupt stack. Since it is unknown whether the stack |
---|
| 446 | * grows up or down (in general), this give the CPU dependent |
---|
| 447 | * code the option of picking the version it wants to use. |
---|
| 448 | * |
---|
| 449 | * NOTE: These two variables are required if the macro |
---|
| 450 | * CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE. |
---|
| 451 | */ |
---|
| 452 | |
---|
| 453 | EXTERN void *_CPU_Interrupt_stack_low; |
---|
| 454 | EXTERN void *_CPU_Interrupt_stack_high; |
---|
| 455 | |
---|
| 456 | /* |
---|
| 457 | * With some compilation systems, it is difficult if not impossible to |
---|
| 458 | * call a high-level language routine from assembly language. This |
---|
| 459 | * is especially true of commercial Ada compilers and name mangling |
---|
| 460 | * C++ ones. This variable can be optionally defined by the CPU porter |
---|
| 461 | * and contains the address of the routine _Thread_Dispatch. This |
---|
| 462 | * can make it easier to invoke that routine at the end of the interrupt |
---|
| 463 | * sequence (if a dispatch is necessary). |
---|
| 464 | */ |
---|
| 465 | |
---|
| 466 | EXTERN void (*_CPU_Thread_dispatch_pointer)(); |
---|
| 467 | |
---|
| 468 | /* |
---|
| 469 | * Nothing prevents the porter from declaring more CPU specific variables. |
---|
| 470 | */ |
---|
| 471 | |
---|
| 472 | /* XXX: if needed, put more variables here */ |
---|
| 473 | |
---|
| 474 | /* |
---|
| 475 | * The size of the floating point context area. On some CPUs this |
---|
| 476 | * will not be a "sizeof" because the format of the floating point |
---|
| 477 | * area is not defined -- only the size is. This is usually on |
---|
| 478 | * CPUs with a "floating point save context" instruction. |
---|
| 479 | */ |
---|
| 480 | |
---|
| 481 | #define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp ) |
---|
| 482 | |
---|
| 483 | /* |
---|
| 484 | * The size of a frame on the stack |
---|
| 485 | */ |
---|
| 486 | |
---|
| 487 | #if defined(hppa1_1) |
---|
| 488 | #define CPU_FRAME_SIZE (32 * 4) |
---|
| 489 | #elif defined(sparc) |
---|
| 490 | #define CPU_FRAME_SIZE (112) /* based on disassembled test code */ |
---|
| 491 | #else |
---|
| 492 | #error "Unknown CPU!!!" |
---|
| 493 | #endif |
---|
| 494 | |
---|
| 495 | /* |
---|
| 496 | * Amount of extra stack (above minimum stack size) required by |
---|
| 497 | * system initialization thread. Remember that in a multiprocessor |
---|
| 498 | * system the system intialization thread becomes the MP server thread. |
---|
| 499 | */ |
---|
| 500 | |
---|
| 501 | #define CPU_SYSTEM_INITIALIZATION_THREAD_EXTRA_STACK 0 |
---|
| 502 | |
---|
| 503 | /* |
---|
| 504 | * This defines the number of entries in the ISR_Vector_table managed |
---|
| 505 | * by RTEMS. |
---|
| 506 | */ |
---|
| 507 | |
---|
| 508 | #define CPU_INTERRUPT_NUMBER_OF_VECTORS 64 |
---|
| 509 | |
---|
| 510 | /* |
---|
| 511 | * Should be large enough to run all RTEMS tests. This insures |
---|
| 512 | * that a "reasonable" small application should not have any problems. |
---|
| 513 | */ |
---|
| 514 | |
---|
| 515 | #define CPU_STACK_MINIMUM_SIZE (16 * 1024) |
---|
| 516 | |
---|
| 517 | /* |
---|
| 518 | * CPU's worst alignment requirement for data types on a byte boundary. This |
---|
| 519 | * alignment does not take into account the requirements for the stack. |
---|
| 520 | */ |
---|
| 521 | |
---|
| 522 | #define CPU_ALIGNMENT 8 |
---|
| 523 | |
---|
| 524 | /* |
---|
| 525 | * This number corresponds to the byte alignment requirement for the |
---|
| 526 | * heap handler. This alignment requirement may be stricter than that |
---|
| 527 | * for the data types alignment specified by CPU_ALIGNMENT. It is |
---|
| 528 | * common for the heap to follow the same alignment requirement as |
---|
| 529 | * CPU_ALIGNMENT. If the CPU_ALIGNMENT is strict enough for the heap, |
---|
| 530 | * then this should be set to CPU_ALIGNMENT. |
---|
| 531 | * |
---|
| 532 | * NOTE: This does not have to be a power of 2. It does have to |
---|
| 533 | * be greater or equal to than CPU_ALIGNMENT. |
---|
| 534 | */ |
---|
| 535 | |
---|
| 536 | #define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT |
---|
| 537 | |
---|
| 538 | /* |
---|
| 539 | * This number corresponds to the byte alignment requirement for memory |
---|
| 540 | * buffers allocated by the partition manager. This alignment requirement |
---|
| 541 | * may be stricter than that for the data types alignment specified by |
---|
| 542 | * CPU_ALIGNMENT. It is common for the partition to follow the same |
---|
| 543 | * alignment requirement as CPU_ALIGNMENT. If the CPU_ALIGNMENT is strict |
---|
| 544 | * enough for the partition, then this should be set to CPU_ALIGNMENT. |
---|
| 545 | * |
---|
| 546 | * NOTE: This does not have to be a power of 2. It does have to |
---|
| 547 | * be greater or equal to than CPU_ALIGNMENT. |
---|
| 548 | */ |
---|
| 549 | |
---|
| 550 | #define CPU_PARTITION_ALIGNMENT CPU_ALIGNMENT |
---|
| 551 | |
---|
| 552 | /* |
---|
| 553 | * This number corresponds to the byte alignment requirement for the |
---|
| 554 | * stack. This alignment requirement may be stricter than that for the |
---|
| 555 | * data types alignment specified by CPU_ALIGNMENT. If the CPU_ALIGNMENT |
---|
| 556 | * is strict enough for the stack, then this should be set to 0. |
---|
| 557 | * |
---|
| 558 | * NOTE: This must be a power of 2 either 0 or greater than CPU_ALIGNMENT. |
---|
| 559 | */ |
---|
| 560 | |
---|
| 561 | #define CPU_STACK_ALIGNMENT 64 |
---|
| 562 | |
---|
| 563 | /* ISR handler macros */ |
---|
| 564 | |
---|
| 565 | /* |
---|
| 566 | * Disable all interrupts for an RTEMS critical section. The previous |
---|
| 567 | * level is returned in _level. |
---|
| 568 | */ |
---|
| 569 | |
---|
| 570 | #define _CPU_ISR_Disable( _level ) \ |
---|
| 571 | do { \ |
---|
| 572 | (_level) = _CPU_Disable_signal(); \ |
---|
| 573 | } while ( 0 ) |
---|
| 574 | |
---|
| 575 | /* |
---|
| 576 | * Enable interrupts to the previous level (returned by _CPU_ISR_Disable). |
---|
| 577 | * This indicates the end of an RTEMS critical section. The parameter |
---|
| 578 | * _level is not modified. |
---|
| 579 | */ |
---|
| 580 | |
---|
| 581 | #define _CPU_ISR_Enable( _level ) \ |
---|
| 582 | do { \ |
---|
| 583 | _CPU_Enable_signal( (_level) ); \ |
---|
| 584 | } while ( 0 ) |
---|
| 585 | |
---|
| 586 | /* |
---|
| 587 | * This temporarily restores the interrupt to _level before immediately |
---|
| 588 | * disabling them again. This is used to divide long RTEMS critical |
---|
| 589 | * sections into two or more parts. The parameter _level is not |
---|
| 590 | * modified. |
---|
| 591 | */ |
---|
| 592 | |
---|
| 593 | #define _CPU_ISR_Flash( _level ) \ |
---|
| 594 | do { \ |
---|
| 595 | register _ignored = 0; \ |
---|
| 596 | _CPU_ISR_Enable( (_level) ); \ |
---|
| 597 | _CPU_ISR_Disable( _ignored ); \ |
---|
| 598 | } while ( 0 ) |
---|
| 599 | |
---|
| 600 | /* |
---|
| 601 | * Map interrupt level in task mode onto the hardware that the CPU |
---|
| 602 | * actually provides. Currently, interrupt levels which do not |
---|
| 603 | * map onto the CPU in a generic fashion are undefined. Someday, |
---|
| 604 | * it would be nice if these were "mapped" by the application |
---|
| 605 | * via a callout. For example, m68k has 8 levels 0 - 7, levels |
---|
| 606 | * 8 - 255 would be available for bsp/application specific meaning. |
---|
| 607 | * This could be used to manage a programmable interrupt controller |
---|
| 608 | * via the rtems_task_mode directive. |
---|
| 609 | */ |
---|
| 610 | |
---|
| 611 | #define _CPU_ISR_Set_level( new_level ) \ |
---|
| 612 | { \ |
---|
| 613 | if ( new_level ) \ |
---|
| 614 | (void) _CPU_Disable_signal(); \ |
---|
| 615 | else \ |
---|
| 616 | _CPU_Enable_signal( 0 ); \ |
---|
| 617 | } |
---|
| 618 | |
---|
| 619 | /* end of ISR handler macros */ |
---|
| 620 | |
---|
| 621 | /* Context handler macros */ |
---|
| 622 | |
---|
| 623 | /* |
---|
| 624 | * This routine is responsible for somehow restarting the currently |
---|
| 625 | * executing task. If you are lucky, then all that is necessary |
---|
| 626 | * is restoring the context. Otherwise, there will need to be |
---|
| 627 | * a special assembly routine which does something special in this |
---|
| 628 | * case. Context_Restore should work most of the time. It will |
---|
| 629 | * not work if restarting self conflicts with the stack frame |
---|
| 630 | * assumptions of restoring a context. |
---|
| 631 | */ |
---|
| 632 | |
---|
| 633 | #define _CPU_Context_Restart_self( _the_context ) \ |
---|
| 634 | _CPU_Context_restore( (_the_context) ); |
---|
| 635 | |
---|
| 636 | /* |
---|
| 637 | * The purpose of this macro is to allow the initial pointer into |
---|
| 638 | * a floating point context area (used to save the floating point |
---|
| 639 | * context) to be at an arbitrary place in the floating point |
---|
| 640 | * context area. |
---|
| 641 | * |
---|
| 642 | * This is necessary because some FP units are designed to have |
---|
| 643 | * their context saved as a stack which grows into lower addresses. |
---|
| 644 | * Other FP units can be saved by simply moving registers into offsets |
---|
| 645 | * from the base of the context area. Finally some FP units provide |
---|
| 646 | * a "dump context" instruction which could fill in from high to low |
---|
| 647 | * or low to high based on the whim of the CPU designers. |
---|
| 648 | */ |
---|
| 649 | |
---|
| 650 | #define _CPU_Context_Fp_start( _base, _offset ) \ |
---|
| 651 | ( (void *) (_base) + (_offset) ) |
---|
| 652 | |
---|
| 653 | /* |
---|
| 654 | * This routine initializes the FP context area passed to it to. |
---|
| 655 | * There are a few standard ways in which to initialize the |
---|
| 656 | * floating point context. The code included for this macro assumes |
---|
| 657 | * that this is a CPU in which a "initial" FP context was saved into |
---|
| 658 | * _CPU_Null_fp_context and it simply copies it to the destination |
---|
| 659 | * context passed to it. |
---|
| 660 | * |
---|
| 661 | * Other models include (1) not doing anything, and (2) putting |
---|
| 662 | * a "null FP status word" in the correct place in the FP context. |
---|
| 663 | */ |
---|
| 664 | |
---|
| 665 | #define _CPU_Context_Initialize_fp( _destination ) \ |
---|
| 666 | { \ |
---|
| 667 | *((Context_Control_fp *) *((void **) _destination)) = _CPU_Null_fp_context; \ |
---|
| 668 | } |
---|
| 669 | |
---|
| 670 | #define _CPU_Context_save_fp( _fp_context ) \ |
---|
| 671 | _CPU_Save_float_context( *(Context_Control_fp **)(_fp_context)) |
---|
| 672 | |
---|
| 673 | #define _CPU_Context_restore_fp( _fp_context ) \ |
---|
| 674 | _CPU_Restore_float_context( *(Context_Control_fp **)(_fp_context)) |
---|
| 675 | |
---|
| 676 | extern void _CPU_Context_Initialize( |
---|
| 677 | Context_Control *_the_context, |
---|
| 678 | unsigned32 *_stack_base, |
---|
| 679 | unsigned32 _size, |
---|
| 680 | unsigned32 _new_level, |
---|
[88d594a] | 681 | void *_entry_point |
---|
[ac7d5ef0] | 682 | ); |
---|
| 683 | |
---|
| 684 | /* end of Context handler macros */ |
---|
| 685 | |
---|
| 686 | /* Fatal Error manager macros */ |
---|
| 687 | |
---|
| 688 | /* |
---|
| 689 | * This routine copies _error into a known place -- typically a stack |
---|
| 690 | * location or a register, optionally disables interrupts, and |
---|
| 691 | * halts/stops the CPU. |
---|
| 692 | */ |
---|
| 693 | |
---|
| 694 | #define _CPU_Fatal_halt( _error ) \ |
---|
| 695 | _CPU_Fatal_error( _error ) |
---|
| 696 | |
---|
| 697 | /* end of Fatal Error manager macros */ |
---|
| 698 | |
---|
| 699 | /* Bitfield handler macros */ |
---|
| 700 | |
---|
| 701 | /* |
---|
| 702 | * This routine sets _output to the bit number of the first bit |
---|
| 703 | * set in _value. _value is of CPU dependent type Priority_Bit_map_control. |
---|
| 704 | * This type may be either 16 or 32 bits wide although only the 16 |
---|
| 705 | * least significant bits will be used. |
---|
| 706 | * |
---|
| 707 | * There are a number of variables in using a "find first bit" type |
---|
| 708 | * instruction. |
---|
| 709 | * |
---|
| 710 | * (1) What happens when run on a value of zero? |
---|
| 711 | * (2) Bits may be numbered from MSB to LSB or vice-versa. |
---|
| 712 | * (3) The numbering may be zero or one based. |
---|
| 713 | * (4) The "find first bit" instruction may search from MSB or LSB. |
---|
| 714 | * |
---|
| 715 | * RTEMS guarantees that (1) will never happen so it is not a concern. |
---|
| 716 | * (2),(3), (4) are handled by the macros _CPU_Priority_mask() and |
---|
| 717 | * _CPU_Priority_Bits_index(). These three form a set of routines |
---|
| 718 | * which must logically operate together. Bits in the _value are |
---|
| 719 | * set and cleared based on masks built by _CPU_Priority_mask(). |
---|
| 720 | * The basic major and minor values calculated by _Priority_Major() |
---|
| 721 | * and _Priority_Minor() are "massaged" by _CPU_Priority_Bits_index() |
---|
| 722 | * to properly range between the values returned by the "find first bit" |
---|
| 723 | * instruction. This makes it possible for _Priority_Get_highest() to |
---|
| 724 | * calculate the major and directly index into the minor table. |
---|
| 725 | * This mapping is necessary to ensure that 0 (a high priority major/minor) |
---|
| 726 | * is the first bit found. |
---|
| 727 | * |
---|
| 728 | * This entire "find first bit" and mapping process depends heavily |
---|
| 729 | * on the manner in which a priority is broken into a major and minor |
---|
| 730 | * components with the major being the 4 MSB of a priority and minor |
---|
| 731 | * the 4 LSB. Thus (0 << 4) + 0 corresponds to priority 0 -- the highest |
---|
| 732 | * priority. And (15 << 4) + 14 corresponds to priority 254 -- the next |
---|
| 733 | * to the lowest priority. |
---|
| 734 | * |
---|
| 735 | * If your CPU does not have a "find first bit" instruction, then |
---|
| 736 | * there are ways to make do without it. Here are a handful of ways |
---|
| 737 | * to implement this in software: |
---|
| 738 | * |
---|
| 739 | * - a series of 16 bit test instructions |
---|
| 740 | * - a "binary search using if's" |
---|
| 741 | * - _number = 0 |
---|
| 742 | * if _value > 0x00ff |
---|
| 743 | * _value >>=8 |
---|
| 744 | * _number = 8; |
---|
| 745 | * |
---|
| 746 | * if _value > 0x0000f |
---|
| 747 | * _value >=8 |
---|
| 748 | * _number += 4 |
---|
| 749 | * |
---|
| 750 | * _number += bit_set_table[ _value ] |
---|
| 751 | * |
---|
| 752 | * where bit_set_table[ 16 ] has values which indicate the first |
---|
| 753 | * bit set |
---|
| 754 | */ |
---|
| 755 | |
---|
| 756 | #define _CPU_Bitfield_Find_first_bit( _value, _output ) \ |
---|
| 757 | _output = _CPU_ffs( _value ) |
---|
| 758 | |
---|
| 759 | /* end of Bitfield handler macros */ |
---|
| 760 | |
---|
| 761 | /* |
---|
| 762 | * This routine builds the mask which corresponds to the bit fields |
---|
| 763 | * as searched by _CPU_Bitfield_Find_first_bit(). See the discussion |
---|
| 764 | * for that routine. |
---|
| 765 | */ |
---|
| 766 | |
---|
| 767 | #define _CPU_Priority_Mask( _bit_number ) \ |
---|
| 768 | ( 1 << (_bit_number) ) |
---|
| 769 | |
---|
| 770 | /* |
---|
| 771 | * This routine translates the bit numbers returned by |
---|
| 772 | * _CPU_Bitfield_Find_first_bit() into something suitable for use as |
---|
| 773 | * a major or minor component of a priority. See the discussion |
---|
| 774 | * for that routine. |
---|
| 775 | */ |
---|
| 776 | |
---|
| 777 | #define _CPU_Priority_Bits_index( _priority ) \ |
---|
| 778 | (_priority) |
---|
| 779 | |
---|
| 780 | /* end of Priority handler macros */ |
---|
| 781 | |
---|
| 782 | /* functions */ |
---|
| 783 | |
---|
| 784 | /* |
---|
| 785 | * _CPU_Initialize |
---|
| 786 | * |
---|
| 787 | * This routine performs CPU dependent initialization. |
---|
| 788 | */ |
---|
| 789 | |
---|
| 790 | void _CPU_Initialize( |
---|
| 791 | rtems_cpu_table *cpu_table, |
---|
| 792 | void (*thread_dispatch) |
---|
| 793 | ); |
---|
| 794 | |
---|
| 795 | /* |
---|
| 796 | * _CPU_ISR_install_vector |
---|
| 797 | * |
---|
| 798 | * This routine installs an interrupt vector. |
---|
| 799 | */ |
---|
| 800 | |
---|
| 801 | void _CPU_ISR_install_vector( |
---|
| 802 | unsigned32 vector, |
---|
| 803 | proc_ptr new_handler, |
---|
| 804 | proc_ptr *old_handler |
---|
| 805 | ); |
---|
| 806 | |
---|
| 807 | /* |
---|
| 808 | * _CPU_Install_interrupt_stack |
---|
| 809 | * |
---|
| 810 | * This routine installs the hardware interrupt stack pointer. |
---|
| 811 | * |
---|
| 812 | * NOTE: It need only be provided if CPU_HAS_HARDWARE_INTERRUPT_STACK |
---|
| 813 | * is TRUE. |
---|
| 814 | */ |
---|
| 815 | |
---|
| 816 | void _CPU_Install_interrupt_stack( void ); |
---|
| 817 | |
---|
| 818 | /* |
---|
| 819 | * _CPU_Internal_threads_Idle_thread_body |
---|
| 820 | * |
---|
| 821 | * This routine is the CPU dependent IDLE thread body. |
---|
| 822 | * |
---|
| 823 | * NOTE: It need only be provided if CPU_PROVIDES_IDLE_THREAD_BODY |
---|
| 824 | * is TRUE. |
---|
| 825 | */ |
---|
| 826 | |
---|
| 827 | void _CPU_Internal_threads_Idle_thread_body( void ); |
---|
| 828 | |
---|
| 829 | /* |
---|
| 830 | * _CPU_Context_switch |
---|
| 831 | * |
---|
| 832 | * This routine switches from the run context to the heir context. |
---|
| 833 | */ |
---|
| 834 | |
---|
| 835 | void _CPU_Context_switch( |
---|
| 836 | Context_Control *run, |
---|
| 837 | Context_Control *heir |
---|
| 838 | ); |
---|
| 839 | |
---|
| 840 | /* |
---|
| 841 | * _CPU_Context_restore |
---|
| 842 | * |
---|
| 843 | * This routine is generallu used only to restart self in an |
---|
| 844 | * efficient manner. It may simply be a label in _CPU_Context_switch. |
---|
| 845 | * |
---|
| 846 | * NOTE: May be unnecessary to reload some registers. |
---|
| 847 | */ |
---|
| 848 | |
---|
| 849 | void _CPU_Context_restore( |
---|
| 850 | Context_Control *new_context |
---|
| 851 | ); |
---|
| 852 | |
---|
| 853 | /* |
---|
| 854 | * _CPU_Save_float_context |
---|
| 855 | * |
---|
| 856 | * This routine saves the floating point context passed to it. |
---|
| 857 | */ |
---|
| 858 | |
---|
| 859 | void _CPU_Save_float_context( |
---|
| 860 | Context_Control_fp *fp_context_ptr |
---|
| 861 | ); |
---|
| 862 | |
---|
| 863 | /* |
---|
| 864 | * _CPU_Restore_float_context |
---|
| 865 | * |
---|
| 866 | * This routine restores the floating point context passed to it. |
---|
| 867 | */ |
---|
| 868 | |
---|
| 869 | void _CPU_Restore_float_context( |
---|
| 870 | Context_Control_fp *fp_context_ptr |
---|
| 871 | ); |
---|
| 872 | |
---|
| 873 | |
---|
| 874 | void _CPU_ISR_Set_signal_level( |
---|
| 875 | unsigned32 level |
---|
| 876 | ); |
---|
| 877 | |
---|
| 878 | unsigned32 _CPU_Disable_signal( void ); |
---|
| 879 | |
---|
| 880 | void _CPU_Enable_signal( |
---|
| 881 | unsigned32 level |
---|
| 882 | ); |
---|
| 883 | |
---|
| 884 | void _CPU_Fatal_error( |
---|
| 885 | unsigned32 _error |
---|
| 886 | ); |
---|
| 887 | |
---|
| 888 | int _CPU_ffs( |
---|
| 889 | unsigned32 _value |
---|
| 890 | ); |
---|
| 891 | |
---|
| 892 | /* The following routine swaps the endian format of an unsigned int. |
---|
| 893 | * It must be static because it is referenced indirectly. |
---|
| 894 | * |
---|
| 895 | * This version will work on any processor, but if there is a better |
---|
| 896 | * way for your CPU PLEASE use it. The most common way to do this is to: |
---|
| 897 | * |
---|
| 898 | * swap least significant two bytes with 16-bit rotate |
---|
| 899 | * swap upper and lower 16-bits |
---|
| 900 | * swap most significant two bytes with 16-bit rotate |
---|
| 901 | * |
---|
| 902 | * Some CPUs have special instructions which swap a 32-bit quantity in |
---|
| 903 | * a single instruction (e.g. i486). It is probably best to avoid |
---|
| 904 | * an "endian swapping control bit" in the CPU. One good reason is |
---|
| 905 | * that interrupts would probably have to be disabled to insure that |
---|
| 906 | * an interrupt does not try to access the same "chunk" with the wrong |
---|
| 907 | * endian. Another good reason is that on some CPUs, the endian bit |
---|
| 908 | * endianness for ALL fetches -- both code and data -- so the code |
---|
| 909 | * will be fetched incorrectly. |
---|
| 910 | */ |
---|
| 911 | |
---|
| 912 | static inline unsigned int CPU_swap_u32( |
---|
| 913 | unsigned int value |
---|
| 914 | ) |
---|
| 915 | { |
---|
| 916 | unsigned32 byte1, byte2, byte3, byte4, swapped; |
---|
| 917 | |
---|
| 918 | byte4 = (value >> 24) & 0xff; |
---|
| 919 | byte3 = (value >> 16) & 0xff; |
---|
| 920 | byte2 = (value >> 8) & 0xff; |
---|
| 921 | byte1 = value & 0xff; |
---|
| 922 | |
---|
| 923 | swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4; |
---|
| 924 | return( swapped ); |
---|
| 925 | } |
---|
| 926 | |
---|
| 927 | #ifdef __cplusplus |
---|
| 928 | } |
---|
| 929 | #endif |
---|
| 930 | |
---|
| 931 | #endif |
---|