18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd. 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#ifndef __ASM_CSKY_ENTRY_H 58c2ecf20Sopenharmony_ci#define __ASM_CSKY_ENTRY_H 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include <asm/setup.h> 88c2ecf20Sopenharmony_ci#include <abi/regdef.h> 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#define LSAVE_PC 8 118c2ecf20Sopenharmony_ci#define LSAVE_PSR 12 128c2ecf20Sopenharmony_ci#define LSAVE_A0 24 138c2ecf20Sopenharmony_ci#define LSAVE_A1 28 148c2ecf20Sopenharmony_ci#define LSAVE_A2 32 158c2ecf20Sopenharmony_ci#define LSAVE_A3 36 168c2ecf20Sopenharmony_ci#define LSAVE_A4 40 178c2ecf20Sopenharmony_ci#define LSAVE_A5 44 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define usp ss1 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci.macro USPTOKSP 228c2ecf20Sopenharmony_ci mtcr sp, usp 238c2ecf20Sopenharmony_ci mfcr sp, ss0 248c2ecf20Sopenharmony_ci.endm 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci.macro KSPTOUSP 278c2ecf20Sopenharmony_ci mtcr sp, ss0 288c2ecf20Sopenharmony_ci mfcr sp, usp 298c2ecf20Sopenharmony_ci.endm 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci.macro SAVE_ALL epc_inc 328c2ecf20Sopenharmony_ci mtcr r13, ss2 338c2ecf20Sopenharmony_ci mfcr r13, epsr 348c2ecf20Sopenharmony_ci btsti r13, 31 358c2ecf20Sopenharmony_ci bt 1f 368c2ecf20Sopenharmony_ci USPTOKSP 378c2ecf20Sopenharmony_ci1: 388c2ecf20Sopenharmony_ci subi sp, 32 398c2ecf20Sopenharmony_ci subi sp, 32 408c2ecf20Sopenharmony_ci subi sp, 16 418c2ecf20Sopenharmony_ci stw r13, (sp, 12) 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci stw lr, (sp, 4) 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci mfcr lr, epc 468c2ecf20Sopenharmony_ci movi r13, \epc_inc 478c2ecf20Sopenharmony_ci add lr, r13 488c2ecf20Sopenharmony_ci stw lr, (sp, 8) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci mov lr, sp 518c2ecf20Sopenharmony_ci addi lr, 32 528c2ecf20Sopenharmony_ci addi lr, 32 538c2ecf20Sopenharmony_ci addi lr, 16 548c2ecf20Sopenharmony_ci bt 2f 558c2ecf20Sopenharmony_ci mfcr lr, ss1 568c2ecf20Sopenharmony_ci2: 578c2ecf20Sopenharmony_ci stw lr, (sp, 16) 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci stw a0, (sp, 20) 608c2ecf20Sopenharmony_ci stw a0, (sp, 24) 618c2ecf20Sopenharmony_ci stw a1, (sp, 28) 628c2ecf20Sopenharmony_ci stw a2, (sp, 32) 638c2ecf20Sopenharmony_ci stw a3, (sp, 36) 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci addi sp, 32 668c2ecf20Sopenharmony_ci addi sp, 8 678c2ecf20Sopenharmony_ci mfcr r13, ss2 688c2ecf20Sopenharmony_ci stw r6, (sp) 698c2ecf20Sopenharmony_ci stw r7, (sp, 4) 708c2ecf20Sopenharmony_ci stw r8, (sp, 8) 718c2ecf20Sopenharmony_ci stw r9, (sp, 12) 728c2ecf20Sopenharmony_ci stw r10, (sp, 16) 738c2ecf20Sopenharmony_ci stw r11, (sp, 20) 748c2ecf20Sopenharmony_ci stw r12, (sp, 24) 758c2ecf20Sopenharmony_ci stw r13, (sp, 28) 768c2ecf20Sopenharmony_ci stw r14, (sp, 32) 778c2ecf20Sopenharmony_ci stw r1, (sp, 36) 788c2ecf20Sopenharmony_ci subi sp, 32 798c2ecf20Sopenharmony_ci subi sp, 8 808c2ecf20Sopenharmony_ci.endm 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci.macro RESTORE_ALL 838c2ecf20Sopenharmony_ci ldw lr, (sp, 4) 848c2ecf20Sopenharmony_ci ldw a0, (sp, 8) 858c2ecf20Sopenharmony_ci mtcr a0, epc 868c2ecf20Sopenharmony_ci ldw a0, (sp, 12) 878c2ecf20Sopenharmony_ci mtcr a0, epsr 888c2ecf20Sopenharmony_ci btsti a0, 31 898c2ecf20Sopenharmony_ci bt 1f 908c2ecf20Sopenharmony_ci ldw a0, (sp, 16) 918c2ecf20Sopenharmony_ci mtcr a0, ss1 928c2ecf20Sopenharmony_ci1: 938c2ecf20Sopenharmony_ci ldw a0, (sp, 24) 948c2ecf20Sopenharmony_ci ldw a1, (sp, 28) 958c2ecf20Sopenharmony_ci ldw a2, (sp, 32) 968c2ecf20Sopenharmony_ci ldw a3, (sp, 36) 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci addi sp, 32 998c2ecf20Sopenharmony_ci addi sp, 8 1008c2ecf20Sopenharmony_ci ldw r6, (sp) 1018c2ecf20Sopenharmony_ci ldw r7, (sp, 4) 1028c2ecf20Sopenharmony_ci ldw r8, (sp, 8) 1038c2ecf20Sopenharmony_ci ldw r9, (sp, 12) 1048c2ecf20Sopenharmony_ci ldw r10, (sp, 16) 1058c2ecf20Sopenharmony_ci ldw r11, (sp, 20) 1068c2ecf20Sopenharmony_ci ldw r12, (sp, 24) 1078c2ecf20Sopenharmony_ci ldw r13, (sp, 28) 1088c2ecf20Sopenharmony_ci ldw r14, (sp, 32) 1098c2ecf20Sopenharmony_ci ldw r1, (sp, 36) 1108c2ecf20Sopenharmony_ci addi sp, 32 1118c2ecf20Sopenharmony_ci addi sp, 8 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci bt 2f 1148c2ecf20Sopenharmony_ci KSPTOUSP 1158c2ecf20Sopenharmony_ci2: 1168c2ecf20Sopenharmony_ci rte 1178c2ecf20Sopenharmony_ci.endm 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci.macro SAVE_SWITCH_STACK 1208c2ecf20Sopenharmony_ci subi sp, 32 1218c2ecf20Sopenharmony_ci stm r8-r15, (sp) 1228c2ecf20Sopenharmony_ci.endm 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci.macro RESTORE_SWITCH_STACK 1258c2ecf20Sopenharmony_ci ldm r8-r15, (sp) 1268c2ecf20Sopenharmony_ci addi sp, 32 1278c2ecf20Sopenharmony_ci.endm 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci/* MMU registers operators. */ 1308c2ecf20Sopenharmony_ci.macro RD_MIR rx 1318c2ecf20Sopenharmony_ci cprcr \rx, cpcr0 1328c2ecf20Sopenharmony_ci.endm 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci.macro RD_MEH rx 1358c2ecf20Sopenharmony_ci cprcr \rx, cpcr4 1368c2ecf20Sopenharmony_ci.endm 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci.macro RD_MCIR rx 1398c2ecf20Sopenharmony_ci cprcr \rx, cpcr8 1408c2ecf20Sopenharmony_ci.endm 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci.macro RD_PGDR rx 1438c2ecf20Sopenharmony_ci cprcr \rx, cpcr29 1448c2ecf20Sopenharmony_ci.endm 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci.macro WR_MEH rx 1478c2ecf20Sopenharmony_ci cpwcr \rx, cpcr4 1488c2ecf20Sopenharmony_ci.endm 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci.macro WR_MCIR rx 1518c2ecf20Sopenharmony_ci cpwcr \rx, cpcr8 1528c2ecf20Sopenharmony_ci.endm 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci.macro SETUP_MMU 1558c2ecf20Sopenharmony_ci /* Init psr and enable ee */ 1568c2ecf20Sopenharmony_ci lrw r6, DEFAULT_PSR_VALUE 1578c2ecf20Sopenharmony_ci mtcr r6, psr 1588c2ecf20Sopenharmony_ci psrset ee 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci /* Select MMU as co-processor */ 1618c2ecf20Sopenharmony_ci cpseti cp15 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci /* 1648c2ecf20Sopenharmony_ci * cpcr30 format: 1658c2ecf20Sopenharmony_ci * 31 - 29 | 28 - 4 | 3 | 2 | 1 | 0 1668c2ecf20Sopenharmony_ci * BA Reserved C D V 1678c2ecf20Sopenharmony_ci */ 1688c2ecf20Sopenharmony_ci cprcr r6, cpcr30 1698c2ecf20Sopenharmony_ci lsri r6, 29 1708c2ecf20Sopenharmony_ci lsli r6, 29 1718c2ecf20Sopenharmony_ci addi r6, 0xe 1728c2ecf20Sopenharmony_ci cpwcr r6, cpcr30 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci movi r6, 0 1758c2ecf20Sopenharmony_ci cpwcr r6, cpcr31 1768c2ecf20Sopenharmony_ci.endm 1778c2ecf20Sopenharmony_ci#endif /* __ASM_CSKY_ENTRY_H */ 178