Back to index

glibc  2.9
bp-asm.h
Go to the documentation of this file.
00001 /* Bounded-pointer definitions for PowerPC assembler.
00002    Copyright (C) 2000 Free Software Foundation, Inc.
00003    Contributed by Greg McGary <greg@mcgary.org>
00004    This file is part of the GNU C Library.  Its master source is NOT part of
00005    the C library, however.  The master source lives in the GNU MP Library.
00006 
00007    The GNU C Library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2.1 of the License, or (at your option) any later version.
00011 
00012    The GNU C Library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Lesser General Public License for more details.
00016 
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with the GNU C Library; if not, write to the Free
00019    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00020    02111-1307 USA.  */
00021 
00022 #if __BOUNDED_POINTERS__
00023 
00024 /* Byte offsets of BP components.  */
00025 # define oVALUE      0
00026 # define oLOW 4
00027 # define oHIGH       8
00028 
00029 /* Don't check bounds, just convert the BP register to its simple
00030    pointer value.  */
00031 
00032 # define DISCARD_BOUNDS(rBP)                     \
00033        lwz    rBP, oVALUE(rBP)
00034 
00035 /* Check low bound, with the side effect that the BP register is converted
00036    its simple pointer value.  Move the high bound into a register for
00037    later use.  */
00038 
00039 # define CHECK_BOUNDS_LOW(rBP, rLOW, rHIGH)      \
00040        lwz    rHIGH, oHIGH(rBP);          \
00041        lwz    rLOW, oLOW(rBP);            \
00042        lwz    rBP, oVALUE(rBP);           \
00043        twllt  rBP, rLOW
00044 
00045 /* Check the high bound, which is in a register, using the given
00046    conditional trap instruction.  */
00047 
00048 # define CHECK_BOUNDS_HIGH(rVALUE, rHIGH, TWLcc) \
00049        TWLcc  rVALUE, rHIGH
00050 
00051 /* Check the high bound, which is stored at the return-value's high
00052    bound slot, using the given conditional trap instruction.  */
00053 
00054 # define CHECK_BOUNDS_HIGH_RTN(rVALUE, rHIGH, TWLcc)    \
00055        lwz    rHIGH, oHIGH(rRTN);                \
00056        TWLcc  rVALUE, rHIGH
00057 
00058 /* Check both bounds, with the side effect that the BP register is
00059    converted to its simple pointer value.  */
00060 
00061 # define CHECK_BOUNDS_BOTH(rBP, rLOW, rHIGH)     \
00062        CHECK_BOUNDS_LOW(rBP, rLOW, rHIGH);       \
00063        twlge  rBP, rHIGH
00064 
00065 /* Check bounds on a memory region of given length, with the side
00066    effect that the BP register is converted to its simple pointer
00067    value.  */
00068 
00069 # define CHECK_BOUNDS_BOTH_WIDE(rBP, rLOW, rHIGH, rLENGTH)     \
00070        CHECK_BOUNDS_LOW (rBP, rLOW, rHIGH);                    \
00071        sub    rHIGH, rHIGH, rLENGTH;                           \
00072        twlgt  rBP, rHIGH
00073 
00074 # define CHECK_BOUNDS_BOTH_WIDE_LIT(rBP, rLOW, rHIGH, LENGTH)  \
00075        CHECK_BOUNDS_LOW (rBP, rLOW, rHIGH);                    \
00076        subi   rHIGH, rHIGH, LENGTH;                            \
00077        twlgt  rBP, rHIGH
00078 
00079 /* Store a pointer value register into the return-value's pointer
00080    value slot.  */
00081 
00082 # define STORE_RETURN_VALUE(rVALUE)              \
00083        stw    rVALUE, oVALUE(rRTN)
00084 
00085 /* Store a low and high bounds into the return-value's pointer bounds
00086    slots.  */
00087 
00088 # define STORE_RETURN_BOUNDS(rLOW, rHIGH) \
00089        stw    rLOW, oLOW(rRTN);           \
00090        stw    rHIGH, oHIGH(rRTN)
00091 
00092 /* Stuff zero value/low/high into the BP addressed by rRTN.  */
00093 
00094 # define RETURN_NULL_BOUNDED_POINTER             \
00095        li     r4, 0;                      \
00096        STORE_RETURN_VALUE (r4);           \
00097        STORE_RETURN_BOUNDS (r4, r4)
00098 
00099 #else
00100 
00101 # define DISCARD_BOUNDS(rBP)
00102 # define CHECK_BOUNDS_LOW(rBP, rLOW, rHIGH)
00103 # define CHECK_BOUNDS_HIGH(rVALUE, rHIGH, TWLcc)
00104 # define CHECK_BOUNDS_HIGH_RTN(rVALUE, rHIGH, TWLcc)
00105 # define CHECK_BOUNDS_BOTH(rBP, rLOW, rHIGH)
00106 # define CHECK_BOUNDS_BOTH_WIDE(rBP, rLOW, rHIGH, rLENGTH)
00107 # define CHECK_BOUNDS_BOTH_WIDE_LIT(rBP, rLOW, rHIGH, LENGTH)
00108 # define STORE_RETURN_VALUE(rVALUE)
00109 # define STORE_RETURN_BOUNDS(rLOW, rHIGH)
00110 
00111 # define RETURN_NULL_BOUNDED_POINTER li rRTN, 0
00112 
00113 #endif
00114