13d8536b4Sopenharmony_ci/* 23d8536b4Sopenharmony_ci * Copyright (c) 2013-2020, Huawei Technologies Co., Ltd. All rights reserved. 33d8536b4Sopenharmony_ci * Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved. 43d8536b4Sopenharmony_ci * 53d8536b4Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification, 63d8536b4Sopenharmony_ci * are permitted provided that the following conditions are met: 73d8536b4Sopenharmony_ci * 83d8536b4Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of 93d8536b4Sopenharmony_ci * conditions and the following disclaimer. 103d8536b4Sopenharmony_ci * 113d8536b4Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list 123d8536b4Sopenharmony_ci * of conditions and the following disclaimer in the documentation and/or other materials 133d8536b4Sopenharmony_ci * provided with the distribution. 143d8536b4Sopenharmony_ci * 153d8536b4Sopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used 163d8536b4Sopenharmony_ci * to endorse or promote products derived from this software without specific prior written 173d8536b4Sopenharmony_ci * permission. 183d8536b4Sopenharmony_ci * 193d8536b4Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 203d8536b4Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 213d8536b4Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 223d8536b4Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 233d8536b4Sopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 243d8536b4Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 253d8536b4Sopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 263d8536b4Sopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 273d8536b4Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 283d8536b4Sopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 293d8536b4Sopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 303d8536b4Sopenharmony_ci */ 313d8536b4Sopenharmony_ci 323d8536b4Sopenharmony_ci#ifndef _SOC_COMMON_H 333d8536b4Sopenharmony_ci#define _SOC_COMMON_H 343d8536b4Sopenharmony_ci 353d8536b4Sopenharmony_ci#define LREG lw 363d8536b4Sopenharmony_ci#define SREG sw 373d8536b4Sopenharmony_ci#define REGBYTES 4 383d8536b4Sopenharmony_ci 393d8536b4Sopenharmony_ci#define EXC_SIZE_ON_STACK (36 * REGBYTES) 403d8536b4Sopenharmony_ci#define INT_SIZE_ON_STACK (32 * REGBYTES) 413d8536b4Sopenharmony_ci 423d8536b4Sopenharmony_ci/* task TCB offset */ 433d8536b4Sopenharmony_ci#define TASK_CB_KERNEL_SP 0x0 443d8536b4Sopenharmony_ci#define TASK_CB_STATUS 0x4 453d8536b4Sopenharmony_ci 463d8536b4Sopenharmony_ci#define UINT32_CUT_MASK 0xFFFFFFFF 473d8536b4Sopenharmony_ci#define UINT8_CUT_MASK 0xFF 483d8536b4Sopenharmony_ci#define OS_MV_32_BIT 32 493d8536b4Sopenharmony_ci 503d8536b4Sopenharmony_ci/************************ mstatus ************************/ 513d8536b4Sopenharmony_ci#define RISCV_MSTATUS_UIE 0x00000001 523d8536b4Sopenharmony_ci#define RISCV_MSTATUS_MIE 0x00000008 533d8536b4Sopenharmony_ci#define RISCV_MSTATUS_UPIE 0x00000010 543d8536b4Sopenharmony_ci#define RISCV_MSTATUS_MPIE 0x00000080 553d8536b4Sopenharmony_ci#define RISCV_MSTATUS_MPP 0x00001800 563d8536b4Sopenharmony_ci 573d8536b4Sopenharmony_ci/************************ mie ***************************/ 583d8536b4Sopenharmony_ci#define RISCV_MIE_USIE 0x000000001 593d8536b4Sopenharmony_ci#define RISCV_MIE_MSIE 0x000000008 603d8536b4Sopenharmony_ci#define RISCV_MIE_UTIE 0x000000010 613d8536b4Sopenharmony_ci#define RISCV_MIE_MTIE 0x000000080 623d8536b4Sopenharmony_ci#define RISCV_MIE_UEIE 0x000000100 633d8536b4Sopenharmony_ci#define RISCV_MIE_MEIE 0x000000800 643d8536b4Sopenharmony_ci 653d8536b4Sopenharmony_ci/************************** mcause ***********************/ 663d8536b4Sopenharmony_ci#ifndef MCAUSE_INT_ID_MASK 673d8536b4Sopenharmony_ci#define MCAUSE_INT_ID_MASK 0x7FFFFFF 683d8536b4Sopenharmony_ci#endif 693d8536b4Sopenharmony_ci#define RISCV_MCAUSE_ECALL_U 8 703d8536b4Sopenharmony_ci 713d8536b4Sopenharmony_ci#define RISCV_USER_SOFT_IRQ 0 723d8536b4Sopenharmony_ci#define RISCV_MACH_SOFT_IRQ 3 733d8536b4Sopenharmony_ci#define RISCV_USER_TIMER_IRQ 4 743d8536b4Sopenharmony_ci#define RISCV_MACH_TIMER_IRQ 7 753d8536b4Sopenharmony_ci#define RISCV_USER_EXT_IRQ 8 763d8536b4Sopenharmony_ci#define RISCV_MACH_EXT_IRQ 11 773d8536b4Sopenharmony_ci 783d8536b4Sopenharmony_ci#define READ_CSR(reg) ({ \ 793d8536b4Sopenharmony_ci UINT32 _tmp; \ 803d8536b4Sopenharmony_ci __asm__ volatile("csrr %0, " #reg : "=r"(_tmp) : : "memory"); \ 813d8536b4Sopenharmony_ci _tmp; \ 823d8536b4Sopenharmony_ci}) 833d8536b4Sopenharmony_ci 843d8536b4Sopenharmony_ci#define WRITE_CSR(reg, val) ({ \ 853d8536b4Sopenharmony_ci __asm__ volatile("csrw " #reg ", %0" : : "r"(val) : "memory"); \ 863d8536b4Sopenharmony_ci}) 873d8536b4Sopenharmony_ci 883d8536b4Sopenharmony_ci#define SET_CSR(reg, val) ({ \ 893d8536b4Sopenharmony_ci __asm__ volatile("csrs " #reg ", %0" : : "r"(val) : "memory"); \ 903d8536b4Sopenharmony_ci}) 913d8536b4Sopenharmony_ci 923d8536b4Sopenharmony_ci#define CLEAR_CSR(reg, val) ({ \ 933d8536b4Sopenharmony_ci __asm__ volatile("csrc " #reg ", %0" : : "r"(val) : "memory"); \ 943d8536b4Sopenharmony_ci}) 953d8536b4Sopenharmony_ci 963d8536b4Sopenharmony_ci#define READ_CUSTOM_CSR(reg) ({ \ 973d8536b4Sopenharmony_ci UINT32 _tmp; \ 983d8536b4Sopenharmony_ci __asm__ volatile("csrr %0, %1" : "=r"(_tmp) : "i"(reg) : "memory"); \ 993d8536b4Sopenharmony_ci _tmp; \ 1003d8536b4Sopenharmony_ci}) 1013d8536b4Sopenharmony_ci 1023d8536b4Sopenharmony_ci#define WRITE_CUSTOM_CSR(reg, val) ({ \ 1033d8536b4Sopenharmony_ci __asm__ volatile("csrw %0, %1" : : "i"(reg), "r"(val) : "memory"); \ 1043d8536b4Sopenharmony_ci}) 1053d8536b4Sopenharmony_ci 1063d8536b4Sopenharmony_ci#define SET_CUSTOM_CSR(reg, val) ({ \ 1073d8536b4Sopenharmony_ci __asm__ volatile("csrs " #reg ", %0" : : "r"(val) : "memory"); \ 1083d8536b4Sopenharmony_ci}) 1093d8536b4Sopenharmony_ci 1103d8536b4Sopenharmony_ci#define CLEAR_CUSTOM_CSR(reg, val) ({ \ 1113d8536b4Sopenharmony_ci __asm__ volatile("csrc " #reg ", %0" : : "r"(val) : "memory"); \ 1123d8536b4Sopenharmony_ci}) 1133d8536b4Sopenharmony_ci 1143d8536b4Sopenharmony_ci#endif 115