18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * MT regs definitions, follows on from mipsregs.h 48c2ecf20Sopenharmony_ci * Copyright (C) 2004 - 2005 MIPS Technologies, Inc. All rights reserved. 58c2ecf20Sopenharmony_ci * Elizabeth Clarke et. al. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci#ifndef _ASM_MIPSMTREGS_H 98c2ecf20Sopenharmony_ci#define _ASM_MIPSMTREGS_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <asm/mipsregs.h> 128c2ecf20Sopenharmony_ci#include <asm/war.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/* 178c2ecf20Sopenharmony_ci * C macros 188c2ecf20Sopenharmony_ci */ 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define read_c0_mvpcontrol() __read_32bit_c0_register($0, 1) 218c2ecf20Sopenharmony_ci#define write_c0_mvpcontrol(val) __write_32bit_c0_register($0, 1, val) 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define read_c0_mvpconf0() __read_32bit_c0_register($0, 2) 248c2ecf20Sopenharmony_ci#define read_c0_mvpconf1() __read_32bit_c0_register($0, 3) 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#define read_c0_vpecontrol() __read_32bit_c0_register($1, 1) 278c2ecf20Sopenharmony_ci#define write_c0_vpecontrol(val) __write_32bit_c0_register($1, 1, val) 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#define read_c0_vpeconf0() __read_32bit_c0_register($1, 2) 308c2ecf20Sopenharmony_ci#define write_c0_vpeconf0(val) __write_32bit_c0_register($1, 2, val) 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#define read_c0_vpeconf1() __read_32bit_c0_register($1, 3) 338c2ecf20Sopenharmony_ci#define write_c0_vpeconf1(val) __write_32bit_c0_register($1, 3, val) 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#define read_c0_tcstatus() __read_32bit_c0_register($2, 1) 368c2ecf20Sopenharmony_ci#define write_c0_tcstatus(val) __write_32bit_c0_register($2, 1, val) 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define read_c0_tcbind() __read_32bit_c0_register($2, 2) 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci#define write_c0_tchalt(val) __write_32bit_c0_register($2, 4, val) 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define read_c0_tccontext() __read_32bit_c0_register($2, 5) 438c2ecf20Sopenharmony_ci#define write_c0_tccontext(val) __write_32bit_c0_register($2, 5, val) 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#else /* Assembly */ 468c2ecf20Sopenharmony_ci/* 478c2ecf20Sopenharmony_ci * Macros for use in assembly language code 488c2ecf20Sopenharmony_ci */ 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#define CP0_MVPCONTROL $0, 1 518c2ecf20Sopenharmony_ci#define CP0_MVPCONF0 $0, 2 528c2ecf20Sopenharmony_ci#define CP0_MVPCONF1 $0, 3 538c2ecf20Sopenharmony_ci#define CP0_VPECONTROL $1, 1 548c2ecf20Sopenharmony_ci#define CP0_VPECONF0 $1, 2 558c2ecf20Sopenharmony_ci#define CP0_VPECONF1 $1, 3 568c2ecf20Sopenharmony_ci#define CP0_YQMASK $1, 4 578c2ecf20Sopenharmony_ci#define CP0_VPESCHEDULE $1, 5 588c2ecf20Sopenharmony_ci#define CP0_VPESCHEFBK $1, 6 598c2ecf20Sopenharmony_ci#define CP0_TCSTATUS $2, 1 608c2ecf20Sopenharmony_ci#define CP0_TCBIND $2, 2 618c2ecf20Sopenharmony_ci#define CP0_TCRESTART $2, 3 628c2ecf20Sopenharmony_ci#define CP0_TCHALT $2, 4 638c2ecf20Sopenharmony_ci#define CP0_TCCONTEXT $2, 5 648c2ecf20Sopenharmony_ci#define CP0_TCSCHEDULE $2, 6 658c2ecf20Sopenharmony_ci#define CP0_TCSCHEFBK $2, 7 668c2ecf20Sopenharmony_ci#define CP0_SRSCONF0 $6, 1 678c2ecf20Sopenharmony_ci#define CP0_SRSCONF1 $6, 2 688c2ecf20Sopenharmony_ci#define CP0_SRSCONF2 $6, 3 698c2ecf20Sopenharmony_ci#define CP0_SRSCONF3 $6, 4 708c2ecf20Sopenharmony_ci#define CP0_SRSCONF4 $6, 5 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci#endif 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci/* MVPControl fields */ 758c2ecf20Sopenharmony_ci#define MVPCONTROL_EVP (_ULCAST_(1)) 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci#define MVPCONTROL_VPC_SHIFT 1 788c2ecf20Sopenharmony_ci#define MVPCONTROL_VPC (_ULCAST_(1) << MVPCONTROL_VPC_SHIFT) 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci#define MVPCONTROL_STLB_SHIFT 2 818c2ecf20Sopenharmony_ci#define MVPCONTROL_STLB (_ULCAST_(1) << MVPCONTROL_STLB_SHIFT) 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci/* MVPConf0 fields */ 858c2ecf20Sopenharmony_ci#define MVPCONF0_PTC_SHIFT 0 868c2ecf20Sopenharmony_ci#define MVPCONF0_PTC ( _ULCAST_(0xff)) 878c2ecf20Sopenharmony_ci#define MVPCONF0_PVPE_SHIFT 10 888c2ecf20Sopenharmony_ci#define MVPCONF0_PVPE ( _ULCAST_(0xf) << MVPCONF0_PVPE_SHIFT) 898c2ecf20Sopenharmony_ci#define MVPCONF0_TCA_SHIFT 15 908c2ecf20Sopenharmony_ci#define MVPCONF0_TCA ( _ULCAST_(1) << MVPCONF0_TCA_SHIFT) 918c2ecf20Sopenharmony_ci#define MVPCONF0_PTLBE_SHIFT 16 928c2ecf20Sopenharmony_ci#define MVPCONF0_PTLBE (_ULCAST_(0x3ff) << MVPCONF0_PTLBE_SHIFT) 938c2ecf20Sopenharmony_ci#define MVPCONF0_TLBS_SHIFT 29 948c2ecf20Sopenharmony_ci#define MVPCONF0_TLBS (_ULCAST_(1) << MVPCONF0_TLBS_SHIFT) 958c2ecf20Sopenharmony_ci#define MVPCONF0_M_SHIFT 31 968c2ecf20Sopenharmony_ci#define MVPCONF0_M (_ULCAST_(0x1) << MVPCONF0_M_SHIFT) 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/* config3 fields */ 1008c2ecf20Sopenharmony_ci#define CONFIG3_MT_SHIFT 2 1018c2ecf20Sopenharmony_ci#define CONFIG3_MT (_ULCAST_(1) << CONFIG3_MT_SHIFT) 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci/* VPEControl fields (per VPE) */ 1058c2ecf20Sopenharmony_ci#define VPECONTROL_TARGTC (_ULCAST_(0xff)) 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci#define VPECONTROL_TE_SHIFT 15 1088c2ecf20Sopenharmony_ci#define VPECONTROL_TE (_ULCAST_(1) << VPECONTROL_TE_SHIFT) 1098c2ecf20Sopenharmony_ci#define VPECONTROL_EXCPT_SHIFT 16 1108c2ecf20Sopenharmony_ci#define VPECONTROL_EXCPT (_ULCAST_(0x7) << VPECONTROL_EXCPT_SHIFT) 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci/* Thread Exception Codes for EXCPT field */ 1138c2ecf20Sopenharmony_ci#define THREX_TU 0 1148c2ecf20Sopenharmony_ci#define THREX_TO 1 1158c2ecf20Sopenharmony_ci#define THREX_IYQ 2 1168c2ecf20Sopenharmony_ci#define THREX_GSX 3 1178c2ecf20Sopenharmony_ci#define THREX_YSCH 4 1188c2ecf20Sopenharmony_ci#define THREX_GSSCH 5 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci#define VPECONTROL_GSI_SHIFT 20 1218c2ecf20Sopenharmony_ci#define VPECONTROL_GSI (_ULCAST_(1) << VPECONTROL_GSI_SHIFT) 1228c2ecf20Sopenharmony_ci#define VPECONTROL_YSI_SHIFT 21 1238c2ecf20Sopenharmony_ci#define VPECONTROL_YSI (_ULCAST_(1) << VPECONTROL_YSI_SHIFT) 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci/* VPEConf0 fields (per VPE) */ 1268c2ecf20Sopenharmony_ci#define VPECONF0_VPA_SHIFT 0 1278c2ecf20Sopenharmony_ci#define VPECONF0_VPA (_ULCAST_(1) << VPECONF0_VPA_SHIFT) 1288c2ecf20Sopenharmony_ci#define VPECONF0_MVP_SHIFT 1 1298c2ecf20Sopenharmony_ci#define VPECONF0_MVP (_ULCAST_(1) << VPECONF0_MVP_SHIFT) 1308c2ecf20Sopenharmony_ci#define VPECONF0_XTC_SHIFT 21 1318c2ecf20Sopenharmony_ci#define VPECONF0_XTC (_ULCAST_(0xff) << VPECONF0_XTC_SHIFT) 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci/* VPEConf1 fields (per VPE) */ 1348c2ecf20Sopenharmony_ci#define VPECONF1_NCP1_SHIFT 0 1358c2ecf20Sopenharmony_ci#define VPECONF1_NCP1 (_ULCAST_(0xff) << VPECONF1_NCP1_SHIFT) 1368c2ecf20Sopenharmony_ci#define VPECONF1_NCP2_SHIFT 10 1378c2ecf20Sopenharmony_ci#define VPECONF1_NCP2 (_ULCAST_(0xff) << VPECONF1_NCP2_SHIFT) 1388c2ecf20Sopenharmony_ci#define VPECONF1_NCX_SHIFT 20 1398c2ecf20Sopenharmony_ci#define VPECONF1_NCX (_ULCAST_(0xff) << VPECONF1_NCX_SHIFT) 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci/* TCStatus fields (per TC) */ 1428c2ecf20Sopenharmony_ci#define TCSTATUS_TASID (_ULCAST_(0xff)) 1438c2ecf20Sopenharmony_ci#define TCSTATUS_IXMT_SHIFT 10 1448c2ecf20Sopenharmony_ci#define TCSTATUS_IXMT (_ULCAST_(1) << TCSTATUS_IXMT_SHIFT) 1458c2ecf20Sopenharmony_ci#define TCSTATUS_TKSU_SHIFT 11 1468c2ecf20Sopenharmony_ci#define TCSTATUS_TKSU (_ULCAST_(3) << TCSTATUS_TKSU_SHIFT) 1478c2ecf20Sopenharmony_ci#define TCSTATUS_A_SHIFT 13 1488c2ecf20Sopenharmony_ci#define TCSTATUS_A (_ULCAST_(1) << TCSTATUS_A_SHIFT) 1498c2ecf20Sopenharmony_ci#define TCSTATUS_DA_SHIFT 15 1508c2ecf20Sopenharmony_ci#define TCSTATUS_DA (_ULCAST_(1) << TCSTATUS_DA_SHIFT) 1518c2ecf20Sopenharmony_ci#define TCSTATUS_DT_SHIFT 20 1528c2ecf20Sopenharmony_ci#define TCSTATUS_DT (_ULCAST_(1) << TCSTATUS_DT_SHIFT) 1538c2ecf20Sopenharmony_ci#define TCSTATUS_TDS_SHIFT 21 1548c2ecf20Sopenharmony_ci#define TCSTATUS_TDS (_ULCAST_(1) << TCSTATUS_TDS_SHIFT) 1558c2ecf20Sopenharmony_ci#define TCSTATUS_TSST_SHIFT 22 1568c2ecf20Sopenharmony_ci#define TCSTATUS_TSST (_ULCAST_(1) << TCSTATUS_TSST_SHIFT) 1578c2ecf20Sopenharmony_ci#define TCSTATUS_RNST_SHIFT 23 1588c2ecf20Sopenharmony_ci#define TCSTATUS_RNST (_ULCAST_(3) << TCSTATUS_RNST_SHIFT) 1598c2ecf20Sopenharmony_ci/* Codes for RNST */ 1608c2ecf20Sopenharmony_ci#define TC_RUNNING 0 1618c2ecf20Sopenharmony_ci#define TC_WAITING 1 1628c2ecf20Sopenharmony_ci#define TC_YIELDING 2 1638c2ecf20Sopenharmony_ci#define TC_GATED 3 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci#define TCSTATUS_TMX_SHIFT 27 1668c2ecf20Sopenharmony_ci#define TCSTATUS_TMX (_ULCAST_(1) << TCSTATUS_TMX_SHIFT) 1678c2ecf20Sopenharmony_ci/* TCStatus TCU bits can use same definitions/offsets as CU bits in Status */ 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci/* TCBind */ 1708c2ecf20Sopenharmony_ci#define TCBIND_CURVPE_SHIFT 0 1718c2ecf20Sopenharmony_ci#define TCBIND_CURVPE (_ULCAST_(0xf)) 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci#define TCBIND_CURTC_SHIFT 21 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci#define TCBIND_CURTC (_ULCAST_(0xff) << TCBIND_CURTC_SHIFT) 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci/* TCHalt */ 1788c2ecf20Sopenharmony_ci#define TCHALT_H (_ULCAST_(1)) 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_cistatic inline unsigned core_nvpes(void) 1838c2ecf20Sopenharmony_ci{ 1848c2ecf20Sopenharmony_ci unsigned conf0; 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci if (!cpu_has_mipsmt) 1878c2ecf20Sopenharmony_ci return 1; 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci conf0 = read_c0_mvpconf0(); 1908c2ecf20Sopenharmony_ci return ((conf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1; 1918c2ecf20Sopenharmony_ci} 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_cistatic inline unsigned int dvpe(void) 1948c2ecf20Sopenharmony_ci{ 1958c2ecf20Sopenharmony_ci int res = 0; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci __asm__ __volatile__( 1988c2ecf20Sopenharmony_ci " .set push \n" 1998c2ecf20Sopenharmony_ci " .set noreorder \n" 2008c2ecf20Sopenharmony_ci " .set noat \n" 2018c2ecf20Sopenharmony_ci " .set mips32r2 \n" 2028c2ecf20Sopenharmony_ci " .word 0x41610001 # dvpe $1 \n" 2038c2ecf20Sopenharmony_ci " move %0, $1 \n" 2048c2ecf20Sopenharmony_ci " ehb \n" 2058c2ecf20Sopenharmony_ci " .set pop \n" 2068c2ecf20Sopenharmony_ci : "=r" (res)); 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci instruction_hazard(); 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci return res; 2118c2ecf20Sopenharmony_ci} 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_cistatic inline void __raw_evpe(void) 2148c2ecf20Sopenharmony_ci{ 2158c2ecf20Sopenharmony_ci __asm__ __volatile__( 2168c2ecf20Sopenharmony_ci " .set push \n" 2178c2ecf20Sopenharmony_ci " .set noreorder \n" 2188c2ecf20Sopenharmony_ci " .set noat \n" 2198c2ecf20Sopenharmony_ci " .set mips32r2 \n" 2208c2ecf20Sopenharmony_ci " .word 0x41600021 # evpe \n" 2218c2ecf20Sopenharmony_ci " ehb \n" 2228c2ecf20Sopenharmony_ci " .set pop \n"); 2238c2ecf20Sopenharmony_ci} 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci/* Enable virtual processor execution if previous suggested it should be. 2268c2ecf20Sopenharmony_ci EVPE_ENABLE to force */ 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci#define EVPE_ENABLE MVPCONTROL_EVP 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_cistatic inline void evpe(int previous) 2318c2ecf20Sopenharmony_ci{ 2328c2ecf20Sopenharmony_ci if ((previous & MVPCONTROL_EVP)) 2338c2ecf20Sopenharmony_ci __raw_evpe(); 2348c2ecf20Sopenharmony_ci} 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_cistatic inline unsigned int dmt(void) 2378c2ecf20Sopenharmony_ci{ 2388c2ecf20Sopenharmony_ci int res; 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci __asm__ __volatile__( 2418c2ecf20Sopenharmony_ci " .set push \n" 2428c2ecf20Sopenharmony_ci " .set mips32r2 \n" 2438c2ecf20Sopenharmony_ci " .set noat \n" 2448c2ecf20Sopenharmony_ci " .word 0x41610BC1 # dmt $1 \n" 2458c2ecf20Sopenharmony_ci " ehb \n" 2468c2ecf20Sopenharmony_ci " move %0, $1 \n" 2478c2ecf20Sopenharmony_ci " .set pop \n" 2488c2ecf20Sopenharmony_ci : "=r" (res)); 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci instruction_hazard(); 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci return res; 2538c2ecf20Sopenharmony_ci} 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_cistatic inline void __raw_emt(void) 2568c2ecf20Sopenharmony_ci{ 2578c2ecf20Sopenharmony_ci __asm__ __volatile__( 2588c2ecf20Sopenharmony_ci " .set push \n" 2598c2ecf20Sopenharmony_ci " .set noreorder \n" 2608c2ecf20Sopenharmony_ci " .set mips32r2 \n" 2618c2ecf20Sopenharmony_ci " .word 0x41600be1 # emt \n" 2628c2ecf20Sopenharmony_ci " ehb \n" 2638c2ecf20Sopenharmony_ci " .set pop"); 2648c2ecf20Sopenharmony_ci} 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci/* enable multi-threaded execution if previous suggested it should be. 2678c2ecf20Sopenharmony_ci EMT_ENABLE to force */ 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci#define EMT_ENABLE VPECONTROL_TE 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_cistatic inline void emt(int previous) 2728c2ecf20Sopenharmony_ci{ 2738c2ecf20Sopenharmony_ci if ((previous & EMT_ENABLE)) 2748c2ecf20Sopenharmony_ci __raw_emt(); 2758c2ecf20Sopenharmony_ci} 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_cistatic inline void ehb(void) 2788c2ecf20Sopenharmony_ci{ 2798c2ecf20Sopenharmony_ci __asm__ __volatile__( 2808c2ecf20Sopenharmony_ci " .set push \n" 2818c2ecf20Sopenharmony_ci " .set mips32r2 \n" 2828c2ecf20Sopenharmony_ci " ehb \n" 2838c2ecf20Sopenharmony_ci " .set pop \n"); 2848c2ecf20Sopenharmony_ci} 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci#define mftc0(rt,sel) \ 2878c2ecf20Sopenharmony_ci({ \ 2888c2ecf20Sopenharmony_ci unsigned long __res; \ 2898c2ecf20Sopenharmony_ci \ 2908c2ecf20Sopenharmony_ci __asm__ __volatile__( \ 2918c2ecf20Sopenharmony_ci " .set push \n" \ 2928c2ecf20Sopenharmony_ci " .set mips32r2 \n" \ 2938c2ecf20Sopenharmony_ci " .set noat \n" \ 2948c2ecf20Sopenharmony_ci " # mftc0 $1, $" #rt ", " #sel " \n" \ 2958c2ecf20Sopenharmony_ci " .word 0x41000800 | (" #rt " << 16) | " #sel " \n" \ 2968c2ecf20Sopenharmony_ci " move %0, $1 \n" \ 2978c2ecf20Sopenharmony_ci " .set pop \n" \ 2988c2ecf20Sopenharmony_ci : "=r" (__res)); \ 2998c2ecf20Sopenharmony_ci \ 3008c2ecf20Sopenharmony_ci __res; \ 3018c2ecf20Sopenharmony_ci}) 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci#define mftgpr(rt) \ 3048c2ecf20Sopenharmony_ci({ \ 3058c2ecf20Sopenharmony_ci unsigned long __res; \ 3068c2ecf20Sopenharmony_ci \ 3078c2ecf20Sopenharmony_ci __asm__ __volatile__( \ 3088c2ecf20Sopenharmony_ci " .set push \n" \ 3098c2ecf20Sopenharmony_ci " .set noat \n" \ 3108c2ecf20Sopenharmony_ci " .set mips32r2 \n" \ 3118c2ecf20Sopenharmony_ci " # mftgpr $1," #rt " \n" \ 3128c2ecf20Sopenharmony_ci " .word 0x41000820 | (" #rt " << 16) \n" \ 3138c2ecf20Sopenharmony_ci " move %0, $1 \n" \ 3148c2ecf20Sopenharmony_ci " .set pop \n" \ 3158c2ecf20Sopenharmony_ci : "=r" (__res)); \ 3168c2ecf20Sopenharmony_ci \ 3178c2ecf20Sopenharmony_ci __res; \ 3188c2ecf20Sopenharmony_ci}) 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci#define mftr(rt, u, sel) \ 3218c2ecf20Sopenharmony_ci({ \ 3228c2ecf20Sopenharmony_ci unsigned long __res; \ 3238c2ecf20Sopenharmony_ci \ 3248c2ecf20Sopenharmony_ci __asm__ __volatile__( \ 3258c2ecf20Sopenharmony_ci " mftr %0, " #rt ", " #u ", " #sel " \n" \ 3268c2ecf20Sopenharmony_ci : "=r" (__res)); \ 3278c2ecf20Sopenharmony_ci \ 3288c2ecf20Sopenharmony_ci __res; \ 3298c2ecf20Sopenharmony_ci}) 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci#define mttgpr(rd,v) \ 3328c2ecf20Sopenharmony_cido { \ 3338c2ecf20Sopenharmony_ci __asm__ __volatile__( \ 3348c2ecf20Sopenharmony_ci " .set push \n" \ 3358c2ecf20Sopenharmony_ci " .set mips32r2 \n" \ 3368c2ecf20Sopenharmony_ci " .set noat \n" \ 3378c2ecf20Sopenharmony_ci " move $1, %0 \n" \ 3388c2ecf20Sopenharmony_ci " # mttgpr $1, " #rd " \n" \ 3398c2ecf20Sopenharmony_ci " .word 0x41810020 | (" #rd " << 11) \n" \ 3408c2ecf20Sopenharmony_ci " .set pop \n" \ 3418c2ecf20Sopenharmony_ci : : "r" (v)); \ 3428c2ecf20Sopenharmony_ci} while (0) 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci#define mttc0(rd, sel, v) \ 3458c2ecf20Sopenharmony_ci({ \ 3468c2ecf20Sopenharmony_ci __asm__ __volatile__( \ 3478c2ecf20Sopenharmony_ci " .set push \n" \ 3488c2ecf20Sopenharmony_ci " .set mips32r2 \n" \ 3498c2ecf20Sopenharmony_ci " .set noat \n" \ 3508c2ecf20Sopenharmony_ci " move $1, %0 \n" \ 3518c2ecf20Sopenharmony_ci " # mttc0 %0," #rd ", " #sel " \n" \ 3528c2ecf20Sopenharmony_ci " .word 0x41810000 | (" #rd " << 11) | " #sel " \n" \ 3538c2ecf20Sopenharmony_ci " .set pop \n" \ 3548c2ecf20Sopenharmony_ci : \ 3558c2ecf20Sopenharmony_ci : "r" (v)); \ 3568c2ecf20Sopenharmony_ci}) 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci#define mttr(rd, u, sel, v) \ 3608c2ecf20Sopenharmony_ci({ \ 3618c2ecf20Sopenharmony_ci __asm__ __volatile__( \ 3628c2ecf20Sopenharmony_ci "mttr %0," #rd ", " #u ", " #sel \ 3638c2ecf20Sopenharmony_ci : : "r" (v)); \ 3648c2ecf20Sopenharmony_ci}) 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci#define settc(tc) \ 3688c2ecf20Sopenharmony_cido { \ 3698c2ecf20Sopenharmony_ci write_c0_vpecontrol((read_c0_vpecontrol()&~VPECONTROL_TARGTC) | (tc)); \ 3708c2ecf20Sopenharmony_ci ehb(); \ 3718c2ecf20Sopenharmony_ci} while (0) 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci/* you *must* set the target tc (settc) before trying to use these */ 3758c2ecf20Sopenharmony_ci#define read_vpe_c0_vpecontrol() mftc0(1, 1) 3768c2ecf20Sopenharmony_ci#define write_vpe_c0_vpecontrol(val) mttc0(1, 1, val) 3778c2ecf20Sopenharmony_ci#define read_vpe_c0_vpeconf0() mftc0(1, 2) 3788c2ecf20Sopenharmony_ci#define write_vpe_c0_vpeconf0(val) mttc0(1, 2, val) 3798c2ecf20Sopenharmony_ci#define read_vpe_c0_vpeconf1() mftc0(1, 3) 3808c2ecf20Sopenharmony_ci#define write_vpe_c0_vpeconf1(val) mttc0(1, 3, val) 3818c2ecf20Sopenharmony_ci#define read_vpe_c0_count() mftc0(9, 0) 3828c2ecf20Sopenharmony_ci#define write_vpe_c0_count(val) mttc0(9, 0, val) 3838c2ecf20Sopenharmony_ci#define read_vpe_c0_status() mftc0(12, 0) 3848c2ecf20Sopenharmony_ci#define write_vpe_c0_status(val) mttc0(12, 0, val) 3858c2ecf20Sopenharmony_ci#define read_vpe_c0_cause() mftc0(13, 0) 3868c2ecf20Sopenharmony_ci#define write_vpe_c0_cause(val) mttc0(13, 0, val) 3878c2ecf20Sopenharmony_ci#define read_vpe_c0_config() mftc0(16, 0) 3888c2ecf20Sopenharmony_ci#define write_vpe_c0_config(val) mttc0(16, 0, val) 3898c2ecf20Sopenharmony_ci#define read_vpe_c0_config1() mftc0(16, 1) 3908c2ecf20Sopenharmony_ci#define write_vpe_c0_config1(val) mttc0(16, 1, val) 3918c2ecf20Sopenharmony_ci#define read_vpe_c0_config7() mftc0(16, 7) 3928c2ecf20Sopenharmony_ci#define write_vpe_c0_config7(val) mttc0(16, 7, val) 3938c2ecf20Sopenharmony_ci#define read_vpe_c0_ebase() mftc0(15, 1) 3948c2ecf20Sopenharmony_ci#define write_vpe_c0_ebase(val) mttc0(15, 1, val) 3958c2ecf20Sopenharmony_ci#define write_vpe_c0_compare(val) mttc0(11, 0, val) 3968c2ecf20Sopenharmony_ci#define read_vpe_c0_badvaddr() mftc0(8, 0) 3978c2ecf20Sopenharmony_ci#define read_vpe_c0_epc() mftc0(14, 0) 3988c2ecf20Sopenharmony_ci#define write_vpe_c0_epc(val) mttc0(14, 0, val) 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci/* TC */ 4028c2ecf20Sopenharmony_ci#define read_tc_c0_tcstatus() mftc0(2, 1) 4038c2ecf20Sopenharmony_ci#define write_tc_c0_tcstatus(val) mttc0(2, 1, val) 4048c2ecf20Sopenharmony_ci#define read_tc_c0_tcbind() mftc0(2, 2) 4058c2ecf20Sopenharmony_ci#define write_tc_c0_tcbind(val) mttc0(2, 2, val) 4068c2ecf20Sopenharmony_ci#define read_tc_c0_tcrestart() mftc0(2, 3) 4078c2ecf20Sopenharmony_ci#define write_tc_c0_tcrestart(val) mttc0(2, 3, val) 4088c2ecf20Sopenharmony_ci#define read_tc_c0_tchalt() mftc0(2, 4) 4098c2ecf20Sopenharmony_ci#define write_tc_c0_tchalt(val) mttc0(2, 4, val) 4108c2ecf20Sopenharmony_ci#define read_tc_c0_tccontext() mftc0(2, 5) 4118c2ecf20Sopenharmony_ci#define write_tc_c0_tccontext(val) mttc0(2, 5, val) 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ci/* GPR */ 4148c2ecf20Sopenharmony_ci#define read_tc_gpr_sp() mftgpr(29) 4158c2ecf20Sopenharmony_ci#define write_tc_gpr_sp(val) mttgpr(29, val) 4168c2ecf20Sopenharmony_ci#define read_tc_gpr_gp() mftgpr(28) 4178c2ecf20Sopenharmony_ci#define write_tc_gpr_gp(val) mttgpr(28, val) 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci__BUILD_SET_C0(mvpcontrol) 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci#endif /* Not __ASSEMBLY__ */ 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci#endif 424