OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [lib/] [libbsp/] [powerpc/] [psim/] [vectors/] [align_h.S] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*  align_h.s   1.1 - 95/12/04
2
 *
3
 *  This file contains the assembly code for the PowerPC 403
4
 *  alignment exception handler for RTEMS.
5
 *
6
 *  Based upon IBM provided code with the following release:
7
 *
8
 *  This source code has been made available to you by IBM on an AS-IS
9
 *  basis.  Anyone receiving this source is licensed under IBM
10
 *  copyrights to use it in any way he or she deems fit, including
11
 *  copying it, modifying it, compiling it, and redistributing it either
12
 *  with or without modifications.  No license under IBM patents or
13
 *  patent applications is to be implied by the copyright license.
14
 *
15
 *  Any user of this software should understand that IBM cannot provide
16
 *  technical support for this software and will not be responsible for
17
 *  any consequences resulting from the use of this software.
18
 *
19
 *  Any person who transfers this source code or any derivative work
20
 *  must include the IBM copyright notice, this paragraph, and the
21
 *  preceding two paragraphs in the transferred software.
22
 *
23
 *      COPYRIGHT   I B M   CORPORATION 1995
24
 *      LICENSED MATERIAL  -  PROGRAM PROPERTY OF I B M
25
 *
26
 * Modifications:
27
 *
28
 *  Author:     Andrew Bray 
29
 *
30
 *  COPYRIGHT (c) 1995 by i-cubed ltd.
31
 *
32
 *  To anyone who acknowledges that this file is provided "AS IS"
33
 *  without any express or implied warranty:
34
 *      permission to use, copy, modify, and distribute this file
35
 *      for any purpose is hereby granted without fee, provided that
36
 *      the above copyright notice and this notice appears in all
37
 *      copies, and that the name of i-cubed limited not be used in
38
 *      advertising or publicity pertaining to distribution of the
39
 *      software without specific, written prior permission.
40
 *      i-cubed limited makes no representations about the suitability
41
 *      of this software for any purpose.
42
 *
43
 *  align_h.S,v 1.4 2002/04/18 20:55:05 joel Exp
44
 */
45
 
46
#include 
47
#include 
48
 
49
.set    CACHE_SIZE,16           # cache line size of 32 bytes
50
.set    CACHE_SIZE_L2,4         # cache line size, log 2
51
 
52
.set    Open_gpr0,0
53
.set    Open_gpr1,4
54
.set    Open_gpr2,8
55
.set    Open_gpr3,12
56
.set    Open_gpr4,16
57
.set    Open_gpr5,20
58
.set    Open_gpr6,24
59
.set    Open_gpr7,28
60
.set    Open_gpr8,32
61
.set    Open_gpr9,36
62
.set    Open_gpr10,40
63
.set    Open_gpr11,44
64
.set    Open_gpr12,48
65
.set    Open_gpr13,52
66
.set    Open_gpr14,56
67
.set    Open_gpr15,60
68
.set    Open_gpr16,64
69
.set    Open_gpr17,68
70
.set    Open_gpr18,72
71
.set    Open_gpr19,76
72
.set    Open_gpr20,80
73
.set    Open_gpr21,84
74
.set    Open_gpr22,88
75
.set    Open_gpr23,92
76
.set    Open_gpr24,96
77
.set    Open_gpr25,100
78
.set    Open_gpr26,104
79
.set    Open_gpr27,108
80
.set    Open_gpr28,112
81
.set    Open_gpr29,116
82
.set    Open_gpr30,120
83
.set    Open_gpr31,124
84
.set    Open_xer,128
85
.set    Open_lr,132
86
.set    Open_ctr,136
87
.set    Open_cr,140
88
.set    Open_srr2,144
89
.set    Open_srr3,148
90
.set    Open_srr0,152
91
.set    Open_srr1,156
92
 
93
 
