Update copyright notices with scripts/update-copyrights.
[jlayton/glibc.git] / sysdeps / powerpc / powerpc64 / bp-asm.h
1 /* Bounded-pointer definitions for PowerPC64 assembler.
2    Copyright (C) 2000-2013 Free Software Foundation, Inc.
3    Contributed by Greg McGary <greg@mcgary.org>
4
5    This file is part of the GNU C Library.  Its master source is NOT part of
6    the C library, however.  The master source lives in the GNU MP Library.
7
8    The GNU C Library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Library General Public License as
10    published by the Free Software Foundation; either version 2 of the
11    License, or (at your option) any later version.
12
13    The GNU C Library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Library General Public License for more details.
17
18    You should have received a copy of the GNU Library General Public
19    License along with the GNU C Library; see the file COPYING.LIB.  If
20    not, see <http://www.gnu.org/licenses/>.  */
21
22 #if __BOUNDED_POINTERS__
23
24 /* Byte offsets of BP components.  */
25 # define oVALUE 0
26 # define oLOW   4
27 # define oHIGH  8
28
29 /* Don't check bounds, just convert the BP register to its simple
30    pointer value.  */
31
32 # define DISCARD_BOUNDS(rBP)                    \
33         ld      rBP, oVALUE(rBP)
34
35 /* Check low bound, with the side effect that the BP register is converted
36    its simple pointer value.  Move the high bound into a register for
37    later use.  */
38
39 # define CHECK_BOUNDS_LOW(rBP, rLOW, rHIGH)     \
40         ld      rHIGH, oHIGH(rBP);              \
41         ld      rLOW, oLOW(rBP);                \
42         ld      rBP, oVALUE(rBP);               \
43         tdllt   rBP, rLOW
44
45 /* Check the high bound, which is in a register, using the given
46    conditional trap instruction.  */
47
48 # define CHECK_BOUNDS_HIGH(rVALUE, rHIGH, TWLcc) \
49         TWLcc   rVALUE, rHIGH
50
51 /* Check the high bound, which is stored at the return-value's high
52    bound slot, using the given conditional trap instruction.  */
53
54 # define CHECK_BOUNDS_HIGH_RTN(rVALUE, rHIGH, TWLcc)    \
55         ld      rHIGH, oHIGH(rRTN);                     \
56         TWLcc   rVALUE, rHIGH
57
58 /* Check both bounds, with the side effect that the BP register is
59    converted to its simple pointer value.  */
60
61 # define CHECK_BOUNDS_BOTH(rBP, rLOW, rHIGH)    \
62         CHECK_BOUNDS_LOW(rBP, rLOW, rHIGH);     \
63         tdlge   rBP, rHIGH
64
65 /* Check bounds on a memory region of given length, with the side
66    effect that the BP register is converted to its simple pointer
67    value.  */
68
69 # define CHECK_BOUNDS_BOTH_WIDE(rBP, rLOW, rHIGH, rLENGTH)      \
70         CHECK_BOUNDS_LOW (rBP, rLOW, rHIGH);                    \
71         sub     rHIGH, rHIGH, rLENGTH;                          \
72         tdlgt   rBP, rHIGH
73
74 # define CHECK_BOUNDS_BOTH_WIDE_LIT(rBP, rLOW, rHIGH, LENGTH)   \
75         CHECK_BOUNDS_LOW (rBP, rLOW, rHIGH);                    \
76         subi    rHIGH, rHIGH, LENGTH;                           \
77         tdlgt   rBP, rHIGH
78
79 /* Store a pointer value register into the return-value's pointer
80    value slot.  */
81
82 # define STORE_RETURN_VALUE(rVALUE)             \
83         std     rVALUE, oVALUE(rRTN)
84
85 /* Store a low and high bounds into the return-value's pointer bounds
86    slots.  */
87
88 # define STORE_RETURN_BOUNDS(rLOW, rHIGH)       \
89         std     rLOW, oLOW(rRTN);               \
90         std     rHIGH, oHIGH(rRTN)
91
92 /* Stuff zero value/low/high into the BP addressed by rRTN.  */
93
94 # define RETURN_NULL_BOUNDED_POINTER            \
95         li      r4, 0;                          \
96         STORE_RETURN_VALUE (r4);                \
97         STORE_RETURN_BOUNDS (r4, r4)
98
99 #else
100
101 # define DISCARD_BOUNDS(rBP)
102 # define CHECK_BOUNDS_LOW(rBP, rLOW, rHIGH)
103 # define CHECK_BOUNDS_HIGH(rVALUE, rHIGH, TWLcc)
104 # define CHECK_BOUNDS_HIGH_RTN(rVALUE, rHIGH, TWLcc)
105 # define CHECK_BOUNDS_BOTH(rBP, rLOW, rHIGH)
106 # define CHECK_BOUNDS_BOTH_WIDE(rBP, rLOW, rHIGH, rLENGTH)
107 # define CHECK_BOUNDS_BOTH_WIDE_LIT(rBP, rLOW, rHIGH, LENGTH)
108 # define STORE_RETURN_VALUE(rVALUE)
109 # define STORE_RETURN_BOUNDS(rLOW, rHIGH)
110
111 # define RETURN_NULL_BOUNDED_POINTER li rRTN, 0
112
113 #endif