source: rtems/bsps/powerpc/psim/start/align_h.S @ 762fa62

5
Last change on this file since 762fa62 was b80be135, checked in by Sebastian Huber <sebastian.huber@…>, on 04/25/18 at 12:51:01

bsp/psim: Move align_h.S to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

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