Home | History | Annotate | Line # | Download | only in include
reg.h revision 1.1.2.1
      1  1.1.2.1  skrll /* $NetBSD: reg.h,v 1.1.2.1 2015/04/06 15:18:01 skrll Exp $ */
      2      1.1   matt 
      3      1.1   matt /*-
      4      1.1   matt  * Copyright (c) 2014 The NetBSD Foundation, Inc.
      5      1.1   matt  * All rights reserved.
      6      1.1   matt  *
      7      1.1   matt  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1   matt  * by Matt Thomas of 3am Software Foundry.
      9      1.1   matt  *
     10      1.1   matt  * Redistribution and use in source and binary forms, with or without
     11      1.1   matt  * modification, are permitted provided that the following conditions
     12      1.1   matt  * are met:
     13      1.1   matt  * 1. Redistributions of source code must retain the above copyright
     14      1.1   matt  *    notice, this list of conditions and the following disclaimer.
     15      1.1   matt  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1   matt  *    notice, this list of conditions and the following disclaimer in the
     17      1.1   matt  *    documentation and/or other materials provided with the distribution.
     18      1.1   matt  *
     19      1.1   matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20      1.1   matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21      1.1   matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22      1.1   matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23      1.1   matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24      1.1   matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25      1.1   matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26      1.1   matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27      1.1   matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28      1.1   matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29      1.1   matt  * POSSIBILITY OF SUCH DAMAGE.
     30      1.1   matt  */
     31      1.1   matt 
     32      1.1   matt #ifndef _RISCV_REG_H_
     33      1.1   matt #define _RISCV_REG_H_
     34      1.1   matt 
     35      1.1   matt // x0 = 0
     36      1.1   matt // x1 = ra (return address)
     37  1.1.2.1  skrll // x2 = sp (stack pointer)
     38  1.1.2.1  skrll // x3 = gp (global pointer)
     39  1.1.2.1  skrll // x4 = tp (thread pointer)
     40  1.1.2.1  skrll // x5-x7 = t0-t2 (temporary)
     41  1.1.2.1  skrll // x8 = s0/fp (saved register / frame pointer)
     42  1.1.2.1  skrll // x9 = s1 (saved register)
     43  1.1.2.1  skrll // x10-x11 = a0-a1 (arguments/return values)
     44  1.1.2.1  skrll // x12-x17 = a2-a7 (arguments)
     45  1.1.2.1  skrll // x18-r27 = s2-s11 (saved registers)
     46  1.1.2.1  skrll // x28-x31 = t3-r6 (temporaries)
     47      1.1   matt // x26-x30 = t0-t4 (temporary)
     48      1.1   matt 
     49      1.1   matt struct reg {	// synced with register_t in <riscv/types.h>
     50      1.1   matt #ifdef _LP64
     51      1.1   matt 	__uint64_t r_reg[31]; /* x0 is always 0 */
     52      1.1   matt 	__uint64_t r_pc;
     53      1.1   matt #else
     54      1.1   matt 	__uint32_t r_reg[31]; /* x0 is always 0 */
     55      1.1   matt 	__uint32_t r_pc;
     56      1.1   matt #endif
     57      1.1   matt };
     58      1.1   matt 
     59      1.1   matt #ifdef _LP64
     60      1.1   matt struct reg32 {	// synced with register_t in <riscv/types.h>
     61      1.1   matt 	__uint32_t r_reg[31]; /* x0 is always 0 */
     62      1.1   matt 	__uint32_t r_pc;
     63      1.1   matt };
     64      1.1   matt #endif
     65      1.1   matt 
     66      1.1   matt #define _XREG(n)	((n)-1)
     67      1.1   matt #define _X_RA		_XREG(1)
     68  1.1.2.1  skrll #define _X_SP		_XREG(2)
     69  1.1.2.1  skrll #define _X_GP		_XREG(3)
     70  1.1.2.1  skrll #define _X_TP		_XREG(4)
     71  1.1.2.1  skrll #define _X_T0		_XREG(5)
     72  1.1.2.1  skrll #define _X_T1		_XREG(6)
     73  1.1.2.1  skrll #define _X_T2		_XREG(7)
     74  1.1.2.1  skrll #define _X_S0		_XREG(8)
     75  1.1.2.1  skrll #define _X_S1		_XREG(9)
     76  1.1.2.1  skrll #define _X_A0		_XREG(10)
     77  1.1.2.1  skrll #define _X_A1		_XREG(11)
     78  1.1.2.1  skrll #define _X_A2		_XREG(12)
     79  1.1.2.1  skrll #define _X_A3		_XREG(13)
     80  1.1.2.1  skrll #define _X_A4		_XREG(14)
     81  1.1.2.1  skrll #define _X_A5		_XREG(15)
     82  1.1.2.1  skrll #define _X_A6		_XREG(16)
     83  1.1.2.1  skrll #define _X_A7		_XREG(17)
     84  1.1.2.1  skrll #define _X_S2		_XREG(18)
     85  1.1.2.1  skrll #define _X_S3		_XREG(19)
     86  1.1.2.1  skrll #define _X_S4		_XREG(20)
     87  1.1.2.1  skrll #define _X_S5		_XREG(21)
     88  1.1.2.1  skrll #define _X_S6		_XREG(22)
     89  1.1.2.1  skrll #define _X_S7		_XREG(23)
     90  1.1.2.1  skrll #define _X_S8		_XREG(24)
     91  1.1.2.1  skrll #define _X_S9		_XREG(25)
     92  1.1.2.1  skrll #define _X_S10		_XREG(26)
     93  1.1.2.1  skrll #define _X_S11		_XREG(27)
     94  1.1.2.1  skrll #define _X_T3		_XREG(28)
     95  1.1.2.1  skrll #define _X_T4		_XREG(29)
     96  1.1.2.1  skrll #define _X_T5		_XREG(30)
     97  1.1.2.1  skrll #define _X_T6		_XREG(31)
     98  1.1.2.1  skrll 
     99  1.1.2.1  skrll // f0-f7 = ft0-ft7 (FP temporaries)
    100  1.1.2.1  skrll // following layout is similar to integer registers above
    101  1.1.2.1  skrll // f8-f9 = fs0-fs1 (FP saved registers)
    102  1.1.2.1  skrll // f10-f11 = fa0-fa1 (FP arguments/return values)
    103  1.1.2.1  skrll // f12-f17 = fa2-fa7 (FP arguments)
    104  1.1.2.1  skrll // f18-f27 = fs2-fa11 (FP saved registers)
    105  1.1.2.1  skrll // f28-f31 = ft8-ft11 (FP temporaries)
    106      1.1   matt 
    107      1.1   matt /*
    108      1.1   matt  * This fragment is common to <riscv/mcontext.h> and <riscv/reg.h>
    109      1.1   matt  */
    110      1.1   matt #ifndef _BSD_FPREG_T_
    111      1.1   matt union __fpreg {
    112      1.1   matt 		__uint64_t u_u64;
    113      1.1   matt 		double u_d;
    114      1.1   matt };
    115      1.1   matt #define _BSD_FPREG_T_	union __fpreg
    116      1.1   matt #endif
    117      1.1   matt 
    118      1.1   matt /*
    119      1.1   matt  * 32 double precision floating point, 1 CSR
    120      1.1   matt  */
    121      1.1   matt struct fpreg {
    122      1.1   matt 	_BSD_FPREG_T_	r_fpreg[33];
    123      1.1   matt };
    124      1.1   matt #define r_fcsr		r_fpreg[32].u_u64
    125      1.1   matt 
    126      1.1   matt #endif /* _RISCV_REG_H_ */
    127