94
/*
95
 *  This code makes several assumptions for processing efficiency
96
 *  *  General purpose registers are continuous in the image, beginning with
97
 *     Open_gpr0
98
 *  *  Hash table is highly dependent on opcodes - opcode changes *will*
99
 *     require rework of the instruction decode mechanism.
100
 */
101
 
102
        .text
103
        .globl  align_h
104
 
105
        .align  CACHE_SIZE_L2
106
align_h:
107
        /*-----------------------------------------------------------------------
108
         * Store GPRs in Open Reg save area
109
         * Set up r2 as base reg, r1 pointing to Open Reg save area
110
         *----------------------------------------------------------------------*/
111
        stmw    r0,ALIGN_REGS(r0)
112
        li      r1,ALIGN_REGS
113
        /*-----------------------------------------------------------------------
114
         * Store special purpose registers in reg save area
115
         *----------------------------------------------------------------------*/
116
        mfxer   r7
117
        mflr    r8
118
        mfcr    r9
119
        mfctr   r10
120
        stw     r7,Open_xer(r1)
121
        stw     r8,Open_lr(r1)
122
        stw     r9,Open_cr(r1)
123
        stw     r10,Open_ctr(r1)
124
#if defined(ppc403) || defined(ppc405)
125
        mfspr   r7, srr2                /* SRR 2 */
126
        mfspr   r8, srr3                /* SRR 3 */
127
#endif
128
        mfspr   r9, srr0                /* SRR 0 */
129
        mfspr   r10, srr1               /* SRR 1 */
130
#if defined(ppc403) || defined(ppc405)
131
        stw     r7,Open_srr2(r1)
132
        stw     r8,Open_srr3(r1)
133
#endif
134
        stw     r9,Open_srr0(r1)
135
        stw     r10,Open_srr1(r1)
136
 
137
/*      Set up common registers */
138
#if defined(ppc403) || defined(ppc405)
139
        mfspr   r5, dear                /* DEAR: R5 is data exception address */
140
#endif
141
        lwz     r9,Open_srr0(r1)        /* get faulting instruction */
142
        addi    r7,r9,4                 /* bump instruction */
143
        stw     r7,Open_srr0(r1)        /* restore to image */
144
        lwz     r9, 0(r9)               /* retrieve actual instruction */
145
        rlwinm  r6,r9,18,25,29          /* r6 is RA * 4 field from instruction */
146
        rlwinm  r7,r9,6,26,31           /* r7 is primary opcode */
147
        bl      ref_point               /* establish addressibility */
148
ref_point:
149
        mflr    r11                     /* r11 is the anchor point for ref_point */
150
        addi    r10, r7, -31            /* r10 = r7 - 31 */
151
        rlwinm  r10,r10,2,2,31          /* r10 *= 4 */
152
        add     r10, r10, r11           /* r10 += anchor point */
153
        lwz     r10, primary_jt-ref_point(r10)
154
        mtlr    r10
155
        rlwinm  r8,r9,13,25,29          /* r8 is RD * 4 */
156
        la      r7,Open_gpr0(r1)        /* r7 is address of GPR 0 in list */
157
        blr
158
primary_jt:
159
        .long   xform
160
        .long   lwz
161
        .long   lwzu
162
        .long   0
163
        .long   0
164
        .long   stw
165
        .long   stwu
166
        .long   0
167
        .long   0
168
        .long   lhz
169
        .long   lhzu
170
        .long   lha
171
        .long   lhau
172
        .long   sth
173
        .long   sthu
174
        .long   lmw
175
        .long   stmw
176
/*
177
 *   handlers
178
 */
179
/*
180
 * xform instructions require an additional decode.  Fortunately, a relatively
181
 * simple hash step breaks the instructions out with no collisions
182
 */
183
xform:
184
        rlwinm  r7,r9,31,22,31          /* r7 is secondary opcode */
185
        rlwinm  r10,r7,27,5,31          /* r10 = r7 >> 5 */
186
        add     r10,r7,r10              /* r10 = r7 + r10 */
