| Commit | Line | Data |
|---|---|---|
| 12fb3397 SK |
1 | #include <stdio.h> |
| 2 | #include <stdint.h> | |
| 3 | #include <string.h> | |
| 4 | ||
| fcffa834 SK |
5 | #include "x86_dumpfenv.h" |
| 6 | ||
| 12fb3397 SK |
7 | /* No-Wait Store x87 environment */ |
| 8 | #define __fnstenv(__env) __asm__ __volatile__ \ | |
| 9 | ("fnstenv %0" : "=m" (*(__env))) | |
| 12fb3397 SK |
10 | |
| 11 | /* Store MXCSR register */ | |
| 12 | #define __stmxcsr(__csr) __asm__ __volatile__ \ | |
| 13 | ("stmxcsr %0" : "=m" (*(__csr))) | |
| 14 | ||
| 12fb3397 SK |
15 | void |
| 16 | fenv_dump(myfenv_t *envp) | |
| 17 | { | |
| 18 | memset(envp, 0, sizeof(myfenv_t)); | |
| 19 | ||
| 20 | __fnstenv(&envp->x87); | |
| 21 | __stmxcsr(&envp->mxcsr); | |
| 22 | } | |
| 23 | ||
| 24 | void | |
| 25 | fenv_print(const myfenv_t *envp) | |
| 26 | { | |
| 27 | size_t i; | |
| 28 | ||
| 29 | printf(" word: 0x%x\n", envp->x87.control); | |
| 30 | printf("status: 0x%x\n", envp->x87.status); | |
| 31 | printf(" tag: 0x%x\n", envp->x87.tag); | |
| 32 | ||
| 33 | for (i = 0; i < 4; i++) | |
| f7c9c108 | 34 | printf("others[%d] = 0x%x\n", i, envp->x87.others[i]); |
| 12fb3397 | 35 | |
| 2082a599 | 36 | printf("mxcsr: 0x%x\n", envp->mxcsr); |
| 12fb3397 SK |
37 | } |
| 38 | ||
| 39 | #if 0 | |
| 40 | int | |
| 41 | main(void) | |
| 42 | { | |
| 43 | myfenv_t env1, env2; | |
| 44 | ||
| 45 | /* | |
| 46 | * printf() taints fp environment; therefore first populate the | |
| 47 | * structures and and then print their contents. | |
| 48 | * | |
| 49 | * Many thanks to sjamman@ who saved the day! | |
| 50 | */ | |
| 51 | fenv_dump(&env1); | |
| 52 | fenv_dump(&env2); | |
| 53 | ||
| 54 | fenv_print(&env1); | |
| 55 | fenv_print(&env2); | |
| f7c9c108 | 56 | |
| 12fb3397 SK |
57 | return 0; |
| 58 | } | |
| 59 | #endif |