2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
9 * This file contains all the macros and symbols which define
10 * a PowerPC assembly language environment.
12 #ifndef __PPC_ASM_TMPL__
13 #define __PPC_ASM_TMPL__
17 /***************************************************************************
19 * These definitions simplify the ugly declarations necessary for GOT
22 * Stolen from prepboot/bootldr.h, (C) 1998 Gabriel Paubert, paubert@iram.es
24 * Uses r12 to access the GOT
28 .section ".got2","aw"; \
37 0: .long .LCTOC1-1f ; \
43 #define GOT_ENTRY(NAME) .L_ ## NAME = . - .LCTOC1 ; .long NAME
45 #define GOT(NAME) .L_ ## NAME (r12)
48 /***************************************************************************
84 #if defined(CONFIG_MPC5xxx)
86 #define HID0_ICE_BITPOS 16
87 #define HID0_DCE_BITPOS 17
98 * Macros for storing registers into and loading registers from
101 #define SAVE_GPR(n, base) stw n,GPR0+4*(n)(base)
102 #define SAVE_2GPRS(n, base) SAVE_GPR(n, base); SAVE_GPR(n+1, base)
103 #define SAVE_4GPRS(n, base) SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base)
104 #define SAVE_8GPRS(n, base) SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base)
105 #define SAVE_10GPRS(n, base) SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base)
106 #define REST_GPR(n, base) lwz n,GPR0+4*(n)(base)
107 #define REST_2GPRS(n, base) REST_GPR(n, base); REST_GPR(n+1, base)
108 #define REST_4GPRS(n, base) REST_2GPRS(n, base); REST_2GPRS(n+2, base)
109 #define REST_8GPRS(n, base) REST_4GPRS(n, base); REST_4GPRS(n+4, base)
110 #define REST_10GPRS(n, base) REST_8GPRS(n, base); REST_2GPRS(n+8, base)
113 * GCC sometimes accesses words at negative offsets from the stack
114 * pointer, although the SysV ABI says it shouldn't. To cope with
115 * this, we leave this much untouched space on the stack on exception
118 #define STACK_UNDERHEAD 64
121 * Exception entry code. This code runs with address translation
122 * turned off, i.e. using physical addresses.
123 * We assume sprg3 has the physical address of the current
124 * task's thread_struct.
126 #define EXCEPTION_PROLOG(reg1, reg2) \
130 subi r21,r1,INT_FRAME_SIZE+STACK_UNDERHEAD; /* alloc exc. frame */\
131 stw r20,_CCR(r21); /* save registers */ \
132 stw r22,GPR22(r21); \
133 stw r23,GPR23(r21); \
135 stw r20,GPR20(r21); \
137 stw r22,GPR21(r21); \
139 stw r20,_LINK(r21); \
144 mfspr r20, DAR_DEAR; \
152 mr r1,r21; /* set new kernel sp */ \
155 * Note: code which follows this uses cr0.eq (set if from kernel),
156 * r21, r22 (SRR0), and r23 (SRR1).
162 * The data words for `hdlr' and `int_return' are initialized with
163 * OFFSET values only; they must be relocated first before they can
166 #define COPY_EE(d, s) rlwimi d,s,0,16,16
170 #define EXC_XFER_TEMPLATE(n, label, hdlr, msr, copyee) \
177 rlwimi r20,r23,0,25,25; \
181 addis r23,r23,(hdlr - 1b)@ha; \
182 addi r23,r23,(hdlr - 1b)@l; \
183 b transfer_to_handler
185 #define STD_EXCEPTION(n, label, hdlr) \
188 EXCEPTION_PROLOG(SRR0, SRR1); \
189 addi r3,r1,STACK_FRAME_OVERHEAD; \
190 EXC_XFER_TEMPLATE(n, label, hdlr, MSR_KERNEL, NOCOPY) \
192 #define CRIT_EXCEPTION(n, label, hdlr) \
195 EXCEPTION_PROLOG(CSRR0, CSRR1); \
196 addi r3,r1,STACK_FRAME_OVERHEAD; \
197 EXC_XFER_TEMPLATE(n, label, hdlr, \
198 MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE), NOCOPY) \
200 #define MCK_EXCEPTION(n, label, hdlr) \
203 EXCEPTION_PROLOG(MCSRR0, MCSRR1); \
204 addi r3,r1,STACK_FRAME_OVERHEAD; \
205 EXC_XFER_TEMPLATE(n, label, hdlr, \
206 MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE), NOCOPY) \
210 #define EXC_XFER_TEMPLATE(label, hdlr, msr, copyee) \
213 lwz r20,(.L_ ## label)-1b+8(r20); \
217 rlwimi r20,r23,0,25,25; \
220 .long hdlr - _start + _START_OFFSET; \
221 .long int_return - _start + _START_OFFSET; \
222 .long transfer_to_handler - _start + _START_OFFSET
224 #define STD_EXCEPTION(n, label, hdlr) \
227 EXCEPTION_PROLOG(SRR0, SRR1); \
228 addi r3,r1,STACK_FRAME_OVERHEAD; \
229 EXC_XFER_TEMPLATE(label, hdlr, MSR_KERNEL, NOCOPY) \
231 #define CRIT_EXCEPTION(n, label, hdlr) \
234 EXCEPTION_PROLOG(CSRR0, CSRR1); \
235 addi r3,r1,STACK_FRAME_OVERHEAD; \
236 EXC_XFER_TEMPLATE(label, hdlr, \
237 MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE), NOCOPY) \
239 #define MCK_EXCEPTION(n, label, hdlr) \
242 EXCEPTION_PROLOG(MCSRR0, MCSRR1); \
243 addi r3,r1,STACK_FRAME_OVERHEAD; \
244 EXC_XFER_TEMPLATE(label, hdlr, \
245 MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE), NOCOPY) \
248 #endif /* __PPC_ASM_TMPL__ */