Mercurial > ecos
annotate packages/hal/powerpc/arch/current/src/hal_misc.c @ 16:4f2df4ab82c8 ecos-sw-1999-06-18
Merge from eCos master repository on 1999-06-18-15:25:04-BST
| author | jlarmour |
|---|---|
| date | Fri, 18 Jun 1999 07:59:09 +0000 |
| parents | 01ce82f3e11a |
| children | 7253dcc42a09 |
| rev | line source |
|---|---|
| 2 | 1 //========================================================================== |
| 0 | 2 // |
| 3 // hal_misc.c | |
| 4 // | |
| 5 // HAL miscellaneous functions | |
| 6 // | |
| 2 | 7 //========================================================================== |
| 0 | 8 //####COPYRIGHTBEGIN#### |
| 9 // | |
| 10 // ------------------------------------------- | |
| 11 // The contents of this file are subject to the Cygnus eCos Public License | |
| 12 // Version 1.0 (the "License"); you may not use this file except in | |
| 13 // compliance with the License. You may obtain a copy of the License at | |
| 14 // http://sourceware.cygnus.com/ecos | |
| 15 // | |
| 16 // Software distributed under the License is distributed on an "AS IS" | |
| 17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | |
| 18 // License for the specific language governing rights and limitations under | |
| 19 // the License. | |
| 20 // | |
| 21 // The Original Code is eCos - Embedded Cygnus Operating System, released | |
| 22 // September 30, 1998. | |
| 23 // | |
| 24 // The Initial Developer of the Original Code is Cygnus. Portions created | |
| 2 | 25 // by Cygnus are Copyright (C) 1998, 1999 Cygnus Solutions. |
| 26 // All Rights Reserved. | |
| 0 | 27 // ------------------------------------------- |
| 28 // | |
| 29 //####COPYRIGHTEND#### | |
| 2 | 30 //========================================================================== |
| 0 | 31 //#####DESCRIPTIONBEGIN#### |
| 32 // | |
| 2 | 33 // Author(s): nickg, jskov |
| 34 // Contributors: nickg, jskov, | |
| 35 // jlarmour | |
| 36 // Date: 1999-02-20 | |
| 37 // Purpose: HAL miscellaneous functions | |
| 38 // Description: This file contains miscellaneous functions provided by the | |
| 39 // HAL. | |
| 0 | 40 // |
| 41 //####DESCRIPTIONEND#### | |
| 42 // | |
| 2 | 43 //=========================================================================== |
| 0 | 44 |
| 45 #include <pkgconf/hal.h> | |
| 46 | |
| 2 | 47 #define CYGARC_HAL_COMMON_EXPORT_CPU_MACROS |
| 48 #include <cyg/hal/ppc_regs.h> // SPR definitions | |
| 49 | |
| 0 | 50 #include <cyg/infra/cyg_type.h> |
| 51 #include <cyg/infra/cyg_trac.h> // tracing macros | |
| 52 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 2 | 53 #include <cyg/infra/diag.h> // diag_printf |
| 0 | 54 |
| 55 #include <cyg/hal/hal_arch.h> // HAL header | |
| 2 | 56 #include <cyg/hal/hal_cache.h> // HAL cache |
| 57 #if defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) && \ | |
| 58 defined(CYGPKG_HAL_EXCEPTIONS) | |
| 59 # include <cyg/hal/hal_intr.h> // HAL interrupts/exceptions | |
| 60 #endif | |
| 0 | 61 |
| 62 //--------------------------------------------------------------------------- | |
| 2 | 63 // Functions used during initialization. |
| 0 | 64 |
| 2 | 65 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG |
| 66 cyg_bool cyg_hal_stop_constructors; | |
| 67 #endif | |
| 68 | |
| 69 typedef void (*pfunc) (void); | |
| 70 extern pfunc __CTOR_LIST__[]; | |
| 71 extern pfunc __CTOR_END__[]; | |
| 0 | 72 |
| 2 | 73 void |
| 74 cyg_hal_invoke_constructors (void) | |
| 75 { | |
| 76 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG | |
| 77 static pfunc *p = &__CTOR_END__[-1]; | |
| 78 | |
| 79 cyg_hal_stop_constructors = 0; | |
| 80 for (; p >= __CTOR_LIST__; p--) { | |
| 81 (*p) (); | |
| 82 if (cyg_hal_stop_constructors) { | |
| 83 p--; | |
| 84 break; | |
| 0 | 85 } |
| 86 } | |
| 2 | 87 #else |
| 88 pfunc *p; | |
| 89 | |
| 90 for (p = &__CTOR_END__[-1]; p >= __CTOR_LIST__; p--) | |
| 91 (*p) (); | |
| 92 #endif | |
| 0 | 93 } |
| 94 | |
| 95 // Override any __eabi the compiler might generate. We don't want | |
| 96 // constructors to be called twice. | |
| 97 void __eabi (void) {} | |
| 98 | |
| 99 //--------------------------------------------------------------------------- | |
| 100 // First level C exception handler. | |
| 101 | |
| 102 externC void __handle_exception (void); | |
| 103 | |
| 104 externC HAL_SavedRegisters *_hal_registers; | |
| 105 | |
| 2 | 106 void |
| 107 cyg_hal_exception_handler(HAL_SavedRegisters *regs) | |
| 0 | 108 { |
| 109 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS | |
| 110 | |
| 111 // Set the pointer to the registers of the current exception | |
| 112 // context. At entry the GDB stub will expand the | |
| 113 // HAL_SavedRegisters structure into a (bigger) register array. | |
| 114 _hal_registers = regs; | |
| 115 | |
| 116 __handle_exception(); | |
| 117 | |
| 2 | 118 #elif defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) && \ |
| 119 defined(CYGPKG_HAL_EXCEPTIONS) | |
| 120 int vector = regs->vector>>8; | |
| 0 | 121 |
| 122 // We should decode the vector and pass a more appropriate | |
| 123 // value as the second argument. For now we simply pass a | |
| 124 // pointer to the saved registers. We should also divert | |
| 125 // breakpoint and other debug vectors into the debug stubs. | |
| 126 | |
| 2 | 127 if (vector==CYGNUM_HAL_VECTOR_PROGRAM) { |
| 128 int srr1; | |
| 129 CYGARC_MFSPR(CYGARC_REG_SRR1, srr1); // get srr1 | |
| 130 | |
| 131 switch ((srr1 >> 17) & 0xf) { | |
| 132 case 1: | |
| 133 vector = CYGNUM_HAL_EXCEPTION_TRAP; | |
| 134 break; | |
| 135 case 2: | |
| 136 vector = CYGNUM_HAL_EXCEPTION_PRIVILEGED_INSTRUCTION; | |
| 137 break; | |
| 138 case 4: | |
| 139 vector = CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION; | |
| 140 break; | |
| 141 case 8: | |
| 142 vector = CYGNUM_HAL_EXCEPTION_FPU; | |
| 143 break; | |
| 144 default: | |
| 145 CYG_FAIL("Unknown PROGRAM exception!!"); | |
| 146 } | |
| 147 } | |
| 148 cyg_hal_deliver_exception( vector, (CYG_ADDRWORD)regs ); | |
| 0 | 149 |
| 150 #else | |
| 151 | |
| 152 CYG_FAIL("Exception!!!"); | |
| 153 | |
| 154 #endif | |
| 155 | |
| 156 return; | |
| 157 } | |
| 158 | |
| 159 //--------------------------------------------------------------------------- | |
|
14
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
2
diff
changeset
|
160 // Default ISRs |
| 0 | 161 |
| 2 | 162 externC cyg_uint32 |
| 163 hal_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data) | |
| 0 | 164 { |
| 2 | 165 diag_printf("Interrupt: %d\n", vector); |
| 166 | |
| 0 | 167 CYG_FAIL("Spurious Interrupt!!!"); |
| 168 return 0; | |
| 169 } | |
| 170 | |
|
14
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
2
diff
changeset
|
171 // The decrementer default ISR has to do nothing. The reason is that |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
2
diff
changeset
|
172 // decrementer interrupts cannot be disabled - if a kernel configuration |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
2
diff
changeset
|
173 // does not use the RTC, but does use external interrupts, the decrementer |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
2
diff
changeset
|
174 // underflow could cause a CYG_FAIL (as above) even though the user did |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
2
diff
changeset
|
175 // not expect any decrementer interrupts to happen. |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
2
diff
changeset
|
176 externC cyg_uint32 |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
2
diff
changeset
|
177 hal_default_decrementer_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data) |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
2
diff
changeset
|
178 { |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
2
diff
changeset
|
179 return 0; |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
2
diff
changeset
|
180 } |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
2
diff
changeset
|
181 |
| 0 | 182 //--------------------------------------------------------------------------- |
| 183 // Idle thread action | |
| 184 | |
| 2 | 185 void |
| 186 hal_idle_thread_action( cyg_uint32 count ) | |
| 0 | 187 { |
| 188 } | |
| 189 | |
| 190 //--------------------------------------------------------------------------- | |
| 2 | 191 // Use MMU resources to map memory regions. |
| 192 // Takes and returns an int used to ID the MMU resource to use. This ID | |
| 193 // is increased as resources are used and should be used for subsequent | |
| 194 // invocations. | |
| 195 static int | |
| 196 hal_map_memory (int id,CYG_ADDRESS virt, CYG_ADDRESS phys, | |
| 197 cyg_int32 size, cyg_uint8 flags) | |
| 198 { | |
| 199 #ifdef CYG_HAL_POWERPC_MPC603 | |
| 200 { | |
| 201 // Use BATs to map the memory. | |
| 202 cyg_uint32 ubat, lbat; | |
| 203 | |
| 204 ubat = (virt & UBAT_BEPIMASK) | UBAT_VS | UBAT_VP; | |
| 205 lbat = (phys & LBAT_BRPNMASK); | |
| 206 if (flags & CYGARC_MEMDESC_CI) | |
| 207 lbat |= LBAT_I; | |
| 208 if (flags & CYGARC_MEMDESC_GUARDED) | |
| 209 lbat |= LBAT_G; | |
| 210 | |
| 211 // There are 4 BATs, size is programmable. | |
| 212 while (id < 4 && size > 0) { | |
| 213 cyg_uint32 blk_size = 128*1024; | |
| 214 cyg_uint32 bl = 0; | |
| 215 while (blk_size < 256*1024*1024 && blk_size < size) { | |
| 216 blk_size *= 2; | |
| 217 bl = (bl << 1) | 1; | |
| 218 } | |
| 219 ubat = (ubat & ~UBAT_BLMASK) | (bl << 2); | |
| 220 | |
| 221 switch (id) { | |
| 222 case 0: | |
| 223 CYGARC_MTSPR (IBAT0U, ubat); | |
| 224 CYGARC_MTSPR (IBAT0L, lbat); | |
| 225 CYGARC_MTSPR (DBAT0U, ubat); | |
| 226 CYGARC_MTSPR (DBAT0L, lbat); | |
| 227 break; | |
| 228 case 1: | |
| 229 CYGARC_MTSPR (IBAT1U, ubat); | |
| 230 CYGARC_MTSPR (IBAT1L, lbat); | |
| 231 CYGARC_MTSPR (DBAT1U, ubat); | |
| 232 CYGARC_MTSPR (DBAT1L, lbat); | |
| 233 break; | |
| 234 case 2: | |
| 235 CYGARC_MTSPR (IBAT2U, ubat); | |
| 236 CYGARC_MTSPR (IBAT2L, lbat); | |
| 237 CYGARC_MTSPR (DBAT2U, ubat); | |
| 238 CYGARC_MTSPR (DBAT2L, lbat); | |
| 239 break; | |
| 240 case 3: | |
| 241 CYGARC_MTSPR (IBAT3U, ubat); | |
| 242 CYGARC_MTSPR (IBAT3L, lbat); | |
| 243 CYGARC_MTSPR (DBAT3U, ubat); | |
| 244 CYGARC_MTSPR (DBAT3L, lbat); | |
| 245 break; | |
| 246 } | |
| 247 | |
| 248 size -= blk_size; | |
| 249 id++; | |
| 250 } | |
| 251 } | |
| 252 #endif | |
| 253 | |
| 254 | |
| 255 #ifdef CYG_HAL_POWERPC_MPC8xx | |
| 256 { | |
| 257 // The MPC8xx CPUs do not have BATs. Fortunately we don't | |
| 258 // currently use the MMU, so we can simulate BATs by using the | |
| 259 // TLBs. | |
| 260 | |
| 261 cyg_uint32 epn, rpn, ctr, twc; | |
| 262 int max_tlbs; | |
| 263 | |
| 264 #if defined(CYG_HAL_POWERPC_MPC860) | |
| 265 // There are 32 TLBs. | |
| 266 max_tlbs = 32; | |
| 267 #endif | |
| 268 #if defined(CYG_HAL_POWERPC_MPC823) || defined(CYG_HAL_POWERPC_MPC850) | |
| 269 // There are 8 TLBs. | |
| 270 max_tlbs = 8; | |
| 271 #endif | |
| 272 | |
| 273 epn = (virt & MI_EPN_EPNMASK) | MI_EPN_EV; | |
| 274 rpn = ((phys & MI_RPN_RPNMASK) | |
| 275 | MI_RPN_PPRWRW | MI_RPN_LPS | MI_RPN_SH | MI_RPN_V); | |
| 276 if (flags & CYGARC_MEMDESC_CI) | |
| 277 rpn |= MI_RPN_CI; | |
| 278 | |
| 279 twc = MI_TWC_PS8MB | MI_TWC_V; | |
| 280 if (flags & CYGARC_MEMDESC_GUARDED) | |
| 281 twc |= MI_TWC_G; | |
| 282 | |
| 283 // Ignore attempts to use more than max_tlbs. | |
| 284 while (id < max_tlbs && size > 0) { | |
| 285 ctr = id << MI_CTR_INDX_SHIFT; | |
| 286 | |
| 287 // Instruction TLB. | |
| 288 CYGARC_MTSPR (MI_TWC, twc); | |
| 289 CYGARC_MTSPR (MI_CTR, ctr); | |
| 290 CYGARC_MTSPR (MI_EPN, epn); | |
| 291 CYGARC_MTSPR (MI_RPN, rpn); | |
| 292 | |
| 293 // Data TLB. | |
| 294 { | |
| 295 cyg_uint32 drpn; | |
| 296 | |
| 297 // Need to mark data page as changed or an exception | |
| 298 // will be generated on first write to the page. | |
| 299 drpn = rpn | MD_RPN_CHANGED; | |
| 300 | |
| 301 CYGARC_MTSPR (MD_TWC, twc); | |
| 302 CYGARC_MTSPR (MD_CTR, ctr); | |
| 303 CYGARC_MTSPR (MD_EPN, epn); | |
| 304 CYGARC_MTSPR (MD_RPN, drpn); | |
| 305 } | |
| 306 | |
| 307 // Move to next 8MB block. | |
| 308 size -= 8*1024*1024; | |
| 309 epn += 8*1024*1024; | |
| 310 rpn += 8*1024*1024; | |
| 311 id++; | |
| 312 } | |
| 313 } | |
| 314 #endif | |
| 315 | |
| 316 return id; | |
| 317 } | |
| 318 | |
| 319 | |
| 320 // Initialize MMU to a sane (NOP) state. | |
| 321 static void | |
| 322 hal_clear_MMU (void) | |
| 323 { | |
| 324 #ifdef CYG_HAL_POWERPC_MPC603 | |
| 325 { | |
| 326 cyg_uint32 ubat, lbat; | |
| 327 | |
| 328 // Initialize BATs with 0 -- VS&VP are unset, making all matches fail | |
| 329 ubat = 0; | |
| 330 lbat = 0; | |
| 331 | |
| 332 CYGARC_MTSPR (IBAT0U, ubat); | |
| 333 CYGARC_MTSPR (IBAT0L, lbat); | |
| 334 CYGARC_MTSPR (DBAT0U, ubat); | |
| 335 CYGARC_MTSPR (DBAT0L, lbat); | |
| 336 CYGARC_MTSPR (IBAT1U, ubat); | |
| 337 CYGARC_MTSPR (IBAT1L, lbat); | |
| 338 CYGARC_MTSPR (DBAT1U, ubat); | |
| 339 CYGARC_MTSPR (DBAT1L, lbat); | |
| 340 CYGARC_MTSPR (IBAT2U, ubat); | |
| 341 CYGARC_MTSPR (IBAT2L, lbat); | |
| 342 CYGARC_MTSPR (DBAT2U, ubat); | |
| 343 CYGARC_MTSPR (DBAT2L, lbat); | |
| 344 CYGARC_MTSPR (IBAT3U, ubat); | |
| 345 CYGARC_MTSPR (IBAT3L, lbat); | |
| 346 CYGARC_MTSPR (DBAT3U, ubat); | |
| 347 CYGARC_MTSPR (DBAT3L, lbat); | |
| 348 } | |
| 349 #endif | |
| 350 | |
| 351 #ifdef CYG_HAL_POWERPC_MPC8xx | |
| 352 { | |
| 353 // Initialize TLBs with 0, Valid bits unset. | |
| 354 | |
| 355 cyg_uint32 ctr; | |
| 356 int id; | |
| 357 int max_tlbs; | |
| 358 | |
| 359 #if defined(CYG_HAL_POWERPC_MPC860) | |
| 360 // There are 32 TLBs. | |
| 361 max_tlbs = 32; | |
| 362 #endif | |
| 363 #if defined(CYG_HAL_POWERPC_MPC823) || defined(CYG_HAL_POWERPC_MPC850) | |
| 364 // There are 8 TLBs. | |
| 365 max_tlbs = 8; | |
| 366 #endif | |
| 367 | |
| 368 CYGARC_MTSPR (M_CASID, 0); | |
| 369 | |
| 370 for (id = 0; id < max_tlbs; id++) { | |
| 371 ctr = id << MI_CTR_INDX_SHIFT; | |
| 372 | |
| 373 // Instruction TLBs. | |
| 374 CYGARC_MTSPR (MI_TWC, 0); | |
| 375 CYGARC_MTSPR (MI_CTR, ctr); | |
| 376 CYGARC_MTSPR (MI_EPN, 0); | |
| 377 CYGARC_MTSPR (MI_RPN, 0); | |
| 378 // Data TLBs. | |
| 379 CYGARC_MTSPR (MD_TWC, 0); | |
| 380 CYGARC_MTSPR (MD_CTR, ctr); | |
| 381 CYGARC_MTSPR (MD_EPN, 0); | |
| 382 CYGARC_MTSPR (MD_RPN, 0); | |
| 383 } | |
| 384 } | |
| 385 #endif | |
| 386 } | |
| 387 | |
|
16
4f2df4ab82c8
Merge from eCos master repository on 1999-06-18-15:25:04-BST
jlarmour
parents:
14
diff
changeset
|
388 // NB this demands that the platform HAL has provided an |
|
4f2df4ab82c8
Merge from eCos master repository on 1999-06-18-15:25:04-BST
jlarmour
parents:
14
diff
changeset
|
389 // externC cyg_memdesc_t cyg_hal_mem_map[]; |
|
4f2df4ab82c8
Merge from eCos master repository on 1999-06-18-15:25:04-BST
jlarmour
parents:
14
diff
changeset
|
390 // as detailed in hal_cache.h: |
| 2 | 391 externC void hal_MMU_init (void) |
| 392 { | |
| 393 int id = 0; | |
| 394 int i = 0; | |
| 395 | |
| 396 hal_clear_MMU (); | |
| 397 | |
| 398 while (cyg_hal_mem_map[i].size) { | |
| 399 id = hal_map_memory (id, | |
| 400 cyg_hal_mem_map[i].virtual_addr, | |
| 401 cyg_hal_mem_map[i].physical_addr, | |
| 402 cyg_hal_mem_map[i].size, | |
| 403 cyg_hal_mem_map[i].flags); | |
| 404 i++; | |
| 405 } | |
| 406 } | |
| 407 | |
| 408 //--------------------------------------------------------------------------- | |
| 409 // Initial cache enabling | |
| 410 externC void | |
| 411 hal_enable_caches(void) | |
| 412 { | |
| 413 #ifdef CYGPKG_HAL_POWERPC_COGENT | |
| 414 // Initialize caches. | |
| 415 HAL_ICACHE_UNLOCK_ALL(); | |
| 416 HAL_DCACHE_UNLOCK_ALL(); | |
| 417 HAL_ICACHE_INVALIDATE_ALL(); | |
| 418 HAL_DCACHE_INVALIDATE_ALL(); | |
| 419 | |
| 420 // Enable caches. | |
| 421 #if defined(CYG_HAL_STARTUP_RAM) | |
| 422 // Cogent board doesn't support burst access to the ROM and on the | |
| 423 // MPC8xx caches require burst. | |
| 424 HAL_ICACHE_ENABLE(); | |
| 425 HAL_DCACHE_ENABLE(); | |
| 426 #endif | |
| 427 #endif | |
| 428 | |
| 429 #ifdef CYG_HAL_POWERPC_MPC8xx | |
| 430 // Disable serialization | |
| 431 { | |
| 432 cyg_uint32 ictrl; | |
| 433 CYGARC_MFSPR (ICTRL, ictrl); | |
| 434 ictrl |= ICTRL_NOSERSHOW; | |
| 435 CYGARC_MTSPR (ICTRL, ictrl); | |
| 436 } | |
| 437 #endif | |
| 438 } | |
| 439 | |
| 440 //--------------------------------------------------------------------------- | |
| 0 | 441 // End of hal_misc.c |