187
        rlwinm  r10,r10,2,25,29         /* r10 = (r10 & 0x1F) * 4 */
188
        add     r10,r10,r11             /* r10 += anchor point */
189
        lwz     r10, secondary_ht-ref_point(r10)
190
        mtlr    r10
191
        la      r7,Open_gpr0(r1)        /* r7 is address of GPR 0 in list */
192
        rlwinm  r8,r9,13,25,29          /* r8 is RD * 4 */
193
        blrl
194
 
195
secondary_ht:
196
        .long   lhzux                   /* b 0  0x137 */
197
        .long   lhax                    /* b 1  0x157 */
198
        .long   lhaux                   /* b 2  0x177 */
199
        .long   sthx                    /* b 3  0x197 */
200
        .long   sthux                   /* b 4  0x1b7 */
201
        .long   0                       /* b 5 */
202
        .long   lwbrx                   /* b 6  0x216 */
203
        .long   0                       /* b 7 */
204
        .long   0                       /* b 8 */
205
        .long   0                       /* b 9 */
206
        .long   stwbrx                  /* b A  0x296 */
207
        .long   0                       /* b B */
208
        .long   0                       /* b C */
209
        .long   0                       /* b D */
210
        .long   lhbrx                   /* b E   0x316 */
211
        .long   0                       /* b F */
212
        .long   0                       /* b 10 */
213
        .long   0                       /* b 11 */
214
        .long   sthbrx                  /* b 12  0x396 */
215
        .long   0                       /* b 13 */
216
        .long   lwarx                   /* b 14  0x014 */
217
        .long   dcbz                    /* b 15  0x3f6 */
218
        .long   0                       /* b 16 */
219
        .long   lwzx                    /* b 17  0x017 */
220
        .long   lwzux                   /* b 18  0x037 */
221
        .long   0                       /* b 19 */
222
        .long   stwcx                   /* b 1A  0x096 */
223
        .long   stwx                    /* b 1B  0x097 */
224
        .long   stwux                   /* b 1C  0x0B7 */
225
        .long   0                       /* b 1D */
226
        .long   0                       /* b 1E */
227
        .long   lhzx                    /* b 1F 0x117 */
228
 
229
/*
230
 * for all handlers
231
 *       r4 - Addressability to interrupt context
232
 *       r5 - DEAR address (faulting data address)
233
 *       r6 - RA field * 4
234
 *       r7 - Address of GPR 0 in image
235
 *       r8 - RD field * 4
236
 *       r9 - Failing instruction
237
 */
238
 
239
/*       Load halfword algebraic with update */
240
lhau:
241
/*       Load halfword algebraic with update indexed */
242
lhaux:
243
        stwx    r5,r7,r6                /* update RA with effective addr */
244
 
245
/*       Load halfword algebraic */
246
lha:
247
/*       Load halfword algebraic indexed */
248
lhax:
249
        lswi    r10,r5,2                /* load two bytes into r10 */
250
        srawi   r10,r10,16              /* shift right 2 bytes, extending sign */
251
        stwx    r10,r7,r8               /* update reg image */
252
        b       align_complete          /* return */
253
 
254
/*       Load Half Word Byte-Reversed Indexed */
255
lhbrx:
256
        lswi    r10,r5,2                /* load two bytes from DEAR into r10 */
257
        rlwinm  r10,r10,0,0,15          /* mask off lower 2 bytes */
258
        stwbrx  r10,r7,r8               /* store reversed in reg image */
259
        b       align_complete          /* return */
260
 
261
/*       Load Half Word and Zero with Update */
262
lhzu:
263
/*       Load Half Word and Zero with Update Indexed */
264
lhzux:
265
        stwx    r5,r7,r6                /* update RA with effective addr */
266
 
267
/*       Load Half Word and Zero */
268
lhz:
269
/*       Load Half Word and Zero Indexed */
270
lhzx:
271
        lswi    r10,r5,2                /* load two bytes from DEAR into r10 */
