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