1 /* Overlay manager for SPU.
3 Copyright 2006, 2007 Free Software Foundation, Inc.
5 This file is part of the GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
25 #define MFC_GET_CMD 0x40
26 #define MFC_MAX_DMA_SIZE 0x4000
27 #define MFC_TAG_UPDATE_ALL 2
32 * Temporary register allocations.
33 * These are saved/restored here.
76 # Stack quadword minux N
95 .extern _ovly_buf_table
98 #define SPE_C99_VPRINTF 37
100 .string "In entry_event_hook segment=0x%08x entry-address=0x%08x\n"
101 __debug_event_format:
102 .string "In debug_event_hook link-register=0x%08x %08x %08x %08x\n"
104 .string "In dma_event_hook vma=0x%08x ea=%08x%08x sz=%08x\n"
105 __ovly_buf_table_format:
106 .string "_ovly_buf_table[%08x]=%08x\n"
111 .type __rv_pattern, @object
112 .size __rv_pattern, 16
114 .word 0x00010203, 0x1c1d1e1f, 0x00010203, 0x10111213
115 .type __cg_pattern, @object
116 .size __cg_pattern, 16
118 .word 0x04050607, 0x80808080, 0x80808080, 0x80808080
121 * __ovly_return - stub for returning from overlay functions.
127 * $78 old partition number, to be reloaded
128 * $79 return address in old partion number
130 .global __ovly_return
131 .type __ovly_return, @function
138 .size __ovly_return, . - __ovly_return
141 * __ovly_load - copy an overlay partion to local store.
144 * $78 partition number to be loaded.
145 * $79 branch target in new partition.
146 * $lr link register, containing return addr.
149 * $lr new link register, returning through __ovly_return.
151 * Copy a new overlay partition into local store, or return
152 * immediately if the partition is already resident.
155 .type __ovly_load, @function
158 /* Save temporary registers to stack. */
164 /* Save irq state, then disable interrupts. */
166 ila irqtmp, __ovly_irq_save
167 rdch irq_stat, $SPU_RdMachStat
173 //==============================================
174 // In entry_event_hook segment=0x%08x entry-address=0x%08x
175 //==============================================
180 # Place input parameters onto the stack to form the
181 # local storage memory image.
182 ila $10, __entry_event_format
183 stqd $10, SQWM12($sp)
185 stqd $10, SQWM11($sp)
186 stqd $sp, SQWM10($sp)
189 # Construct a message consisting of the 8-bit opcode
190 # and 24-bit local store pointer to the input
191 # parameters and place it forllowing the stop and signal
192 ila $10, 0x3ffff # address mask
193 ilhu $11, SPE_C99_VPRINTF << 8
194 ai $12, $sp, SQWM12 # parameter pointer
195 selb $11, $11, $12, $10 # combine command & address ptr
198 .type next1a, @function
200 cwd $10, message1a-next1a($10)
201 shufb $11, $11, $12, $10 # insert msg into inst word
202 stqr $11, message1a # store cmd/ptr into msg word
204 # Notify the PPE to perform the assisted call request
205 # by issing a stop and signal with a signal code
206 # of 0x2100 (C99 class)
214 stqd $15, SQWM10($sp)
215 stqd $16, SQWM11($sp)
219 ila $14, _ovly_buf_table
220 ila $15, _ovly_buf_table_end
223 # Place input parameters onto the stack to form the
224 # local storage memory image.
225 ila $10, __ovly_buf_table_format
226 stqd $10, SQWM16($sp)
228 stqd $10, SQWM15($sp)
229 stqd $sp, SQWM14($sp)
230 stqd $13, SQWM13($sp)
233 stqd $16, SQWM12($sp)
234 # Construct a message consisting of the 8-bit opcode
235 # and 24-bit local store pointer to the input
236 # parameters and place it forllowing the stop and signal
237 ila $10, 0x3ffff # address mask
238 ilhu $11, SPE_C99_VPRINTF << 8
239 ai $12, $sp, SQWM16 # parameter pointer
240 selb $11, $11, $12, $10 # combine command & address ptr
243 .type next1b, @function
245 cwd $10, message1b-next1b($10)
246 shufb $11, $11, $12, $10 # insert msg into inst word
247 stqr $11, message1b # store cmd/ptr into msg word
249 # Notify the PPE to perform the assisted call request
250 # by issing a stop and signal with a signal code
251 # of 0x2100 (C99 class)
260 brnz $16, loop_start1
270 //==============================================
273 /* Set branch hint to overlay target. */
274 hbr __ovly_load_ret, $79
276 /* Get caller's overlay index by back chaining through stack frames.
277 * Loop until end of stack (back chain all-zeros) or
278 * encountered a link register we set here. */
280 ila retval, __ovly_return
282 __ovly_backchain_loop:
285 ceq cmp, lnkr, retval
288 brz cmp, __ovly_backchain_loop
290 /* If we reached the zero back-chain, then lnkr is bogus. Clear the
291 * part of lnkr that we use later (slot 3). */
292 rotqbyi cmp2, cmp2, 4
293 andc lnkr, lnkr, cmp2
295 /* Set lr = {__ovly_return, prev ovl ndx, caller return adr, callee ovl ndx}. */
296 lqd rv1, (__rv_pattern-__ovly_return+4)(retval)
297 shufb rv2, retval, lnkr, rv1
298 shufb rv3, $lr, $78, rv1
300 selb rv2, rv2, rv3, rv1
301 /* If we have a tail call from one overlay function to another overlay,
302 then lr is already set up. Don't change it. */
305 selb $lr, rv2, $lr, rv1
307 /* Branch to $79 if non-overlay */
308 brz $78, __ovly_load_restore
310 /* Load values from _ovly_table[$78].
319 ila tab, _ovly_table - 16
323 /* Load values from _ovly_buf_table[buf].
326 * } _ovly_buf_table[];
328 ila tab, _ovly_buf_table
334 /* Branch to $79 now if overlay is already mapped. */
336 brnz cmp, __ovly_load_restore
338 /* Marker for profiling code. If we get here, we are about to load
341 .global __ovly_load_event
342 .type __ovly_load_event, @function
345 /* Set _ovly_buf_table[buf].mapped = $78. */
347 shufb map, $78, map, genwi
350 /* A new partition needs to be loaded. Prepare for DMA loop.
351 * _EAR_ is the 64b base EA, filled in at run time by the
352 * loader, and indicating the value for SPU executable image start.
354 lqd cgshuf, (__cg_pattern-__ovly_return+4)(retval)
355 rotqbyi osize, vma, 4
360 /* 64b add to compute next ea64. */
361 rotqmbyi off64, sz, -4
362 cg cgbits, ea64, off64
363 shufb add64, cgbits, cgbits, cgshuf
364 addx add64, ea64, off64
367 /* Setup DMA parameters, then issue DMA request. */
368 rotqbyi ealo, add64, 4
369 ila maxsize, MFC_MAX_DMA_SIZE
370 cgt cmp, osize, maxsize
371 selb sz, osize, maxsize, cmp
372 ila tagid, MFC_TAG_ID
377 wrch $MFC_TagId, tagid
382 //==============================================
383 // In dma_event_hook vma=0x%08x ea=%08x%08x sz=%08x
384 //==============================================
389 # Place input parameters onto the stack to form the
390 # local storage memory image.
391 ila $10, __dma_event_format
392 stqd $10, SQWM14($sp)
394 stqd $10, SQWM13($sp)
395 stqd $sp, SQWM12($sp)
396 stqd vma, SQWM11($sp)
397 stqd ea64, SQWM10($sp)
398 stqd ealo, SQWM9($sp)
400 # Construct a message consisting of the 8-bit opcode
401 # and 24-bit local store pointer to the input
402 # parameters and place it forllowing the stop and signal
403 ila $10, 0x3ffff # address mask
404 ilhu $11, SPE_C99_VPRINTF << 8
405 ai $12, $sp, SQWM14 # parameter pointer
406 selb $11, $11, $12, $10 # combine command & address ptr
409 .type next3a, @function
411 cwd $10, message3a-next3a($10)
412 shufb $11, $11, $12, $10 # insert msg into inst word
413 stqr $11, message3a # store cmd/ptr into msg word
415 # Notify the PPE to perform the assisted call request
416 # by issing a stop and signal with a signal code
417 # of 0x2100 (C99 class)
426 //==============================================
429 /* Increment vma, decrement size, branch back as needed. */
432 brnz osize, __ovly_xfer_loop
434 /* Save app's tagmask, wait for DMA complete, restore mask. */
435 rdch oldmask, $MFC_RdTagMask
437 ilh newmask, 1 << MFC_TAG_ID
439 ilhu newmask, 1 << (MFC_TAG_ID - 16)
441 wrch $MFC_WrTagMask, newmask
442 ila tagstat, MFC_TAG_UPDATE_ALL
443 wrch $MFC_WrTagUpdate, tagstat
444 rdch tagstat, $MFC_RdTagStat
446 wrch $MFC_WrTagMask, oldmask
449 //==============================================
450 // In debug_event_hook link-register=0x%08x %08x %08x %08x
451 //==============================================
456 # Place input parameters onto the stack to form the
457 # local storage memory image.
458 ila $10, __debug_event_format
459 stqd $10, SQWM14($sp)
461 stqd $10, SQWM13($sp)
462 stqd $sp, SQWM12($sp)
463 stqd $lr, SQWM11($sp)
465 stqd $10, SQWM10($sp)
470 # Construct a message consisting of the 8-bit opcode
471 # and 24-bit local store pointer to the input
472 # parameters and place it forllowing the stop and signal
473 ila $10, 0x3ffff # address mask
474 ilhu $11, SPE_C99_VPRINTF << 8
475 ai $12, $sp, SQWM14 # parameter pointer
476 selb $11, $11, $12, $10 # combine command & address ptr
479 .type next2a, @function
481 cwd $10, message2a-next2a($10)
482 shufb $11, $11, $12, $10 # insert msg into inst word
483 stqr $11, message2a # store cmd/ptr into msg word
485 # Notify the PPE to perform the assisted call request
486 # by issing a stop and signal with a signal code
487 # of 0x2100 (C99 class)
495 stqd $15, SQWM10($sp)
496 stqd $16, SQWM11($sp)
500 ila $14, _ovly_buf_table
501 ila $15, _ovly_buf_table_end
504 # Place input parameters onto the stack to form the
505 # local storage memory image.
506 ila $10, __ovly_buf_table_format
507 stqd $10, SQWM16($sp)
509 stqd $10, SQWM15($sp)
510 stqd $sp, SQWM14($sp)
511 stqd $13, SQWM13($sp)
514 stqd $16, SQWM12($sp)
515 # Construct a message consisting of the 8-bit opcode
516 # and 24-bit local store pointer to the input
517 # parameters and place it forllowing the stop and signal
518 ila $10, 0x3ffff # address mask
519 ilhu $11, SPE_C99_VPRINTF << 8
520 ai $12, $sp, SQWM16 # parameter pointer
521 selb $11, $11, $12, $10 # combine command & address ptr
524 .type next2b, @function
526 cwd $10, message2b-next2b($10)
527 shufb $11, $11, $12, $10 # insert msg into inst word
528 stqr $11, message2b # store cmd/ptr into msg word
530 # Notify the PPE to perform the assisted call request
531 # by issing a stop and signal with a signal code
532 # of 0x2100 (C99 class)
541 brnz $16, loop_start2
551 //==============================================
554 .global _ovly_debug_event
555 .type _ovly_debug_event, @function
557 /* GDB inserts debugger trap here. */
562 /* Conditionally re-enable interrupts. */
563 andi irq_stat, irq_stat, 1
564 ila irqtmp, __ovly_irq_restore
565 binze irq_stat, irqtmp
570 /* Restore saved registers. */
576 /* Branch to target address. */
579 .size __ovly_load, . - __ovly_load