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_8xx)
86 /* Some special registers */
88 #define ICR 148 /* Interrupt Cause Register (37-44) */
90 #define COUNTA 150 /* Breakpoint Counter (37-44) */
91 #define COUNTB 151 /* Breakpoint Counter (37-44) */
92 #define LCTRL1 156 /* Load/Store Support (37-40) */
93 #define LCTRL2 157 /* Load/Store Support (37-41) */
96 #endif /* CONFIG_8xx */
99 #if defined(CONFIG_8xx)
101 /* Registers in the processor's internal memory map that we use.
103 #define SYPCR 0x00000004
104 #define BR0 0x00000100
105 #define OR0 0x00000104
106 #define BR1 0x00000108
107 #define OR1 0x0000010c
108 #define BR2 0x00000110
109 #define OR2 0x00000114
110 #define BR3 0x00000118
111 #define OR3 0x0000011c
112 #define BR4 0x00000120
113 #define OR4 0x00000124
115 #define MAR 0x00000164
116 #define MCR 0x00000168
117 #define MAMR 0x00000170
118 #define MBMR 0x00000174
119 #define MSTAT 0x00000178
120 #define MPTPR 0x0000017a
121 #define MDR 0x0000017c
123 #define TBSCR 0x00000200
124 #define TBREFF0 0x00000204
126 #define PLPRCR 0x00000284
137 * Macros for storing registers into and loading registers from
140 #define SAVE_GPR(n, base) stw n,GPR0+4*(n)(base)
141 #define SAVE_2GPRS(n, base) SAVE_GPR(n, base); SAVE_GPR(n+1, base)
142 #define SAVE_4GPRS(n, base) SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base)
143 #define SAVE_8GPRS(n, base) SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base)
144 #define SAVE_10GPRS(n, base) SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base)
145 #define REST_GPR(n, base) lwz n,GPR0+4*(n)(base)
146 #define REST_2GPRS(n, base) REST_GPR(n, base); REST_GPR(n+1, base)
147 #define REST_4GPRS(n, base) REST_2GPRS(n, base); REST_2GPRS(n+2, base)
148 #define REST_8GPRS(n, base) REST_4GPRS(n, base); REST_4GPRS(n+4, base)
149 #define REST_10GPRS(n, base) REST_8GPRS(n, base); REST_2GPRS(n+8, base)
152 * GCC sometimes accesses words at negative offsets from the stack
153 * pointer, although the SysV ABI says it shouldn't. To cope with
154 * this, we leave this much untouched space on the stack on exception
157 #define STACK_UNDERHEAD 64
160 * Exception entry code. This code runs with address translation
161 * turned off, i.e. using physical addresses.
162 * We assume sprg3 has the physical address of the current
163 * task's thread_struct.
165 #define EXCEPTION_PROLOG(reg1, reg2) \
169 subi r21,r1,INT_FRAME_SIZE+STACK_UNDERHEAD; /* alloc exc. frame */\
170 stw r20,_CCR(r21); /* save registers */ \
171 stw r22,GPR22(r21); \
172 stw r23,GPR23(r21); \
174 stw r20,GPR20(r21); \
176 stw r22,GPR21(r21); \
178 stw r20,_LINK(r21); \
183 mfspr r20, DAR_DEAR; \
191 mr r1,r21; /* set new kernel sp */ \
194 * Note: code which follows this uses cr0.eq (set if from kernel),
195 * r21, r22 (SRR0), and r23 (SRR1).
201 * The data words for `hdlr' and `int_return' are initialized with
202 * OFFSET values only; they must be relocated first before they can
205 #define COPY_EE(d, s) rlwimi d,s,0,16,16
209 #define EXC_XFER_TEMPLATE(n, label, hdlr, msr, copyee) \
216 rlwimi r20,r23,0,25,25; \
220 addis r23,r23,(hdlr - 1b)@ha; \
221 addi r23,r23,(hdlr - 1b)@l; \
222 b transfer_to_handler
224 #define STD_EXCEPTION(n, label, hdlr) \
227 EXCEPTION_PROLOG(SRR0, SRR1); \
228 addi r3,r1,STACK_FRAME_OVERHEAD; \
229 EXC_XFER_TEMPLATE(n, 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(n, 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(n, label, hdlr, \
245 MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE), NOCOPY) \
249 #define EXC_XFER_TEMPLATE(label, hdlr, msr, copyee) \
252 lwz r20,(.L_ ## label)-1b+8(r20); \
256 rlwimi r20,r23,0,25,25; \
259 .long hdlr - _start + _START_OFFSET; \
260 .long int_return - _start + _START_OFFSET; \
261 .long transfer_to_handler - _start + _START_OFFSET
263 #define STD_EXCEPTION(n, label, hdlr) \
266 EXCEPTION_PROLOG(SRR0, SRR1); \
267 addi r3,r1,STACK_FRAME_OVERHEAD; \
268 EXC_XFER_TEMPLATE(label, hdlr, MSR_KERNEL, NOCOPY) \
270 #define CRIT_EXCEPTION(n, label, hdlr) \
273 EXCEPTION_PROLOG(CSRR0, CSRR1); \
274 addi r3,r1,STACK_FRAME_OVERHEAD; \
275 EXC_XFER_TEMPLATE(label, hdlr, \
276 MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE), NOCOPY) \
278 #define MCK_EXCEPTION(n, label, hdlr) \
281 EXCEPTION_PROLOG(MCSRR0, MCSRR1); \
282 addi r3,r1,STACK_FRAME_OVERHEAD; \
283 EXC_XFER_TEMPLATE(label, hdlr, \
284 MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE), NOCOPY) \
287 #endif /* __PPC_ASM_TMPL__ */