1 /*
2 * Copyright (C) 1998, 1999, 2002, 2003, 2005 Hewlett-Packard Co
3 * David Mosberger-Tang <davidm@hpl.hp.com>
4 *
5 * Register stack engine related helper functions. This file may be
6 * used in applications, so be careful about the name-space and give
7 * some consideration to non-GNU C compilers (though __inline__ is
8 * fine).
9 */
10 #ifndef RSE_H
11 #define RSE_H
12
13 #include <libunwind.h>
14
15 static inline uint64_t
rse_slot_num(uint64_t addr)16 rse_slot_num (uint64_t addr)
17 {
18 return (addr >> 3) & 0x3f;
19 }
20
21 /*
22 * Return TRUE if ADDR is the address of an RNAT slot.
23 */
24 static inline uint64_t
rse_is_rnat_slot(uint64_t addr)25 rse_is_rnat_slot (uint64_t addr)
26 {
27 return rse_slot_num (addr) == 0x3f;
28 }
29
30 /*
31 * Returns the address of the RNAT slot that covers the slot at
32 * address SLOT_ADDR.
33 */
34 static inline uint64_t
rse_rnat_addr(uint64_t slot_addr)35 rse_rnat_addr (uint64_t slot_addr)
36 {
37 return slot_addr | (0x3f << 3);
38 }
39
40 /*
41 * Calculate the number of registers in the dirty partition starting at
42 * BSPSTORE and ending at BSP. This isn't simply (BSP-BSPSTORE)/8
43 * because every 64th slot stores ar.rnat.
44 */
45 static inline uint64_t
rse_num_regs(uint64_t bspstore,uint64_t bsp)46 rse_num_regs (uint64_t bspstore, uint64_t bsp)
47 {
48 uint64_t slots = (bsp - bspstore) >> 3;
49
50 return slots - (rse_slot_num(bspstore) + slots)/0x40;
51 }
52
53 /*
54 * The inverse of the above: given bspstore and the number of
55 * registers, calculate ar.bsp.
56 */
57 static inline uint64_t
rse_skip_regs(uint64_t addr,long num_regs)58 rse_skip_regs (uint64_t addr, long num_regs)
59 {
60 long delta = rse_slot_num(addr) + num_regs;
61
62 if (num_regs < 0)
63 delta -= 0x3e;
64 return addr + ((num_regs + delta/0x3f) << 3);
65 }
66
67 #endif /* RSE_H */
68