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 /***************************************************************************
91 * Macros for storing registers into and loading registers from
94 #define SAVE_GPR(n, base) stw n,GPR0+4*(n)(base)
95 #define SAVE_2GPRS(n, base) SAVE_GPR(n, base); SAVE_GPR(n+1, base)
96 #define SAVE_4GPRS(n, base) SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base)
97 #define SAVE_8GPRS(n, base) SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base)
98 #define SAVE_10GPRS(n, base) SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base)
99 #define REST_GPR(n, base) lwz n,GPR0+4*(n)(base)
100 #define REST_2GPRS(n, base) REST_GPR(n, base); REST_GPR(n+1, base)
101 #define REST_4GPRS(n, base) REST_2GPRS(n, base); REST_2GPRS(n+2, base)
102 #define REST_8GPRS(n, base) REST_4GPRS(n, base); REST_4GPRS(n+4, base)
103 #define REST_10GPRS(n, base) REST_8GPRS(n, base); REST_2GPRS(n+8, base)
106 * GCC sometimes accesses words at negative offsets from the stack
107 * pointer, although the SysV ABI says it shouldn't. To cope with
108 * this, we leave this much untouched space on the stack on exception
111 #define STACK_UNDERHEAD 64
114 * Exception entry code. This code runs with address translation
115 * turned off, i.e. using physical addresses.
116 * We assume sprg3 has the physical address of the current
117 * task's thread_struct.
119 #define EXCEPTION_PROLOG(reg1, reg2) \
123 subi r21,r1,INT_FRAME_SIZE+STACK_UNDERHEAD; /* alloc exc. frame */\
124 stw r20,_CCR(r21); /* save registers */ \
125 stw r22,GPR22(r21); \
126 stw r23,GPR23(r21); \
128 stw r20,GPR20(r21); \
130 stw r22,GPR21(r21); \
132 stw r20,_LINK(r21); \
137 mfspr r20, DAR_DEAR; \
145 mr r1,r21; /* set new kernel sp */ \
148 * Note: code which follows this uses cr0.eq (set if from kernel),
149 * r21, r22 (SRR0), and r23 (SRR1).
155 * The data words for `hdlr' and `int_return' are initialized with
156 * OFFSET values only; they must be relocated first before they can
159 #define COPY_EE(d, s) rlwimi d,s,0,16,16
163 #define EXC_XFER_TEMPLATE(n, label, hdlr, msr, copyee) \
170 rlwimi r20,r23,0,25,25; \
174 addis r23,r23,(hdlr - 1b)@ha; \
175 addi r23,r23,(hdlr - 1b)@l; \
176 b transfer_to_handler
178 #define STD_EXCEPTION(n, label, hdlr) \
181 EXCEPTION_PROLOG(SRR0, SRR1); \
182 addi r3,r1,STACK_FRAME_OVERHEAD; \
183 EXC_XFER_TEMPLATE(n, label, hdlr, MSR_KERNEL, NOCOPY) \
185 #define CRIT_EXCEPTION(n, label, hdlr) \
188 EXCEPTION_PROLOG(CSRR0, CSRR1); \
189 addi r3,r1,STACK_FRAME_OVERHEAD; \
190 EXC_XFER_TEMPLATE(n, label, hdlr, \
191 MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE), NOCOPY) \
193 #define MCK_EXCEPTION(n, label, hdlr) \
196 EXCEPTION_PROLOG(MCSRR0, MCSRR1); \
197 addi r3,r1,STACK_FRAME_OVERHEAD; \
198 EXC_XFER_TEMPLATE(n, label, hdlr, \
199 MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE), NOCOPY) \
203 #define EXC_XFER_TEMPLATE(label, hdlr, msr, copyee) \
206 lwz r20,(.L_ ## label)-1b+8(r20); \
210 rlwimi r20,r23,0,25,25; \
213 .long hdlr - _start + _START_OFFSET; \
214 .long int_return - _start + _START_OFFSET; \
215 .long transfer_to_handler - _start + _START_OFFSET
217 #define STD_EXCEPTION(n, label, hdlr) \
220 EXCEPTION_PROLOG(SRR0, SRR1); \
221 addi r3,r1,STACK_FRAME_OVERHEAD; \
222 EXC_XFER_TEMPLATE(label, hdlr, MSR_KERNEL, NOCOPY) \
224 #define CRIT_EXCEPTION(n, label, hdlr) \
227 EXCEPTION_PROLOG(CSRR0, CSRR1); \
228 addi r3,r1,STACK_FRAME_OVERHEAD; \
229 EXC_XFER_TEMPLATE(label, hdlr, \
230 MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE), NOCOPY) \
232 #define MCK_EXCEPTION(n, label, hdlr) \
235 EXCEPTION_PROLOG(MCSRR0, MCSRR1); \
236 addi r3,r1,STACK_FRAME_OVERHEAD; \
237 EXC_XFER_TEMPLATE(label, hdlr, \
238 MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE), NOCOPY) \
241 #endif /* __PPC_ASM_TMPL__ */