source: rtems/c/src/lib/libbsp/powerpc/shared/bootloader/qemu_fakerom.S @ 04d3761

4.115
Last change on this file since 04d3761 was 6464a2b, checked in by Till Straumann <strauman@…>, on 07/18/11 at 16:38:54

2011-07-18 Till Straumann <strauman@…>

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