Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame^] | 1 | /* target operations */ |
| 2 | |
| 3 | #include <linux/types.h> |
| 4 | #define intptr_t long |
| 5 | #define uintptr_t unsigned long |
| 6 | |
| 7 | |
| 8 | /* These three macro definitions are generic, just shorthands |
| 9 | used by the generated code. */ |
| 10 | |
| 11 | #define op_abs(x) (x < 0 ? -x : x) |
| 12 | |
| 13 | #define fetch_bitfield(target, base, higherbits, nbits) \ |
| 14 | target = (((base) >> (sizeof (base) * 8 - (higherbits) - (nbits))) \ |
| 15 | & (((__typeof (base)) 1 << (nbits)) - 1)) |
| 16 | |
| 17 | #define store_bitfield(target, base, higherbits, nbits) \ |
| 18 | target = (target \ |
| 19 | &~ ((((__typeof (base)) 1 << (nbits)) - 1) \ |
| 20 | << (sizeof (base) * 8 - (higherbits) - (nbits))) \ |
| 21 | | ((__typeof (base)) (value) \ |
| 22 | << (sizeof (base) * 8 - (higherbits) - (nbits)))) |
| 23 | |
| 24 | |
| 25 | /* These operations are target-specific. */ |
| 26 | #include <asm/uaccess.h> |
| 27 | |
| 28 | #define fetch_register(regno) ((intptr_t) regs->dwarf_register_##regno) |
| 29 | |
| 30 | #if defined __i386__ |
| 31 | |
| 32 | #define dwarf_register_0 eax |
| 33 | #define dwarf_register_1 ecx |
| 34 | #define dwarf_register_2 edx |
| 35 | #define dwarf_register_3 ebx |
| 36 | #define dwarf_register_4 esp |
| 37 | #define dwarf_register_5 ebp |
| 38 | #define dwarf_register_6 esi |
| 39 | #define dwarf_register_7 edi |
| 40 | |
| 41 | #elif defined __x86_64__ |
| 42 | |
| 43 | #define dwarf_register_0 eax |
| 44 | #define dwarf_register_1 edx |
| 45 | #define dwarf_register_2 ecx |
| 46 | #define dwarf_register_3 ebx |
| 47 | #define dwarf_register_4 esi |
| 48 | #define dwarf_register_5 edi |
| 49 | #define dwarf_register_6 ebp |
| 50 | #define dwarf_register_7 esp |
| 51 | #define dwarf_register_8 r8 |
| 52 | #define dwarf_register_9 r9 |
| 53 | #define dwarf_register_10 r10 |
| 54 | #define dwarf_register_11 r11 |
| 55 | #define dwarf_register_12 r12 |
| 56 | #define dwarf_register_13 r13 |
| 57 | #define dwarf_register_14 r14 |
| 58 | #define dwarf_register_15 r15 |
| 59 | |
| 60 | #elif defined __powerpc__ |
| 61 | |
| 62 | #undef fetch_register |
| 63 | #define fetch_register(regno) ((intptr_t) regs->gpr[regno]) |
| 64 | |
| 65 | #endif |
| 66 | |
| 67 | #if defined __i386__ || defined __x86_64__ |
| 68 | |
| 69 | #define deref(size, addr) \ |
| 70 | ({ \ |
| 71 | int _bad = 0; \ |
| 72 | u8 _b; u16 _w; u32 _l; u64 _q; \ |
| 73 | intptr_t _v; \ |
| 74 | switch (size) \ |
| 75 | { \ |
| 76 | case 1: __get_user_asm(_b,addr,_bad,"b","b","=q",1); _v = _b; break; \ |
| 77 | case 2: __get_user_asm(_w,addr,_bad,"w","w","=r",1); _v = _w; break; \ |
| 78 | case 4: __get_user_asm(_l,addr,_bad,"l","","=r",1); _v = _l; break; \ |
| 79 | case 8: __get_user_asm(_q,addr,_bad,"q","","=r",1); _v = _q; break; \ |
| 80 | default: _v = __get_user_bad(); \ |
| 81 | } \ |
| 82 | if (_bad) \ |
| 83 | goto deref_fault; \ |
| 84 | _v; \ |
| 85 | }) |
| 86 | |
| 87 | #elif defined __powerpc64__ |
| 88 | |
| 89 | #define deref(size, addr) \ |
| 90 | ({ \ |
| 91 | int _bad = 0; \ |
| 92 | intptr_t _v; \ |
| 93 | switch (size) \ |
| 94 | { \ |
| 95 | case 1: __get_user_asm(_v,addr,_bad,"lbz",1); break; \ |
| 96 | case 2: __get_user_asm(_v,addr,_bad,"lhz",1); break; \ |
| 97 | case 4: __get_user_asm(_v,addr,_bad,"lwz",1); break; \ |
| 98 | case 8: __get_user_asm(_v,addr,_bad,"ld",1); break; \ |
| 99 | default: _v = __get_user_bad(); \ |
| 100 | } \ |
| 101 | if (_bad) \ |
| 102 | goto deref_fault; \ |
| 103 | _v; \ |
| 104 | }) |
| 105 | |
| 106 | #elif defined __powerpc__ |
| 107 | |
| 108 | #define deref(size, addr) \ |
| 109 | ({ \ |
| 110 | int _bad = 0; \ |
| 111 | intptr_t _v; \ |
| 112 | switch (size) \ |
| 113 | { \ |
| 114 | case 1: __get_user_asm(_v,addr,_bad,"lbz"); break; \ |
| 115 | case 2: __get_user_asm(_v,addr,_bad,"lhz"); break; \ |
| 116 | case 4: __get_user_asm(_v,addr,_bad,"lwz"); break; \ |
| 117 | case 8: __get_user_asm(_v,addr,_bad,"ld"); break; \ |
| 118 | default: _v = __get_user_bad(); \ |
| 119 | } \ |
| 120 | if (_bad) \ |
| 121 | goto deref_fault; \ |
| 122 | _v; \ |
| 123 | }) |
| 124 | |
| 125 | #endif |