272
        rlwinm  r10,r10,16,16,31        /* shift right 2 bytes, with zero fill */
273
        stwx    r10,r7,r8               /* update reg image */
274
        b       align_complete          /* return */
275
 
276
/*
277
 *       Load Multiple Word
278
 */
279
lmw:
280
        lwzx    r9,r6,r7                /* R9 contains saved value of RA */
281
        addi    r10,r7,32*4             /* r10 points to r31 in image  + 4 */
282
        rlwinm  r8,r8,30,2,31           /* r8 >>= 2  (recovers RT) */
283
        subfic  r8,r8,32                /* r8 is reg count to load */
284
        mtctr   r8                      /* load counter */
285
        addi    r8,r8,-1                /* r8-- */
286
        rlwinm  r8,r8,2,2,31            /* r8 *= 4 */
287
        add     r5,r5,r8                /* update DEAR to point to last reg */
288
lwmloop:
289
        lswi    r11,r5,4                /* load r11 with 4 bytes from DEAR */
290
        stwu    r11,-4(r10)             /* load image and decrement pointer */
291
        addi    r5,r5,-4                /* decrement effective address */
292
        bdnz    lwmloop
293
        stwx    r9,r6,r7                /* restore RA (in case it was trashed) */
294
        b       align_complete          /* return */
295
 
296
/*
297
 *       Load Word and Reserve Indexed
298
 */
299
lwarx:
300
        lswi    r10,r5,4                /* load four bytes from DEAR into r10 */
301
        stwx    r10,r7,r8               /* update reg image */
302
        rlwinm  r5,r5,0,0,29            /* Word align address */
303
        lwarx   r10,0,r5                /* Set reservation */
304
        b       align_complete          /* return */
305
 
306
/*
307
 *       Load Word Byte-Reversed Indexed
308
 */
309
lwbrx:
310
        lswi    r10,r5,4                /* load four bytes from DEAR into r10 */
311
        stwbrx  r10,r7,r8               /* store reversed in reg image */
312
        b       align_complete          /* return */
313
 
314
/*       Load Word and Zero with Update */
315
lwzu:
316
/*       Load Word and Zero with Update Indexed */
317
lwzux:
318
        stwx    r5,r7,r6                /* update RA with effective addr */
319
 
320
/*       Load Word and Zero */
321
lwz:
322
/*       Load Word and Zero Indexed */
323
lwzx:
324
        lswi    r10,r5,4                /* load four bytes from DEAR into r10 */
325
        stwx    r10,r7,r8               /* update reg image */
326
        b       align_complete          /* return */
327
 
328
/*    Store instructions */
329
 
330
/* */
331
/*       Store Half Word and Update */
332
sthu:
333
/*       Store Half Word and Update Indexed */
334
sthux:
335
        stwx    r5,r7,r6                /* Update RA with effective address */
336
 
337
/*       Store Half Word */
338
sth:
339
/*       Store Half Word Indexed */
340
sthx:
341
        lwzx    r10,r8,r7               /* retrieve source register value */
342
        rlwinm  r10,r10,16,0,15         /* move two bytes to high end of reg */
343
        stswi   r10,r5,2                /* store bytes to DEAR address */
344
        b       align_complete          /* return */
345
 
346
/* */
347
/*       Store Half Word Byte-Reversed Indexed */
348
sthbrx:
349
        lwbrx   r10,r8,r7               /* retrieve src reg value byte reversed */
350
        stswi   r10,r5,2                /* move two bytes to DEAR address */
351
        b       align_complete          /* return */
352
 
353
/* */
354
/*       Store Multiple Word */
355
stmw:
356
        addi    r10,r7,32*4             /* r10 points to r31 in image  + 4 */
357
        rlwinm  r8,r8,30,2,31           /* r8 >>= 2  (recovers RT) */
358
        subfic  r8,r8,32                /* r8 is reg count to load */
359
        mtctr   r8                      /* load counter */
