51 lines · c
1#ifndef CALL_APSR_H2#define CALL_APSR_H3 4#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__5 6union cpsr {7 struct {8 uint32_t filler : 28;9 uint32_t v : 1;10 uint32_t c : 1;11 uint32_t z : 1;12 uint32_t n : 1;13 } flags;14 uint32_t value;15};16 17#else18 19union cpsr {20 struct {21 uint32_t n : 1;22 uint32_t z : 1;23 uint32_t c : 1;24 uint32_t v : 1;25 uint32_t filler : 28;26 } flags;27 uint32_t value;28};29 30#endif31 32__attribute__((noinline, pcs("aapcs"))) static uint32_t call_apsr_f(float a, float b,33 __attribute__((pcs("aapcs"))) void (*fn)(float, float)) {34 uint32_t result;35 fn(a, b);36 asm volatile("mrs %0, apsr"37 : "=r"(result));38 return result;39}40 41__attribute__((noinline, pcs("aapcs"))) static uint32_t call_apsr_d(double a, double b,42 __attribute__((pcs("aapcs"))) void (*fn)(double, double)) {43 uint32_t result;44 fn(a, b);45 asm volatile("mrs %0, apsr"46 : "=r"(result));47 return result;48}49 50#endif // CALL_APSR_H51