1 /* libunwind - a platform-independent unwind library 2 Copyright (C) 2002-2005 Hewlett-Packard Co 3 Contributed by David Mosberger-Tang <davidm (at) hpl.hp.com> 4 5 This file is part of libunwind. 6 7 Permission is hereby granted, free of charge, to any person obtaining 8 a copy of this software and associated documentation files (the 9 "Software"), to deal in the Software without restriction, including 10 without limitation the rights to use, copy, modify, merge, publish, 11 distribute, sublicense, and/or sell copies of the Software, and to 12 permit persons to whom the Software is furnished to do so, subject to 13 the following conditions: 14 15 The above copyright notice and this permission notice shall be 16 included in all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 25 26 #include <assert.h> 27 28 #include "unwind_i.h" 29 30 HIDDEN struct ia64_global_unwind_state unw = 31 { 32 .lock = PTHREAD_MUTEX_INITIALIZER, 33 .save_order = { 34 IA64_REG_IP, IA64_REG_PFS, IA64_REG_PSP, IA64_REG_PR, 35 IA64_REG_UNAT, IA64_REG_LC, IA64_REG_FPSR, IA64_REG_PRI_UNAT_GR 36 }, 37 #if UNW_DEBUG 38 .preg_name = { 39 "pri_unat_gr", "pri_unat_mem", "psp", "bsp", "bspstore", 40 "ar.pfs", "ar.rnat", "rp", 41 "r4", "r5", "r6", "r7", 42 "nat4", "nat5", "nat6", "nat7", 43 "ar.unat", "pr", "ar.lc", "ar.fpsr", 44 "b1", "b2", "b3", "b4", "b5", 45 "f2", "f3", "f4", "f5", 46 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", 47 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31" 48 } 49 #endif 50 }; 51 52 HIDDEN void 53 tdep_init (void) 54 { 55 const uint8_t f1_bytes[16] = { 56 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 57 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 58 }; 59 const uint8_t nat_val_bytes[16] = { 60 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xfe, 61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 62 }; 63 const uint8_t int_val_bytes[16] = { 64 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x3e, 65 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 66 }; 67 intrmask_t saved_mask; 68 uint8_t *lep, *bep; 69 long i; 70 71 sigfillset (&unwi_full_mask); 72 73 lock_acquire (&unw.lock, saved_mask); 74 { 75 if (tdep_init_done) 76 /* another thread else beat us to it... */ 77 goto out; 78 79 mi_init (); 80 81 mempool_init (&unw.reg_state_pool, sizeof (struct ia64_reg_state), 0); 82 mempool_init (&unw.labeled_state_pool, 83 sizeof (struct ia64_labeled_state), 0); 84 85 unw.read_only.r0 = 0; 86 unw.read_only.f0.raw.bits[0] = 0; 87 unw.read_only.f0.raw.bits[1] = 0; 88 89 lep = (uint8_t *) &unw.read_only.f1_le + 16; 90 bep = (uint8_t *) &unw.read_only.f1_be; 91 for (i = 0; i < 16; ++i) 92 { 93 *--lep = f1_bytes[i]; 94 *bep++ = f1_bytes[i]; 95 } 96 97 lep = (uint8_t *) &unw.nat_val_le + 16; 98 bep = (uint8_t *) &unw.nat_val_be; 99 for (i = 0; i < 16; ++i) 100 { 101 *--lep = nat_val_bytes[i]; 102 *bep++ = nat_val_bytes[i]; 103 } 104 105 lep = (uint8_t *) &unw.int_val_le + 16; 106 bep = (uint8_t *) &unw.int_val_be; 107 for (i = 0; i < 16; ++i) 108 { 109 *--lep = int_val_bytes[i]; 110 *bep++ = int_val_bytes[i]; 111 } 112 113 assert (8*sizeof(unw_hash_index_t) >= IA64_LOG_UNW_HASH_SIZE); 114 115 #ifndef UNW_REMOTE_ONLY 116 ia64_local_addr_space_init (); 117 #endif 118 tdep_init_done = 1; /* signal that we're initialized... */ 119 } 120 out: 121 lock_release (&unw.lock, saved_mask); 122 } 123