source: rtems/bsps/powerpc/motorola_powerpc/bootloader/qemu_fakerom.S @ eb36d11

5
Last change on this file since eb36d11 was 03e1d837, checked in by Sebastian Huber <sebastian.huber@…>, on 04/24/18 at 05:06:36

bsps/powerpc: Move bootloader to bsps

This bootloader is only used by the motorola_powerpc BSP.

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/* A fake 'bios' which does nothing but move a kernel image
2 * to RAM address zero and then starts that...
3 */
4
5#include <bsp/residual.h>
6
7#define LD_CACHE_LINE_SIZE  5
8#define INIT_STACK (0x100 - 16) /* 16-byte/svr4 aligned */
9
10/* These offsets must correspond to declaration in qemu_fakeres.c */
11#define DAT_LEN    0
12#define RES_OFF    4
13#define CMD_OFF    8
14#define CMD_LEN   12
15#define IMG_ADR   16
16
17/* Non-volatile registers */
18#define OBASE     30
19#define PCID      25
20#define PCIA      26
21
22#define PCI_MAX_DEV 32
23
24#define BA_OPCODE(tgt)  ((18<<(31-5)) | 2 | ((tgt) & 0x03fffffc))
25
26        .global fake_data
27        .global res_set_memsz
28
29        .global _start
30_start:
31        lis    1,  INIT_STACK@h
32        ori    1,1,INIT_STACK@l
33
34                /* qemu 0.14.1 has the wrong exception prefix for 74xx CPUs
35                 * (bug 811683). Work around this by putting a stub at 0x00000X00
36                 * which simply jumps to high memory. We only need the SC exception
37                 * for now.
38                 */
39        lis  3,    BA_OPCODE(0xfff00000)@h
40        ori  3, 3, BA_OPCODE(0xfff00000)@l
41        li   4, 0x0c00
42        add  3, 3, 4
43        stw  3, 0(4)
44        dcbf 0, 4
45        icbi 0, 4
46
47        bl     pci_irq_set
48                /* copy residual to RAM and fix up;
49                 * this routine returns a pointer to
50                 * a 'fake_data' struct. If reading
51                 * NVRAM failed then the return value
52                 * points to a fall-back version in
53                 * ROM...
54                 */
55        bl     res_copy
56                /* fake_data pointer to R29 */
57        mr     29, 3
58
59                /* Load up R3..R5 with PreP mandated
60                 * values (R3: residual, R4: kernel image,
61                 * R5: OpenFirmware PTR (or NULL).
62                 */
63
64                /* load R3 with residual pointer  */
65        lwz    3, RES_OFF(29)
66        add    3, 3, 29
67
68                /* load R4 with image address     */
69        lwz    4, IMG_ADR(29)
70
71                /* load R5 with zero (OFW = NULL) */
72        li     5, 0
73                /* EXTENSION: R6 = cmdline start  */
74        lwz    6, CMD_OFF(29)
75        add    6, 6, 29
76                /* EXTENSION: R7 = cmdline end    */
77        lwz    7, CMD_LEN(29)
78        add    7, 7, 6
79
80                /* jump to image address          */
81        mtctr  4
82        bctr
83
84        .org 0x100
85        b    _start
86
87        .org 0x110
88template:
89        mfsrr0 30
90        mfsrr1 31
911:  b      1b
92template_end:
93
94        .org 0xc00
95        b    monitor
96       
97
98        .org 0x4000
99codemove: /* src/dst are cache-aligned */
100        addi   5,5,(1<<LD_CACHE_LINE_SIZE)-1
101        srwi   5,5,LD_CACHE_LINE_SIZE
102        addi   3,3,-4
103        addi   4,4,-4
1041:
105        li     0,  (1<<LD_CACHE_LINE_SIZE)
106        mtctr  0
1072:
108        lwzu   0,  4(3)
109        stwu   0,  4(4)
110        bdnz   2b
111        dcbf   0,4
112        icbi   0,4
113        addic. 5,5,-1
114        bne  1b
115        blr
116
117cpexc:
118        lis    3,template@h
119        ori    3,3,template@l
120        li     5,template_end-template
121        b      codemove
122
123monitor:
124        stwu   1,-16(1)
125        stw    OBASE, 8(1)
126        lis    OBASE, 0x80000000@h
127        cmplwi 10,0x63 /* enter_monitor -> RESET */
128        bne    10f
129hwreset:
130        li   3,1
131        stb  3,0x92(OBASE)
1321:  b 1b
13310: cmplwi 10,0x1d /* .NETCTRL -> ignore */
134        bne    10f
135        b      ret_from_mon
13610: b hwreset      /* unknown -> RESET */
137
138ret_from_mon:
139        lwz    OBASE,8(1)
140        lwz    1,0(1)
141        rfi
142
143rcb:
144        stwbrx 3, 0, PCIA
145        lbzx   3, 0, PCID
146        blr
147
148wcb:
149        stwbrx 3, 0, PCIA
150        stbx   4, 0, PCID
151        blr
152
153rcd:
154        stwbrx 3, 0, PCIA
155        lwbrx  3, 0, PCID
156        blr
157
158/* fixup pci interrupt line register according to what
159 * qemu does: line = ((pin-1) +  slot_no) & 1 ? 11 : 9;
160 */
161pci_irq_set:
162                /* set up stack frame */
163        stwu    1, -32(1)
164        mflr    0
165        stw     0,  32+4(1)
166                /* load counter with # of PCI devs */   
167        li      0, PCI_MAX_DEV
168        mtctr   0
169                /* save non-volatile registers we use
170                 * in stack frame
171                 */
172        stw    20,               8(1)
173        stw  PCIA,              12(1)
174        stw  PCID,              16(1)
175                /* load non-volatile registers with
176                 * intended values.
177                 */
178        lis  20,         0x80000000@h /* key for slot # 0             */
179        lis  PCIA,       0x80000cf8@h /* PCI config space address reg */
180        ori  PCIA, PCIA, 0x80000cf8@l
181        addi PCID, PCIA, 4            /* PCI config space data    reg */
182
183                /* loop over all slots and fix up PCI IRQ LINE */
1841:
185        mr   3, 20
186        bl   rcd
187        addi 3, 3, 1
188        cmplwi 3, 0      /* slot empty (= -1 + 1 = 0) ? */
189        beq  2f
190        addi 3, 20, 0x3d
191        bl   rcb
192        cmplwi 3, 0
193        beq  2f
194        slwi  4, 3, 11
195        addi  3, 20, 0x3c
196        xor   4, 4, 3    /* bit 11 = slot # + irq_num [zero-based] + 1 */
197        andi. 4, 4, 0x0800
198        li   4, 11
199        beq  3f
200        li   4,  9
2013:
202        bl   wcb
2032:
204        addi 20, 20, 0x0800 /* next slot */
205    bdnz 1b
206
207                /* restore and return */
208        lwz 20,  32+4(1)
209        mtlr 20
210        lwz PCID, 16(1)
211        lwz PCIA, 12(1)
212        lwz 20,    8(1)
213        lwz 1,     0(1)
214        blr
215
216        .section .romentry, "ax"
217        b     _start
Note: See TracBrowser for help on using the repository browser.