• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (C) 1999 Hewlett-Packard (Frank Rowand)
4  * Copyright (C) 1999 Philipp Rumpf <prumpf@tux.org>
5  * Copyright (C) 1999 SuSE GmbH
6  */
7 
8 #ifndef _PARISC_ASSEMBLY_H
9 #define _PARISC_ASSEMBLY_H
10 
11 #define CALLEE_FLOAT_FRAME_SIZE	80
12 
13 #ifdef CONFIG_64BIT
14 #define LDREG	ldd
15 #define STREG	std
16 #define LDREGX  ldd,s
17 #define LDREGM	ldd,mb
18 #define STREGM	std,ma
19 #define SHRREG	shrd
20 #define SHLREG	shld
21 #define ANDCM   andcm,*
22 #define	COND(x)	* ## x
23 #define RP_OFFSET	16
24 #define FRAME_SIZE	128
25 #define CALLEE_REG_FRAME_SIZE	144
26 #define REG_SZ		8
27 #define ASM_ULONG_INSN	.dword
28 #else	/* CONFIG_64BIT */
29 #define LDREG	ldw
30 #define STREG	stw
31 #define LDREGX  ldwx,s
32 #define LDREGM	ldwm
33 #define STREGM	stwm
34 #define SHRREG	shr
35 #define SHLREG	shlw
36 #define ANDCM   andcm
37 #define COND(x)	x
38 #define RP_OFFSET	20
39 #define FRAME_SIZE	64
40 #define CALLEE_REG_FRAME_SIZE	128
41 #define REG_SZ		4
42 #define ASM_ULONG_INSN	.word
43 #endif
44 
45 #define CALLEE_SAVE_FRAME_SIZE (CALLEE_REG_FRAME_SIZE + CALLEE_FLOAT_FRAME_SIZE)
46 
47 #ifdef CONFIG_PA20
48 #define LDCW		ldcw,co
49 #define BL		b,l
50 # ifdef CONFIG_64BIT
51 #  define PA_ASM_LEVEL	2.0w
52 # else
53 #  define PA_ASM_LEVEL	2.0
54 # endif
55 #else
56 #define LDCW		ldcw
57 #define BL		bl
58 #define PA_ASM_LEVEL	1.1
59 #endif
60 
61 #ifdef __ASSEMBLY__
62 
63 #ifdef CONFIG_64BIT
64 /* the 64-bit pa gnu assembler unfortunately defaults to .level 1.1 or 2.0 so
65  * work around that for now... */
66 	.level 2.0w
67 #endif
68 
69 #include <asm/asm-offsets.h>
70 #include <asm/page.h>
71 #include <asm/types.h>
72 
73 #include <asm/asmregs.h>
74 
75 	/*
76 	 * We provide two versions of each macro to convert from physical
77 	 * to virtual and vice versa. The "_r1" versions take one argument
78 	 * register, but trashes r1 to do the conversion. The other
79 	 * version takes two arguments: a src and destination register.
80 	 * However, the source and destination registers can not be
81 	 * the same register.
82 	 */
83 
84 	.macro  tophys  grvirt, grphys
85 	ldil    L%(__PAGE_OFFSET), \grphys
86 	sub     \grvirt, \grphys, \grphys
87 	.endm
88 
89 	.macro  tovirt  grphys, grvirt
90 	ldil    L%(__PAGE_OFFSET), \grvirt
91 	add     \grphys, \grvirt, \grvirt
92 	.endm
93 
94 	.macro  tophys_r1  gr
95 	ldil    L%(__PAGE_OFFSET), %r1
96 	sub     \gr, %r1, \gr
97 	.endm
98 
99 	.macro  tovirt_r1  gr
100 	ldil    L%(__PAGE_OFFSET), %r1
101 	add     \gr, %r1, \gr
102 	.endm
103 
104 	.macro delay value
105 	ldil	L%\value, 1
106 	ldo	R%\value(1), 1
107 	addib,UV,n -1,1,.
108 	addib,NUV,n -1,1,.+8
109 	nop
110 	.endm
111 
112 	.macro	debug value
113 	.endm
114 
115 	.macro shlw r, sa, t
116 	zdep	\r, 31-(\sa), 32-(\sa), \t
117 	.endm
118 
119 	/* And the PA 2.0W shift left */
120 	.macro shld r, sa, t
121 	depd,z	\r, 63-(\sa), 64-(\sa), \t
122 	.endm
123 
124 	/* Shift Right - note the r and t can NOT be the same! */
125 	.macro shr r, sa, t
126 	extru \r, 31-(\sa), 32-(\sa), \t
127 	.endm
128 
129 	/* pa20w version of shift right */
130 	.macro shrd r, sa, t
131 	extrd,u \r, 63-(\sa), 64-(\sa), \t
132 	.endm
133 
134 	/* load 32-bit 'value' into 'reg' compensating for the ldil
135 	 * sign-extension when running in wide mode.
136 	 * WARNING!! neither 'value' nor 'reg' can be expressions
137 	 * containing '.'!!!! */
138 	.macro	load32 value, reg
139 	ldil	L%\value, \reg
140 	ldo	R%\value(\reg), \reg
141 	.endm
142 
143 	.macro loadgp
144 #ifdef CONFIG_64BIT
145 	ldil		L%__gp, %r27
146 	ldo		R%__gp(%r27), %r27
147 #else
148 	ldil		L%$global$, %r27
149 	ldo		R%$global$(%r27), %r27
150 #endif
151 	.endm
152 
153 #define SAVE_SP(r, where) mfsp r, %r1 ! STREG %r1, where
154 #define REST_SP(r, where) LDREG where, %r1 ! mtsp %r1, r
155 #define SAVE_CR(r, where) mfctl r, %r1 ! STREG %r1, where
156 #define REST_CR(r, where) LDREG where, %r1 ! mtctl %r1, r
157 
158 	.macro	save_general	regs
159 	STREG %r1, PT_GR1 (\regs)
160 	STREG %r2, PT_GR2 (\regs)
161 	STREG %r3, PT_GR3 (\regs)
162 	STREG %r4, PT_GR4 (\regs)
163 	STREG %r5, PT_GR5 (\regs)
164 	STREG %r6, PT_GR6 (\regs)
165 	STREG %r7, PT_GR7 (\regs)
166 	STREG %r8, PT_GR8 (\regs)
167 	STREG %r9, PT_GR9 (\regs)
168 	STREG %r10, PT_GR10(\regs)
169 	STREG %r11, PT_GR11(\regs)
170 	STREG %r12, PT_GR12(\regs)
171 	STREG %r13, PT_GR13(\regs)
172 	STREG %r14, PT_GR14(\regs)
173 	STREG %r15, PT_GR15(\regs)
174 	STREG %r16, PT_GR16(\regs)
175 	STREG %r17, PT_GR17(\regs)
176 	STREG %r18, PT_GR18(\regs)
177 	STREG %r19, PT_GR19(\regs)
178 	STREG %r20, PT_GR20(\regs)
179 	STREG %r21, PT_GR21(\regs)
180 	STREG %r22, PT_GR22(\regs)
181 	STREG %r23, PT_GR23(\regs)
182 	STREG %r24, PT_GR24(\regs)
183 	STREG %r25, PT_GR25(\regs)
184 	/* r26 is saved in get_stack and used to preserve a value across virt_map */
185 	STREG %r27, PT_GR27(\regs)
186 	STREG %r28, PT_GR28(\regs)
187 	/* r29 is saved in get_stack and used to point to saved registers */
188 	/* r30 stack pointer saved in get_stack */
189 	STREG %r31, PT_GR31(\regs)
190 	.endm
191 
192 	.macro	rest_general	regs
193 	/* r1 used as a temp in rest_stack and is restored there */
194 	LDREG PT_GR2 (\regs), %r2
195 	LDREG PT_GR3 (\regs), %r3
196 	LDREG PT_GR4 (\regs), %r4
197 	LDREG PT_GR5 (\regs), %r5
198 	LDREG PT_GR6 (\regs), %r6
199 	LDREG PT_GR7 (\regs), %r7
200 	LDREG PT_GR8 (\regs), %r8
201 	LDREG PT_GR9 (\regs), %r9
202 	LDREG PT_GR10(\regs), %r10
203 	LDREG PT_GR11(\regs), %r11
204 	LDREG PT_GR12(\regs), %r12
205 	LDREG PT_GR13(\regs), %r13
206 	LDREG PT_GR14(\regs), %r14
207 	LDREG PT_GR15(\regs), %r15
208 	LDREG PT_GR16(\regs), %r16
209 	LDREG PT_GR17(\regs), %r17
210 	LDREG PT_GR18(\regs), %r18
211 	LDREG PT_GR19(\regs), %r19
212 	LDREG PT_GR20(\regs), %r20
213 	LDREG PT_GR21(\regs), %r21
214 	LDREG PT_GR22(\regs), %r22
215 	LDREG PT_GR23(\regs), %r23
216 	LDREG PT_GR24(\regs), %r24
217 	LDREG PT_GR25(\regs), %r25
218 	LDREG PT_GR26(\regs), %r26
219 	LDREG PT_GR27(\regs), %r27
220 	LDREG PT_GR28(\regs), %r28
221 	/* r29 points to register save area, and is restored in rest_stack */
222 	/* r30 stack pointer restored in rest_stack */
223 	LDREG PT_GR31(\regs), %r31
224 	.endm
225 
226 	.macro	save_fp 	regs
227 	fstd,ma  %fr0, 8(\regs)
228 	fstd,ma	 %fr1, 8(\regs)
229 	fstd,ma	 %fr2, 8(\regs)
230 	fstd,ma	 %fr3, 8(\regs)
231 	fstd,ma	 %fr4, 8(\regs)
232 	fstd,ma	 %fr5, 8(\regs)
233 	fstd,ma	 %fr6, 8(\regs)
234 	fstd,ma	 %fr7, 8(\regs)
235 	fstd,ma	 %fr8, 8(\regs)
236 	fstd,ma	 %fr9, 8(\regs)
237 	fstd,ma	%fr10, 8(\regs)
238 	fstd,ma	%fr11, 8(\regs)
239 	fstd,ma	%fr12, 8(\regs)
240 	fstd,ma	%fr13, 8(\regs)
241 	fstd,ma	%fr14, 8(\regs)
242 	fstd,ma	%fr15, 8(\regs)
243 	fstd,ma	%fr16, 8(\regs)
244 	fstd,ma	%fr17, 8(\regs)
245 	fstd,ma	%fr18, 8(\regs)
246 	fstd,ma	%fr19, 8(\regs)
247 	fstd,ma	%fr20, 8(\regs)
248 	fstd,ma	%fr21, 8(\regs)
249 	fstd,ma	%fr22, 8(\regs)
250 	fstd,ma	%fr23, 8(\regs)
251 	fstd,ma	%fr24, 8(\regs)
252 	fstd,ma	%fr25, 8(\regs)
253 	fstd,ma	%fr26, 8(\regs)
254 	fstd,ma	%fr27, 8(\regs)
255 	fstd,ma	%fr28, 8(\regs)
256 	fstd,ma	%fr29, 8(\regs)
257 	fstd,ma	%fr30, 8(\regs)
258 	fstd	%fr31, 0(\regs)
259 	.endm
260 
261 	.macro	rest_fp 	regs
262 	fldd	0(\regs),	 %fr31
263 	fldd,mb	-8(\regs),       %fr30
264 	fldd,mb	-8(\regs),       %fr29
265 	fldd,mb	-8(\regs),       %fr28
266 	fldd,mb	-8(\regs),       %fr27
267 	fldd,mb	-8(\regs),       %fr26
268 	fldd,mb	-8(\regs),       %fr25
269 	fldd,mb	-8(\regs),       %fr24
270 	fldd,mb	-8(\regs),       %fr23
271 	fldd,mb	-8(\regs),       %fr22
272 	fldd,mb	-8(\regs),       %fr21
273 	fldd,mb	-8(\regs),       %fr20
274 	fldd,mb	-8(\regs),       %fr19
275 	fldd,mb	-8(\regs),       %fr18
276 	fldd,mb	-8(\regs),       %fr17
277 	fldd,mb	-8(\regs),       %fr16
278 	fldd,mb	-8(\regs),       %fr15
279 	fldd,mb	-8(\regs),       %fr14
280 	fldd,mb	-8(\regs),       %fr13
281 	fldd,mb	-8(\regs),       %fr12
282 	fldd,mb	-8(\regs),       %fr11
283 	fldd,mb	-8(\regs),       %fr10
284 	fldd,mb	-8(\regs),       %fr9
285 	fldd,mb	-8(\regs),       %fr8
286 	fldd,mb	-8(\regs),       %fr7
287 	fldd,mb	-8(\regs),       %fr6
288 	fldd,mb	-8(\regs),       %fr5
289 	fldd,mb	-8(\regs),       %fr4
290 	fldd,mb	-8(\regs),       %fr3
291 	fldd,mb	-8(\regs),       %fr2
292 	fldd,mb	-8(\regs),       %fr1
293 	fldd,mb	-8(\regs),       %fr0
294 	.endm
295 
296 	.macro	callee_save_float
297 	fstd,ma	 %fr12,	8(%r30)
298 	fstd,ma	 %fr13,	8(%r30)
299 	fstd,ma	 %fr14,	8(%r30)
300 	fstd,ma	 %fr15,	8(%r30)
301 	fstd,ma	 %fr16,	8(%r30)
302 	fstd,ma	 %fr17,	8(%r30)
303 	fstd,ma	 %fr18,	8(%r30)
304 	fstd,ma	 %fr19,	8(%r30)
305 	fstd,ma	 %fr20,	8(%r30)
306 	fstd,ma	 %fr21,	8(%r30)
307 	.endm
308 
309 	.macro	callee_rest_float
310 	fldd,mb	-8(%r30),   %fr21
311 	fldd,mb	-8(%r30),   %fr20
312 	fldd,mb	-8(%r30),   %fr19
313 	fldd,mb	-8(%r30),   %fr18
314 	fldd,mb	-8(%r30),   %fr17
315 	fldd,mb	-8(%r30),   %fr16
316 	fldd,mb	-8(%r30),   %fr15
317 	fldd,mb	-8(%r30),   %fr14
318 	fldd,mb	-8(%r30),   %fr13
319 	fldd,mb	-8(%r30),   %fr12
320 	.endm
321 
322 #ifdef CONFIG_64BIT
323 	.macro	callee_save
324 	std,ma	  %r3,	 CALLEE_REG_FRAME_SIZE(%r30)
325 	mfctl	  %cr27, %r3
326 	std	  %r4,	-136(%r30)
327 	std	  %r5,	-128(%r30)
328 	std	  %r6,	-120(%r30)
329 	std	  %r7,	-112(%r30)
330 	std	  %r8,	-104(%r30)
331 	std	  %r9,	 -96(%r30)
332 	std	 %r10,	 -88(%r30)
333 	std	 %r11,	 -80(%r30)
334 	std	 %r12,	 -72(%r30)
335 	std	 %r13,	 -64(%r30)
336 	std	 %r14,	 -56(%r30)
337 	std	 %r15,	 -48(%r30)
338 	std	 %r16,	 -40(%r30)
339 	std	 %r17,	 -32(%r30)
340 	std	 %r18,	 -24(%r30)
341 	std	  %r3,	 -16(%r30)
342 	.endm
343 
344 	.macro	callee_rest
345 	ldd	 -16(%r30),    %r3
346 	ldd	 -24(%r30),   %r18
347 	ldd	 -32(%r30),   %r17
348 	ldd	 -40(%r30),   %r16
349 	ldd	 -48(%r30),   %r15
350 	ldd	 -56(%r30),   %r14
351 	ldd	 -64(%r30),   %r13
352 	ldd	 -72(%r30),   %r12
353 	ldd	 -80(%r30),   %r11
354 	ldd	 -88(%r30),   %r10
355 	ldd	 -96(%r30),    %r9
356 	ldd	-104(%r30),    %r8
357 	ldd	-112(%r30),    %r7
358 	ldd	-120(%r30),    %r6
359 	ldd	-128(%r30),    %r5
360 	ldd	-136(%r30),    %r4
361 	mtctl	%r3, %cr27
362 	ldd,mb	-CALLEE_REG_FRAME_SIZE(%r30),    %r3
363 	.endm
364 
365 #else /* ! CONFIG_64BIT */
366 
367 	.macro	callee_save
368 	stw,ma	 %r3,	CALLEE_REG_FRAME_SIZE(%r30)
369 	mfctl	 %cr27, %r3
370 	stw	 %r4,	-124(%r30)
371 	stw	 %r5,	-120(%r30)
372 	stw	 %r6,	-116(%r30)
373 	stw	 %r7,	-112(%r30)
374 	stw	 %r8,	-108(%r30)
375 	stw	 %r9,	-104(%r30)
376 	stw	 %r10,	-100(%r30)
377 	stw	 %r11,	 -96(%r30)
378 	stw	 %r12,	 -92(%r30)
379 	stw	 %r13,	 -88(%r30)
380 	stw	 %r14,	 -84(%r30)
381 	stw	 %r15,	 -80(%r30)
382 	stw	 %r16,	 -76(%r30)
383 	stw	 %r17,	 -72(%r30)
384 	stw	 %r18,	 -68(%r30)
385 	stw	  %r3,	 -64(%r30)
386 	.endm
387 
388 	.macro	callee_rest
389 	ldw	 -64(%r30),    %r3
390 	ldw	 -68(%r30),   %r18
391 	ldw	 -72(%r30),   %r17
392 	ldw	 -76(%r30),   %r16
393 	ldw	 -80(%r30),   %r15
394 	ldw	 -84(%r30),   %r14
395 	ldw	 -88(%r30),   %r13
396 	ldw	 -92(%r30),   %r12
397 	ldw	 -96(%r30),   %r11
398 	ldw	-100(%r30),   %r10
399 	ldw	-104(%r30),   %r9
400 	ldw	-108(%r30),   %r8
401 	ldw	-112(%r30),   %r7
402 	ldw	-116(%r30),   %r6
403 	ldw	-120(%r30),   %r5
404 	ldw	-124(%r30),   %r4
405 	mtctl	%r3, %cr27
406 	ldw,mb	-CALLEE_REG_FRAME_SIZE(%r30),   %r3
407 	.endm
408 #endif /* ! CONFIG_64BIT */
409 
410 	.macro	save_specials	regs
411 
412 	SAVE_SP  (%sr0, PT_SR0 (\regs))
413 	SAVE_SP  (%sr1, PT_SR1 (\regs))
414 	SAVE_SP  (%sr2, PT_SR2 (\regs))
415 	SAVE_SP  (%sr3, PT_SR3 (\regs))
416 	SAVE_SP  (%sr4, PT_SR4 (\regs))
417 	SAVE_SP  (%sr5, PT_SR5 (\regs))
418 	SAVE_SP  (%sr6, PT_SR6 (\regs))
419 
420 	SAVE_CR  (%cr17, PT_IASQ0(\regs))
421 	mtctl	 %r0,	%cr17
422 	SAVE_CR  (%cr17, PT_IASQ1(\regs))
423 
424 	SAVE_CR  (%cr18, PT_IAOQ0(\regs))
425 	mtctl	 %r0,	%cr18
426 	SAVE_CR  (%cr18, PT_IAOQ1(\regs))
427 
428 #ifdef CONFIG_64BIT
429 	/* cr11 (sar) is a funny one.  5 bits on PA1.1 and 6 bit on PA2.0
430 	 * For PA2.0 mtsar or mtctl always write 6 bits, but mfctl only
431 	 * reads 5 bits.  Use mfctl,w to read all six bits.  Otherwise
432 	 * we lose the 6th bit on a save/restore over interrupt.
433 	 */
434 	mfctl,w  %cr11, %r1
435 	STREG    %r1, PT_SAR (\regs)
436 #else
437 	SAVE_CR  (%cr11, PT_SAR  (\regs))
438 #endif
439 	SAVE_CR  (%cr19, PT_IIR  (\regs))
440 
441 	/*
442 	 * Code immediately following this macro (in intr_save) relies
443 	 * on r8 containing ipsw.
444 	 */
445 	mfctl    %cr22, %r8
446 	STREG    %r8,   PT_PSW(\regs)
447 	.endm
448 
449 	.macro	rest_specials	regs
450 
451 	REST_SP  (%sr0, PT_SR0 (\regs))
452 	REST_SP  (%sr1, PT_SR1 (\regs))
453 	REST_SP  (%sr2, PT_SR2 (\regs))
454 	REST_SP  (%sr3, PT_SR3 (\regs))
455 	REST_SP  (%sr4, PT_SR4 (\regs))
456 	REST_SP  (%sr5, PT_SR5 (\regs))
457 	REST_SP  (%sr6, PT_SR6 (\regs))
458 	REST_SP  (%sr7, PT_SR7 (\regs))
459 
460 	REST_CR	(%cr17, PT_IASQ0(\regs))
461 	REST_CR	(%cr17, PT_IASQ1(\regs))
462 
463 	REST_CR	(%cr18, PT_IAOQ0(\regs))
464 	REST_CR	(%cr18, PT_IAOQ1(\regs))
465 
466 	REST_CR (%cr11, PT_SAR	(\regs))
467 
468 	REST_CR	(%cr22, PT_PSW	(\regs))
469 	.endm
470 
471 
472 	/* First step to create a "relied upon translation"
473 	 * See PA 2.0 Arch. page F-4 and F-5.
474 	 *
475 	 * The ssm was originally necessary due to a "PCxT bug".
476 	 * But someone decided it needed to be added to the architecture
477 	 * and this "feature" went into rev3 of PA-RISC 1.1 Arch Manual.
478 	 * It's been carried forward into PA 2.0 Arch as well. :^(
479 	 *
480 	 * "ssm 0,%r0" is a NOP with side effects (prefetch barrier).
481 	 * rsm/ssm prevents the ifetch unit from speculatively fetching
482 	 * instructions past this line in the code stream.
483 	 * PA 2.0 processor will single step all insn in the same QUAD (4 insn).
484 	 */
485 	.macro	pcxt_ssm_bug
486 	rsm	PSW_SM_I,%r0
487 	nop	/* 1 */
488 	nop	/* 2 */
489 	nop	/* 3 */
490 	nop	/* 4 */
491 	nop	/* 5 */
492 	nop	/* 6 */
493 	nop	/* 7 */
494 	.endm
495 
496 	/*
497 	 * ASM_EXCEPTIONTABLE_ENTRY
498 	 *
499 	 * Creates an exception table entry.
500 	 * Do not convert to a assembler macro. This won't work.
501 	 */
502 #define ASM_EXCEPTIONTABLE_ENTRY(fault_addr, except_addr)	\
503 	.section __ex_table,"aw"			!	\
504 	.word (fault_addr - .), (except_addr - .)	!	\
505 	.previous
506 
507 
508 #endif /* __ASSEMBLY__ */
509 #endif
510