2 * Creation Date: <2001/06/16 21:30:18 samuel>
3 * Time-stamp: <2003/04/04 16:32:06 samuel>
7 * Asm glue for ELF images run inside MOL
9 * Copyright (C) 2001, 2002, 2003 Samuel Rydh (samuel@ibrium.se)
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation
17 #include "asm/asmdefs.h"
18 #include "asm/processor.h"
21 /************************************************************************/
23 /************************************************************************/
25 #define ILLEGAL_VECTOR( v ) .org __vectors + v ; bl trap_error ;
26 #define VECTOR( v, dummystr ) .org __vectors + v ; vector__##v
28 #define EXCEPTION_PREAMBLE \
29 mtsprg1 r1 ; /* scratch */ \
30 mfsprg0 r1 ; /* exception stack in sprg0 */ \
31 addi r1,r1,-80 ; /* push exception frame */ \
33 stw r0,0(r1) ; /* save r0 */ \
35 stw r0,4(r1) ; /* save r1 */ \
36 stw r2,8(r1) ; /* save r2 */ \
37 stw r3,12(r1) ; /* save r3 */ \
58 addi r1,r1,-16 ; /* call conventions uses 0(r1) and 4(r1)... */
61 /************************************************************************/
63 /************************************************************************/
67 .space 32*1024 // 32 K client stack
71 .space 64*1024 // 64 K stack
74 .space 32*1024 // 32 K exception stack
78 /************************************************************************/
80 /************************************************************************/
89 mtsprg0 r1 // setup exception stack
93 // copy exception vectors
95 addi r3,r3,LO(__vectors)
97 li r5,__vectors_end - __vectors + 16
124 /* According to IEEE 1275, PPC bindings:
126 * MSR = FP, ME + (DR|IR)
127 * r1 = stack (32 K + 32 bytes link area above)
128 * r5 = clint interface handler
129 * r6 = address of client program arguments (unused)
130 * r7 = length of client program arguments (unsed)
134 /* void call_elf( entry ) */
140 lis r8,HA(saved_stack)
141 addi r8,r8,LO(saved_stack) // save our stack pointer
143 lis r1,HA(client_stack)
144 addi r1,r1,LO(client_stack)
145 lis r5,HA(of_client_callback)
146 addi r5,r5,LO(of_client_callback) // r5 = callback
147 li r6,0 // r6 = address of client program arguments (unused)
148 li r7,0 // r7 = length of client program arguments (unused)
149 li r0,MSR_FP | MSR_ME | MSR_DR | MSR_IR
153 lis r8,HA(saved_stack)
154 addi r8,r8,LO(saved_stack) // restore stack pointer
159 // XXX: should restore r12-r31 etc..
160 // we should not really come here though
163 GLOBL(of_client_callback):
164 lis r4,HA(saved_stack)
165 addi r4,r4,LO(saved_stack)
170 stw r1,8(r4) // save caller stack
180 // do we need to save more registers?
181 bl of_client_interface
192 lwz r1,8(r1) // restore caller stack
195 /* rtas glue (must be reloctable) */
196 GLOBL(of_rtas_start):
197 /* r3 = argument buffer, r4 = of_rtas_start */
198 /* according to the CHRP standard, cr must be preserved (cr0/cr1 too?) */
200 lis r3,HA(OSI_SC_MAGIC_R3)
201 addi r3,r3,LO(OSI_SC_MAGIC_R3)
202 lis r4,HA(OSI_SC_MAGIC_R4)
203 addi r4,r4,LO(OSI_SC_MAGIC_R4)
210 /* used in a hack to the newworld calibration */
211 GLOBL(nw_dec_calibration):
213 GLOBL(timer_calib_start):
214 lis r3,HA(nw_dec_calibration)
215 addi r3,r3,LO(nw_dec_calibration)
218 GLOBL(timer_calib_end):
221 /************************************************************************/
223 /************************************************************************/
231 addi r1,r1,16 // pop ABI frame
242 lwz r0,0(r1) // restore r0
243 lwz r2,8(r1) // restore r2
244 lwz r3,12(r1) // restore r3
254 lwz r1,4(r1) // restore r1
261 ILLEGAL_VECTOR( 0x100 )
262 ILLEGAL_VECTOR( 0x200 )
264 VECTOR( 0x300, "DSI" ):
266 lis r3,HA(dsi_exception)
267 addi r3,r3,LO(dsi_exception)
272 VECTOR( 0x400, "ISI" ):
274 lis r3,HA(isi_exception)
275 addi r3,r3,LO(isi_exception)
280 ILLEGAL_VECTOR( 0x500 )
281 ILLEGAL_VECTOR( 0x600 )
282 ILLEGAL_VECTOR( 0x700 )
284 VECTOR( 0x800, "FPU" ):
292 ILLEGAL_VECTOR( 0x900 )
293 ILLEGAL_VECTOR( 0xa00 )
294 ILLEGAL_VECTOR( 0xb00 )
295 ILLEGAL_VECTOR( 0xc00 )
296 ILLEGAL_VECTOR( 0xd00 )
297 ILLEGAL_VECTOR( 0xe00 )
298 ILLEGAL_VECTOR( 0xf00 )
299 ILLEGAL_VECTOR( 0xf20 )
300 ILLEGAL_VECTOR( 0x1000 )
301 ILLEGAL_VECTOR( 0x1100 )
302 ILLEGAL_VECTOR( 0x1200 )
303 ILLEGAL_VECTOR( 0x1300 )
304 ILLEGAL_VECTOR( 0x1400 )
305 ILLEGAL_VECTOR( 0x1500 )
306 ILLEGAL_VECTOR( 0x1600 )
307 ILLEGAL_VECTOR( 0x1700 )
309 GLOBL(__vectors_end):
312 #define CACHE_LINE_SIZE 32
313 #define LG_CACHE_LINE_SIZE 5
315 /* flush_icache_range( unsigned long start, unsigned long stop) */
316 GLOBL(flush_icache_range):
317 li r5,CACHE_LINE_SIZE-1
321 srwi. r4,r4,LG_CACHE_LINE_SIZE
326 addi r3,r3,CACHE_LINE_SIZE
328 sync /* wait for dcbst's to get to ram */
331 addi r6,r6,CACHE_LINE_SIZE
333 sync /* additional sync needed on g4 */