• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* libunwind - a platform-independent unwind library
2    Copyright (C) 2008 CodeSourcery
3    Copyright (C) 2021 Zhaofeng Li
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 "unwind_i.h"
27 #include "dwarf_i.h"
28 
29 HIDDEN define_lock (riscv_lock);
30 HIDDEN atomic_bool tdep_init_done = 0;
31 
32 /* Our ordering is already consistent with
33    https://github.com/riscv/riscv-elf-psabi-doc/blob/74ecf07bcebd0cb4bf3c39f3f9d96946cd6aba61/riscv-elf.md#dwarf-register-numbers- */
34 HIDDEN const uint8_t dwarf_to_unw_regnum_map[] =
35   {
36     UNW_RISCV_X0,
37     UNW_RISCV_X1,
38     UNW_RISCV_X2,
39     UNW_RISCV_X3,
40     UNW_RISCV_X4,
41     UNW_RISCV_X5,
42     UNW_RISCV_X6,
43     UNW_RISCV_X7,
44     UNW_RISCV_X8,
45     UNW_RISCV_X9,
46     UNW_RISCV_X10,
47     UNW_RISCV_X11,
48     UNW_RISCV_X12,
49     UNW_RISCV_X13,
50     UNW_RISCV_X14,
51     UNW_RISCV_X15,
52     UNW_RISCV_X16,
53     UNW_RISCV_X17,
54     UNW_RISCV_X18,
55     UNW_RISCV_X19,
56     UNW_RISCV_X20,
57     UNW_RISCV_X21,
58     UNW_RISCV_X22,
59     UNW_RISCV_X23,
60     UNW_RISCV_X24,
61     UNW_RISCV_X25,
62     UNW_RISCV_X26,
63     UNW_RISCV_X27,
64     UNW_RISCV_X28,
65     UNW_RISCV_X29,
66     UNW_RISCV_X30,
67     UNW_RISCV_X31,
68 
69     UNW_RISCV_F0,
70     UNW_RISCV_F1,
71     UNW_RISCV_F2,
72     UNW_RISCV_F3,
73     UNW_RISCV_F4,
74     UNW_RISCV_F5,
75     UNW_RISCV_F6,
76     UNW_RISCV_F7,
77     UNW_RISCV_F8,
78     UNW_RISCV_F9,
79     UNW_RISCV_F10,
80     UNW_RISCV_F11,
81     UNW_RISCV_F12,
82     UNW_RISCV_F13,
83     UNW_RISCV_F14,
84     UNW_RISCV_F15,
85     UNW_RISCV_F16,
86     UNW_RISCV_F17,
87     UNW_RISCV_F18,
88     UNW_RISCV_F19,
89     UNW_RISCV_F20,
90     UNW_RISCV_F21,
91     UNW_RISCV_F22,
92     UNW_RISCV_F23,
93     UNW_RISCV_F24,
94     UNW_RISCV_F25,
95     UNW_RISCV_F26,
96     UNW_RISCV_F27,
97     UNW_RISCV_F28,
98     UNW_RISCV_F29,
99     UNW_RISCV_F30,
100     UNW_RISCV_F31,
101   };
102 
103 HIDDEN void
tdep_init(void)104 tdep_init (void)
105 {
106   intrmask_t saved_mask;
107 
108   sigfillset (&unwi_full_mask);
109 
110   lock_acquire (&riscv_lock, saved_mask);
111 
112   if (atomic_load(&tdep_init_done))
113     /* another thread else beat us to it... */
114     goto out;
115 
116   mi_init ();
117   dwarf_init ();
118 
119 #ifndef UNW_REMOTE_ONLY
120   tdep_init_mem_validate ();
121 
122   riscv_local_addr_space_init ();
123 #endif
124   atomic_store(&tdep_init_done, 1);  /* signal that we're initialized... */
125 
126  out:
127   lock_release (&riscv_lock, saved_mask);
128 }
129