1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (C) 2023 StarFive Technology Co., Ltd. 4 * 5 * Author: Jee Heng Sia <jeeheng.sia@starfivetech.com> 6 */ 7 8 #ifndef __ASSEMBLER__ 9 #error "Only include this from assembly code" 10 #endif 11 12 #ifndef __ASM_ASSEMBLER_H 13 #define __ASM_ASSEMBLER_H 14 15 #include <asm/asm.h> 16 #include <asm/asm-offsets.h> 17 #include <asm/csr.h> 18 19 /* 20 * suspend_restore_csrs - restore CSRs 21 */ 22 .macro suspend_restore_csrs 23 REG_L t0, (SUSPEND_CONTEXT_REGS + PT_EPC)(a0) 24 csrw CSR_EPC, t0 25 REG_L t0, (SUSPEND_CONTEXT_REGS + PT_STATUS)(a0) 26 csrw CSR_STATUS, t0 27 REG_L t0, (SUSPEND_CONTEXT_REGS + PT_BADADDR)(a0) 28 csrw CSR_TVAL, t0 29 REG_L t0, (SUSPEND_CONTEXT_REGS + PT_CAUSE)(a0) 30 csrw CSR_CAUSE, t0 31 .endm 32 33 /* 34 * suspend_restore_regs - Restore registers (except A0 and T0-T6) 35 */ 36 .macro suspend_restore_regs 37 REG_L ra, (SUSPEND_CONTEXT_REGS + PT_RA)(a0) 38 REG_L sp, (SUSPEND_CONTEXT_REGS + PT_SP)(a0) 39 REG_L gp, (SUSPEND_CONTEXT_REGS + PT_GP)(a0) 40 REG_L tp, (SUSPEND_CONTEXT_REGS + PT_TP)(a0) 41 REG_L s0, (SUSPEND_CONTEXT_REGS + PT_S0)(a0) 42 REG_L s1, (SUSPEND_CONTEXT_REGS + PT_S1)(a0) 43 REG_L a1, (SUSPEND_CONTEXT_REGS + PT_A1)(a0) 44 REG_L a2, (SUSPEND_CONTEXT_REGS + PT_A2)(a0) 45 REG_L a3, (SUSPEND_CONTEXT_REGS + PT_A3)(a0) 46 REG_L a4, (SUSPEND_CONTEXT_REGS + PT_A4)(a0) 47 REG_L a5, (SUSPEND_CONTEXT_REGS + PT_A5)(a0) 48 REG_L a6, (SUSPEND_CONTEXT_REGS + PT_A6)(a0) 49 REG_L a7, (SUSPEND_CONTEXT_REGS + PT_A7)(a0) 50 REG_L s2, (SUSPEND_CONTEXT_REGS + PT_S2)(a0) 51 REG_L s3, (SUSPEND_CONTEXT_REGS + PT_S3)(a0) 52 REG_L s4, (SUSPEND_CONTEXT_REGS + PT_S4)(a0) 53 REG_L s5, (SUSPEND_CONTEXT_REGS + PT_S5)(a0) 54 REG_L s6, (SUSPEND_CONTEXT_REGS + PT_S6)(a0) 55 REG_L s7, (SUSPEND_CONTEXT_REGS + PT_S7)(a0) 56 REG_L s8, (SUSPEND_CONTEXT_REGS + PT_S8)(a0) 57 REG_L s9, (SUSPEND_CONTEXT_REGS + PT_S9)(a0) 58 REG_L s10, (SUSPEND_CONTEXT_REGS + PT_S10)(a0) 59 REG_L s11, (SUSPEND_CONTEXT_REGS + PT_S11)(a0) 60 .endm 61 62 /* 63 * copy_page - copy 1 page (4KB) of data from source to destination 64 * @a0 - destination 65 * @a1 - source 66 */ 67 .macro copy_page a0, a1 68 lui a2, 0x1 69 add a2, a2, a0 70 1 : 71 REG_L t0, 0(a1) 72 REG_L t1, SZREG(a1) 73 74 REG_S t0, 0(a0) 75 REG_S t1, SZREG(a0) 76 77 addi a0, a0, 2 * SZREG 78 addi a1, a1, 2 * SZREG 79 bne a2, a0, 1b 80 .endm 81 82 #endif /* __ASM_ASSEMBLER_H */ 83 84 #if defined(VDSO_CFI) && (__riscv_xlen == 64) 85 .macro vdso_lpad, label = 0 86 lpad \label 87 .endm 88 #else 89 .macro vdso_lpad, label = 0 90 .endm 91 #endif 92 93 /* 94 * This macro emits a program property note section identifying 95 * architecture features which require special handling, mainly for 96 * use in assembly files included in the VDSO. 97 */ 98 #define NT_GNU_PROPERTY_TYPE_0 5 99 #define GNU_PROPERTY_RISCV_FEATURE_1_AND 0xc0000000 100 101 #define GNU_PROPERTY_RISCV_FEATURE_1_ZICFILP BIT(0) 102 #define GNU_PROPERTY_RISCV_FEATURE_1_ZICFISS BIT(1) 103 104 #if defined(VDSO_CFI) && (__riscv_xlen == 64) 105 #define GNU_PROPERTY_RISCV_FEATURE_1_DEFAULT \ 106 (GNU_PROPERTY_RISCV_FEATURE_1_ZICFILP | GNU_PROPERTY_RISCV_FEATURE_1_ZICFISS) 107 #endif 108 109 #ifdef GNU_PROPERTY_RISCV_FEATURE_1_DEFAULT 110 .macro emit_riscv_feature_1_and, feat = GNU_PROPERTY_RISCV_FEATURE_1_DEFAULT 111 .pushsection .note.gnu.property, "a" 112 .p2align 3 113 .word 4 114 .word 16 115 .word NT_GNU_PROPERTY_TYPE_0 116 .asciz "GNU" 117 .word GNU_PROPERTY_RISCV_FEATURE_1_AND 118 .word 4 119 .word \feat 120 .word 0 121 .popsection 122 .endm 123 #else 124 .macro emit_riscv_feature_1_and, feat = 0 125 .endm 126 #endif 127