blob: 0dc798d46ea462bc33759f1637f708928c61bbc7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Copyright (C) 1995-1999 Gary Thomas, Paul Mackerras, Cort Dougan.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 */
Kumar Gala5f7c6902005-09-09 15:02:25 -05004#ifndef _ASM_POWERPC_PPC_ASM_H
5#define _ASM_POWERPC_PPC_ASM_H
6
Paul Mackerras40ef8cb2005-10-10 22:50:37 +10007#include <linux/stringify.h>
8#include <linux/config.h>
David Gibson3ddfbcf2005-11-10 12:56:55 +11009#include <asm/asm-compat.h>
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100010
David Gibson3ddfbcf2005-11-10 12:56:55 +110011#ifndef __ASSEMBLY__
12#error __FILE__ should only be used in assembler files
13#else
14
15#define SZL (BITS_PER_LONG/8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17/*
18 * Macros for storing registers into and loading registers from
19 * exception frames.
20 */
Kumar Gala5f7c6902005-09-09 15:02:25 -050021#ifdef __powerpc64__
22#define SAVE_GPR(n, base) std n,GPR0+8*(n)(base)
23#define REST_GPR(n, base) ld n,GPR0+8*(n)(base)
24#define SAVE_NVGPRS(base) SAVE_8GPRS(14, base); SAVE_10GPRS(22, base)
25#define REST_NVGPRS(base) REST_8GPRS(14, base); REST_10GPRS(22, base)
26#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#define SAVE_GPR(n, base) stw n,GPR0+4*(n)(base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#define REST_GPR(n, base) lwz n,GPR0+4*(n)(base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#define SAVE_NVGPRS(base) SAVE_GPR(13, base); SAVE_8GPRS(14, base); \
30 SAVE_10GPRS(22, base)
31#define REST_NVGPRS(base) REST_GPR(13, base); REST_8GPRS(14, base); \
32 REST_10GPRS(22, base)
Kumar Gala5f7c6902005-09-09 15:02:25 -050033#endif
34
35
36#define SAVE_2GPRS(n, base) SAVE_GPR(n, base); SAVE_GPR(n+1, base)
37#define SAVE_4GPRS(n, base) SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base)
38#define SAVE_8GPRS(n, base) SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base)
39#define SAVE_10GPRS(n, base) SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base)
40#define REST_2GPRS(n, base) REST_GPR(n, base); REST_GPR(n+1, base)
41#define REST_4GPRS(n, base) REST_2GPRS(n, base); REST_2GPRS(n+2, base)
42#define REST_8GPRS(n, base) REST_4GPRS(n, base); REST_4GPRS(n+4, base)
43#define REST_10GPRS(n, base) REST_8GPRS(n, base); REST_2GPRS(n+8, base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45#define SAVE_FPR(n, base) stfd n,THREAD_FPR0+8*(n)(base)
46#define SAVE_2FPRS(n, base) SAVE_FPR(n, base); SAVE_FPR(n+1, base)
47#define SAVE_4FPRS(n, base) SAVE_2FPRS(n, base); SAVE_2FPRS(n+2, base)
48#define SAVE_8FPRS(n, base) SAVE_4FPRS(n, base); SAVE_4FPRS(n+4, base)
49#define SAVE_16FPRS(n, base) SAVE_8FPRS(n, base); SAVE_8FPRS(n+8, base)
50#define SAVE_32FPRS(n, base) SAVE_16FPRS(n, base); SAVE_16FPRS(n+16, base)
51#define REST_FPR(n, base) lfd n,THREAD_FPR0+8*(n)(base)
52#define REST_2FPRS(n, base) REST_FPR(n, base); REST_FPR(n+1, base)
53#define REST_4FPRS(n, base) REST_2FPRS(n, base); REST_2FPRS(n+2, base)
54#define REST_8FPRS(n, base) REST_4FPRS(n, base); REST_4FPRS(n+4, base)
55#define REST_16FPRS(n, base) REST_8FPRS(n, base); REST_8FPRS(n+8, base)
56#define REST_32FPRS(n, base) REST_16FPRS(n, base); REST_16FPRS(n+16, base)
57
58#define SAVE_VR(n,b,base) li b,THREAD_VR0+(16*(n)); stvx n,b,base
Kumar Gala5f7c6902005-09-09 15:02:25 -050059#define SAVE_2VRS(n,b,base) SAVE_VR(n,b,base); SAVE_VR(n+1,b,base)
60#define SAVE_4VRS(n,b,base) SAVE_2VRS(n,b,base); SAVE_2VRS(n+2,b,base)
61#define SAVE_8VRS(n,b,base) SAVE_4VRS(n,b,base); SAVE_4VRS(n+4,b,base)
62#define SAVE_16VRS(n,b,base) SAVE_8VRS(n,b,base); SAVE_8VRS(n+8,b,base)
63#define SAVE_32VRS(n,b,base) SAVE_16VRS(n,b,base); SAVE_16VRS(n+16,b,base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#define REST_VR(n,b,base) li b,THREAD_VR0+(16*(n)); lvx n,b,base
Kumar Gala5f7c6902005-09-09 15:02:25 -050065#define REST_2VRS(n,b,base) REST_VR(n,b,base); REST_VR(n+1,b,base)
66#define REST_4VRS(n,b,base) REST_2VRS(n,b,base); REST_2VRS(n+2,b,base)
67#define REST_8VRS(n,b,base) REST_4VRS(n,b,base); REST_4VRS(n+4,b,base)
68#define REST_16VRS(n,b,base) REST_8VRS(n,b,base); REST_8VRS(n+8,b,base)
69#define REST_32VRS(n,b,base) REST_16VRS(n,b,base); REST_16VRS(n+16,b,base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71#define SAVE_EVR(n,s,base) evmergehi s,s,n; stw s,THREAD_EVR0+4*(n)(base)
Kumar Gala5f7c6902005-09-09 15:02:25 -050072#define SAVE_2EVRS(n,s,base) SAVE_EVR(n,s,base); SAVE_EVR(n+1,s,base)
73#define SAVE_4EVRS(n,s,base) SAVE_2EVRS(n,s,base); SAVE_2EVRS(n+2,s,base)
74#define SAVE_8EVRS(n,s,base) SAVE_4EVRS(n,s,base); SAVE_4EVRS(n+4,s,base)
75#define SAVE_16EVRS(n,s,base) SAVE_8EVRS(n,s,base); SAVE_8EVRS(n+8,s,base)
76#define SAVE_32EVRS(n,s,base) SAVE_16EVRS(n,s,base); SAVE_16EVRS(n+16,s,base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#define REST_EVR(n,s,base) lwz s,THREAD_EVR0+4*(n)(base); evmergelo n,s,n
Kumar Gala5f7c6902005-09-09 15:02:25 -050078#define REST_2EVRS(n,s,base) REST_EVR(n,s,base); REST_EVR(n+1,s,base)
79#define REST_4EVRS(n,s,base) REST_2EVRS(n,s,base); REST_2EVRS(n+2,s,base)
80#define REST_8EVRS(n,s,base) REST_4EVRS(n,s,base); REST_4EVRS(n+4,s,base)
81#define REST_16EVRS(n,s,base) REST_8EVRS(n,s,base); REST_8EVRS(n+8,s,base)
82#define REST_32EVRS(n,s,base) REST_16EVRS(n,s,base); REST_16EVRS(n+16,s,base)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Michael Ellerman8c716322005-10-24 15:07:27 +100084/* Macros to adjust thread priority for hardware multithreading */
85#define HMT_VERY_LOW or 31,31,31 # very low priority
86#define HMT_LOW or 1,1,1
87#define HMT_MEDIUM_LOW or 6,6,6 # medium low priority
88#define HMT_MEDIUM or 2,2,2
89#define HMT_MEDIUM_HIGH or 5,5,5 # medium high priority
90#define HMT_HIGH or 3,3,3
Kumar Gala5f7c6902005-09-09 15:02:25 -050091
92/* handle instructions that older assemblers may not know */
93#define RFCI .long 0x4c000066 /* rfci instruction */
94#define RFDI .long 0x4c00004e /* rfdi instruction */
95#define RFMCI .long 0x4c00004c /* rfmci instruction */
96
Arnd Bergmann88ced032005-12-16 22:43:46 +010097#ifdef __KERNEL__
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100098#ifdef CONFIG_PPC64
99
100#define XGLUE(a,b) a##b
101#define GLUE(a,b) XGLUE(a,b)
102
103#define _GLOBAL(name) \
104 .section ".text"; \
105 .align 2 ; \
106 .globl name; \
107 .globl GLUE(.,name); \
108 .section ".opd","aw"; \
109name: \
110 .quad GLUE(.,name); \
111 .quad .TOC.@tocbase; \
112 .quad 0; \
113 .previous; \
114 .type GLUE(.,name),@function; \
115GLUE(.,name):
116
117#define _KPROBE(name) \
118 .section ".kprobes.text","a"; \
119 .align 2 ; \
120 .globl name; \
121 .globl GLUE(.,name); \
122 .section ".opd","aw"; \
123name: \
124 .quad GLUE(.,name); \
125 .quad .TOC.@tocbase; \
126 .quad 0; \
127 .previous; \
128 .type GLUE(.,name),@function; \
129GLUE(.,name):
130
131#define _STATIC(name) \
132 .section ".text"; \
133 .align 2 ; \
134 .section ".opd","aw"; \
135name: \
136 .quad GLUE(.,name); \
137 .quad .TOC.@tocbase; \
138 .quad 0; \
139 .previous; \
140 .type GLUE(.,name),@function; \
141GLUE(.,name):
142
143#else /* 32-bit */
144
145#define _GLOBAL(n) \
146 .text; \
147 .stabs __stringify(n:F-1),N_FUN,0,0,n;\
148 .globl n; \
149n:
150
151#define _KPROBE(n) \
152 .section ".kprobes.text","a"; \
153 .globl n; \
154n:
155
156#endif
157
Kumar Gala5f7c6902005-09-09 15:02:25 -0500158/*
159 * LOADADDR( rn, name )
160 * loads the address of 'name' into 'rn'
161 *
162 * LOADBASE( rn, name )
Paul Mackerras63162222005-10-27 22:44:39 +1000163 * loads the address (possibly without the low 16 bits) of 'name' into 'rn'
Kumar Gala5f7c6902005-09-09 15:02:25 -0500164 * suitable for base+disp addressing
165 */
166#ifdef __powerpc64__
167#define LOADADDR(rn,name) \
168 lis rn,name##@highest; \
169 ori rn,rn,name##@higher; \
170 rldicr rn,rn,32,31; \
171 oris rn,rn,name##@h; \
172 ori rn,rn,name##@l
173
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000174#define LOADBASE(rn,name) \
Paul Mackerras63162222005-10-27 22:44:39 +1000175 ld rn,name@got(r2)
Kumar Gala5f7c6902005-09-09 15:02:25 -0500176
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000177#define OFF(name) 0
Kumar Gala5f7c6902005-09-09 15:02:25 -0500178
179#define SET_REG_TO_CONST(reg, value) \
180 lis reg,(((value)>>48)&0xFFFF); \
181 ori reg,reg,(((value)>>32)&0xFFFF); \
182 rldicr reg,reg,32,31; \
183 oris reg,reg,(((value)>>16)&0xFFFF); \
184 ori reg,reg,((value)&0xFFFF);
185
186#define SET_REG_TO_LABEL(reg, label) \
187 lis reg,(label)@highest; \
188 ori reg,reg,(label)@higher; \
189 rldicr reg,reg,32,31; \
190 oris reg,reg,(label)@h; \
191 ori reg,reg,(label)@l;
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000192
Paul Mackerrasf78541d2005-10-28 22:53:37 +1000193/* offsets for stack frame layout */
194#define LRSAVE 16
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000195
196#else /* 32-bit */
Stephen Rothwell70620182005-10-12 17:44:55 +1000197#define LOADADDR(rn,name) \
Stephen Rothwellcf764852005-10-17 11:46:53 +1000198 lis rn,name@ha; \
Stephen Rothwell70620182005-10-12 17:44:55 +1000199 addi rn,rn,name@l
200
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000201#define LOADBASE(rn,name) \
202 lis rn,name@ha
203
204#define OFF(name) name@l
205
Paul Mackerrasf78541d2005-10-28 22:53:37 +1000206/* offsets for stack frame layout */
207#define LRSAVE 4
Paul Mackerrasb85a0462005-10-06 10:59:19 +1000208
Kumar Gala5f7c6902005-09-09 15:02:25 -0500209#endif
210
211/* various errata or part fixups */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212#ifdef CONFIG_PPC601_SYNC_FIX
213#define SYNC \
214BEGIN_FTR_SECTION \
215 sync; \
216 isync; \
217END_FTR_SECTION_IFSET(CPU_FTR_601)
218#define SYNC_601 \
219BEGIN_FTR_SECTION \
220 sync; \
221END_FTR_SECTION_IFSET(CPU_FTR_601)
222#define ISYNC_601 \
223BEGIN_FTR_SECTION \
224 isync; \
225END_FTR_SECTION_IFSET(CPU_FTR_601)
226#else
227#define SYNC
228#define SYNC_601
229#define ISYNC_601
230#endif
231
Kumar Gala5f7c6902005-09-09 15:02:25 -0500232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233#ifndef CONFIG_SMP
234#define TLBSYNC
235#else /* CONFIG_SMP */
236/* tlbsync is not implemented on 601 */
237#define TLBSYNC \
238BEGIN_FTR_SECTION \
239 tlbsync; \
240 sync; \
241END_FTR_SECTION_IFCLR(CPU_FTR_601)
242#endif
243
Kumar Gala5f7c6902005-09-09 15:02:25 -0500244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245/*
246 * This instruction is not implemented on the PPC 603 or 601; however, on
247 * the 403GCX and 405GP tlbia IS defined and tlbie is not.
248 * All of these instructions exist in the 8xx, they have magical powers,
249 * and they must be used.
250 */
251
252#if !defined(CONFIG_4xx) && !defined(CONFIG_8xx)
253#define tlbia \
254 li r4,1024; \
255 mtctr r4; \
256 lis r4,KERNELBASE@h; \
2570: tlbie r4; \
258 addi r4,r4,0x1000; \
259 bdnz 0b
260#endif
261
Kumar Gala5f7c6902005-09-09 15:02:25 -0500262
Kumar Gala5f7c6902005-09-09 15:02:25 -0500263#ifdef CONFIG_IBM440EP_ERR42
264#define PPC440EP_ERR42 isync
265#else
266#define PPC440EP_ERR42
267#endif
268
269
270#if defined(CONFIG_BOOKE)
Paul Mackerras63162222005-10-27 22:44:39 +1000271#define toreal(rd)
272#define fromreal(rd)
273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274#define tophys(rd,rs) \
275 addis rd,rs,0
276
277#define tovirt(rd,rs) \
278 addis rd,rs,0
279
Kumar Gala5f7c6902005-09-09 15:02:25 -0500280#elif defined(CONFIG_PPC64)
Paul Mackerras63162222005-10-27 22:44:39 +1000281#define toreal(rd) /* we can access c000... in real mode */
282#define fromreal(rd)
283
Kumar Gala5f7c6902005-09-09 15:02:25 -0500284#define tophys(rd,rs) \
Paul Mackerras63162222005-10-27 22:44:39 +1000285 clrldi rd,rs,2
Kumar Gala5f7c6902005-09-09 15:02:25 -0500286
287#define tovirt(rd,rs) \
Paul Mackerras63162222005-10-27 22:44:39 +1000288 rotldi rd,rs,16; \
289 ori rd,rd,((KERNELBASE>>48)&0xFFFF);\
290 rotldi rd,rd,48
Kumar Gala5f7c6902005-09-09 15:02:25 -0500291#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292/*
293 * On APUS (Amiga PowerPC cpu upgrade board), we don't know the
294 * physical base address of RAM at compile time.
295 */
Paul Mackerras63162222005-10-27 22:44:39 +1000296#define toreal(rd) tophys(rd,rd)
297#define fromreal(rd) tovirt(rd,rd)
298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299#define tophys(rd,rs) \
3000: addis rd,rs,-KERNELBASE@h; \
301 .section ".vtop_fixup","aw"; \
302 .align 1; \
303 .long 0b; \
304 .previous
305
306#define tovirt(rd,rs) \
3070: addis rd,rs,KERNELBASE@h; \
308 .section ".ptov_fixup","aw"; \
309 .align 1; \
310 .long 0b; \
311 .previous
Kumar Gala5f7c6902005-09-09 15:02:25 -0500312#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000314#ifdef CONFIG_PPC64
315#define RFI rfid
316#define MTMSRD(r) mtmsrd r
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
318#else
319#define FIX_SRR1(ra, rb)
320#ifndef CONFIG_40x
321#define RFI rfi
322#else
323#define RFI rfi; b . /* Prevent prefetch past rfi */
324#endif
325#define MTMSRD(r) mtmsr r
326#define CLR_TOP32(r)
Matt Porterc9cf73a2005-07-31 22:34:52 -0700327#endif
328
Arnd Bergmann88ced032005-12-16 22:43:46 +0100329#endif /* __KERNEL__ */
330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331/* The boring bits... */
332
333/* Condition Register Bit Fields */
334
335#define cr0 0
336#define cr1 1
337#define cr2 2
338#define cr3 3
339#define cr4 4
340#define cr5 5
341#define cr6 6
342#define cr7 7
343
344
345/* General Purpose Registers (GPRs) */
346
347#define r0 0
348#define r1 1
349#define r2 2
350#define r3 3
351#define r4 4
352#define r5 5
353#define r6 6
354#define r7 7
355#define r8 8
356#define r9 9
357#define r10 10
358#define r11 11
359#define r12 12
360#define r13 13
361#define r14 14
362#define r15 15
363#define r16 16
364#define r17 17
365#define r18 18
366#define r19 19
367#define r20 20
368#define r21 21
369#define r22 22
370#define r23 23
371#define r24 24
372#define r25 25
373#define r26 26
374#define r27 27
375#define r28 28
376#define r29 29
377#define r30 30
378#define r31 31
379
380
381/* Floating Point Registers (FPRs) */
382
383#define fr0 0
384#define fr1 1
385#define fr2 2
386#define fr3 3
387#define fr4 4
388#define fr5 5
389#define fr6 6
390#define fr7 7
391#define fr8 8
392#define fr9 9
393#define fr10 10
394#define fr11 11
395#define fr12 12
396#define fr13 13
397#define fr14 14
398#define fr15 15
399#define fr16 16
400#define fr17 17
401#define fr18 18
402#define fr19 19
403#define fr20 20
404#define fr21 21
405#define fr22 22
406#define fr23 23
407#define fr24 24
408#define fr25 25
409#define fr26 26
410#define fr27 27
411#define fr28 28
412#define fr29 29
413#define fr30 30
414#define fr31 31
415
Kumar Gala5f7c6902005-09-09 15:02:25 -0500416/* AltiVec Registers (VPRs) */
417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418#define vr0 0
419#define vr1 1
420#define vr2 2
421#define vr3 3
422#define vr4 4
423#define vr5 5
424#define vr6 6
425#define vr7 7
426#define vr8 8
427#define vr9 9
428#define vr10 10
429#define vr11 11
430#define vr12 12
431#define vr13 13
432#define vr14 14
433#define vr15 15
434#define vr16 16
435#define vr17 17
436#define vr18 18
437#define vr19 19
438#define vr20 20
439#define vr21 21
440#define vr22 22
441#define vr23 23
442#define vr24 24
443#define vr25 25
444#define vr26 26
445#define vr27 27
446#define vr28 28
447#define vr29 29
448#define vr30 30
449#define vr31 31
450
Kumar Gala5f7c6902005-09-09 15:02:25 -0500451/* SPE Registers (EVPRs) */
452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453#define evr0 0
454#define evr1 1
455#define evr2 2
456#define evr3 3
457#define evr4 4
458#define evr5 5
459#define evr6 6
460#define evr7 7
461#define evr8 8
462#define evr9 9
463#define evr10 10
464#define evr11 11
465#define evr12 12
466#define evr13 13
467#define evr14 14
468#define evr15 15
469#define evr16 16
470#define evr17 17
471#define evr18 18
472#define evr19 19
473#define evr20 20
474#define evr21 21
475#define evr22 22
476#define evr23 23
477#define evr24 24
478#define evr25 25
479#define evr26 26
480#define evr27 27
481#define evr28 28
482#define evr29 29
483#define evr30 30
484#define evr31 31
485
486/* some stab codes */
487#define N_FUN 36
488#define N_RSYM 64
489#define N_SLINE 68
490#define N_SO 100
Kumar Gala5f7c6902005-09-09 15:02:25 -0500491
Kumar Gala5f7c6902005-09-09 15:02:25 -0500492#endif /* __ASSEMBLY__ */
493
494#endif /* _ASM_POWERPC_PPC_ASM_H */