Changeset 664fd6d5 in mainline
- Timestamp:
- 2013-01-06T19:20:33Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- de36fdd
- Parents:
- b5a3b50
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/arm32/src/fpu_context.c
rb5a3b50 r664fd6d5 58 58 FPEXC_EX_FLAG = (1 << 31), 59 59 FPEXC_ENABLED_FLAG = (1 << 30), 60 }; 61 62 /* See Architecture reference manual ch. B4.1.40 */ 63 enum { 64 CPACR_CP10_MASK = 0x3 << 20, 65 CPACR_CP11_MASK = 0x3 << 22, 66 CPACR_CP10_USER_ACCESS = CPACR_CP10_MASK, 67 CPACR_CP11_USER_ACCESS = CPACR_CP11_MASK, 60 68 }; 61 69 … … 228 236 } 229 237 238 static int fpu_have_coprocessor_access() 239 { 240 uint32_t cpacr; 241 asm volatile ("MRC p15, 0, %0, c1, c0, 2" :"=r" (cpacr)::); 242 /* FPU needs access to coprocessor 10 and 11. 243 * Moreover they need to have same access enabledd */ 244 if (((cpacr & CPACR_CP10_MASK) == CPACR_CP10_USER_ACCESS) && 245 ((cpacr & CPACR_CP11_MASK) == CPACR_CP11_USER_ACCESS)) 246 return 1; 247 248 return 0; 249 } 250 251 static void fpu_enable_coprocessor_access() 252 { 253 uint32_t cpacr; 254 asm volatile ("mrc p15, 0, %0, c1, c0, 2" :"=r" (cpacr)::); 255 /* FPU needs access to coprocessor 10 and 11. 256 * Moreover, they need to have same access enabled */ 257 cpacr |= CPACR_CP10_USER_ACCESS; 258 cpacr |= CPACR_CP11_USER_ACCESS; 259 asm volatile ("mcr p15, 0, %0, c1, c0, 2" :"=r" (cpacr)::); 260 } 261 262 230 263 void fpu_init(void) 231 264 { 265 /* Enable coprocessor access*/ 266 fpu_enable_coprocessor_access(); 267 268 /* Check if we succeeded */ 269 if (!fpu_have_coprocessor_access()) 270 return; 271 232 272 /* Clear all fpu flags */ 233 273 fpexc_write(0); … … 241 281 void fpu_setup(void) 242 282 { 283 /* Check if we have access */ 284 if (!fpu_have_coprocessor_access()) 285 return; 286 243 287 uint32_t fpsid = 0; 244 288 asm volatile ( … … 288 332 bool handle_if_fpu_exception(void) 289 333 { 334 /* Check if we have access */ 335 if (!fpu_have_coprocessor_access()) 336 return false; 337 290 338 const uint32_t fpexc = fpexc_read(); 291 339 if (fpexc & FPEXC_ENABLED_FLAG) { … … 305 353 void fpu_enable(void) 306 354 { 355 /* Check if we have access */ 356 if (!fpu_have_coprocessor_access()) 357 return; 307 358 /* Enable FPU instructions */ 308 359 fpexc_write(fpexc_read() | FPEXC_ENABLED_FLAG); … … 311 362 void fpu_disable(void) 312 363 { 364 /* Check if we have access */ 365 if (!fpu_have_coprocessor_access()) 366 return; 313 367 /* Disable FPU instructions */ 314 368 fpexc_write(fpexc_read() & ~FPEXC_ENABLED_FLAG); … … 317 371 void fpu_context_save(fpu_context_t *ctx) 318 372 { 373 /* Check if we have access */ 374 if (!fpu_have_coprocessor_access()) 375 return; 319 376 const uint32_t fpexc = fpexc_read(); 320 377 … … 329 386 void fpu_context_restore(fpu_context_t *ctx) 330 387 { 388 /* Check if we have access */ 389 if (!fpu_have_coprocessor_access()) 390 return; 331 391 if (restore_context) 332 392 restore_context(ctx);
Note:
See TracChangeset
for help on using the changeset viewer.