360
        addi    r8,r8,-1                /* r8-- */
361
        rlwinm  r8,r8,2,2,31            /* r8 *= 4 */
362
        add     r5,r5,r8                /* update DEAR to point to last reg */
363
stmloop:
364
        lwzu    r11,-4(r10)             /* get register value */
365
        stswi   r11,r5,4                /* output to DEAR address */
366
        addi    r5,r5,-4                /* decrement effective address */
367
        bdnz    stmloop
368
        b       align_complete          /* return */
369
 
370
/* */
371
/*       Store Word and Update */
372
stwu:
373
/*       Store Word and Update Indexed */
374
stwux:
375
        stwx    r5,r7,r6                /* Update RA with effective address */
376
 
377
/*       Store Word */
378
stw:
379
/*       Store Word Indexed */
380
stwx:
381
        lwzx    r10,r8,r7               /* retrieve source register value */
382
        stswi   r10,r5,4                /* store bytes to DEAR address */
383
        b       align_complete          /* return */
384
 
385
/* */
386
/*       Store Word Byte-Reversed Indexed */
387
stwbrx:
388
        lwbrx   r10,r8,r7               /* retrieve src reg value byte reversed */
389
        stswi   r10,r5,4                /* move two bytes to DEAR address */
390
        b       align_complete          /* return */
391
 
392
/* */
393
/*       Store Word Conditional Indexed */
394
stwcx:
395
        rlwinm  r10,r5,0,0,29           /* r10 = word aligned DEAR */
396
        lwz     r11,0(r10)              /* save original value of store */
397
        stwcx.  r11,r0,r10              /* attempt store to address */
398
        bne     stwcx_moveon            /* store failed, move on */
399
        stw     r11,0(r10)              /* repair damage */
400
        lwzx    r9,r7,r8                /* get register value */
401
        stswi   r10,r5,4                /* store bytes to DEAR address */
402
stwcx_moveon:
403
        mfcr    r11                     /* get condition reg */
404
        lwz     r9,Open_cr(r1)          /* get condition reg image */
405
        rlwimi  r9,r11,0,0,2            /* insert 3 CR bits into cr image */
406
        lwz     r11,Open_xer(r1)        /* get XER reg */
407
        rlwimi  r9,r11,29,2,2           /* insert XER SO bit into cr image */
408
        stw     r9,Open_cr(r1)          /* store cr image */
409
        b       align_complete          /* return */
410
 
411
/* */
412
/*       Data Cache Block Zero */
413
dcbz:
414
        rlwinm  r5,r5,0,0,31-CACHE_SIZE_L2
415
                                        /* get address to nearest Cache line */
416
        addi    r5,r5,-4                /* adjust by a word */
417
        addi    r10,r0,CACHE_SIZE/4     /* set counter value */
418
        mtctr   r10
419
        addi    r11,r0,0                /* r11 = 0 */
420
dcbz_loop:
421
        stwu    r11,4(r5)               /* store a word and update EA */
422
        bdnz    dcbz_loop
423
        b       align_complete          /* return */
424
 
425
align_complete:
426
        /*-----------------------------------------------------------------------
427
         * Restore regs and return from the interrupt
428
         *----------------------------------------------------------------------*/
429
        lmw     r24,Open_xer+ALIGN_REGS(r0)
430
        mtxer   r24
431
        mtlr    r25
432
        mtctr   r26
433
        mtcrf   0xFF, r27
434
#if defined(ppc403) || defined(ppc405)
435
        mtspr   srr2, r28               /* SRR 2 */
436
        mtspr   srr3, r29               /* SRR 3 */
437
#endif
438
        mtspr   srr0, r30               /* SRR 0 */
439
        mtspr   srr1, r31               /* SRR 1 */
440
        lmw     r1,Open_gpr1+ALIGN_REGS(r0)
441
        lwz     r0,Open_gpr0+ALIGN_REGS(r0)
442
        rfi

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.