1 /* Overlay manager for SPU.
3 Copyright 2006 Free Software Foundation, Inc.
5 This file is part of GLD, the Gnu Linker.
7 GLD 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 2, or (at your option)
12 GLD 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 GLD; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
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.
77 .extern _ovly_buf_table
82 .word 0x00010203, 0x1c1d1e1f, 0x00010203, 0x10111213
84 .word 0x04050607, 0x80808080, 0x80808080, 0x80808080
87 * __ovly_return - stub for returning from overlay functions.
93 * $78 old partition number, to be reloaded
94 * $79 return address in old partion number
97 .type __ovly_return, @function
106 * __ovly_load - copy an overlay partion to local store.
109 * $78 partition number to be loaded.
110 * $79 branch target in new partition.
111 * $lr link register, containing return addr.
114 * $lr new link register, returning through __ovly_return.
116 * Copy a new overlay partition into local store, or return
117 * immediately if the partition is already resident.
120 .type __ovly_load, @function
123 /* Save temporary registers to stack. */
129 /* Save irq state, then disable interrupts. */
131 ila irqtmp, __ovly_irq_save
132 rdch irq_stat, $SPU_RdMachStat
137 /* Set branch hint to overlay target. */
138 hbr __ovly_load_ret, $79
140 /* Get caller's overlay index by back chaining through stack frames.
141 * Loop until end of stack (back chain all-zeros) or
142 * encountered a link register we set here. */
144 ila retval, __ovly_return
146 __ovly_backchain_loop:
149 ceq cmp, lnkr, retval
152 brz cmp, __ovly_backchain_loop
154 /* If we reached the zero back-chain, then lnkr is bogus. Clear the
155 * part of lnkr that we use later (slot 3). */
156 rotqbyi cmp2, cmp2, 4
157 andc lnkr, lnkr, cmp2
159 /* Set lr = {__ovly_return, prev ovl ndx, caller return adr, callee ovl ndx}. */
160 lqd rv1, (__rv_pattern-__ovly_return+4)(retval)
161 shufb rv2, retval, lnkr, rv1
162 shufb rv3, $lr, $78, rv1
164 selb $lr, rv2, rv3, rv1
166 /* Branch to $79 if non-overlay */
167 brz $78, __ovly_load_restore
169 /* Load values from _ovly_table[$78].
178 ila tab, _ovly_table - 16
182 /* Load values from _ovly_buf_table[buf].
185 * } _ovly_buf_table[];
187 ila tab, _ovly_buf_table
193 /* Branch to $79 now if overlay is already mapped. */
195 brnz cmp, __ovly_load_restore
197 /* Set _ovly_buf_table[buf].mapped = $78. */
199 shufb map, $78, map, genwi
202 /* A new partition needs to be loaded. Prepare for DMA loop.
203 * _EAR_ is the 64b base EA, filled in at run time by the
204 * loader, and indicating the value for SPU executable image start.
206 lqd cgshuf, (__cg_pattern-__ovly_return+4)(retval)
212 /* 64b add to compute next ea64. */
213 rotqmbyi off64, sz, -4
214 cg cgbits, ea64, off64
215 shufb add64, cgbits, cgbits, cgshuf
216 addx add64, ea64, off64
219 /* Setup DMA parameters, then issue DMA request. */
220 rotqbyi ealo, add64, 4
221 ila maxsize, MFC_MAX_DMA_SIZE
222 cgt cmp, size, maxsize
223 selb sz, size, maxsize, cmp
224 ila tagid, MFC_TAG_ID
229 wrch $MFC_TagId, tagid
233 /* Increment vma, decrement size, branch back as needed. */
236 brnz size, __ovly_xfer_loop
238 /* Save app's tagmask, wait for DMA complete, restore mask. */
239 rdch oldmask, $MFC_RdTagMask
241 ilh newmask, 1 << MFC_TAG_ID
243 ilhu newmask, 1 << (MFC_TAG_ID - 16)
245 wrch $MFC_WrTagMask, newmask
246 ila tagstat, MFC_TAG_UPDATE_ALL
247 wrch $MFC_WrTagUpdate, tagstat
248 rdch tagstat, $MFC_RdTagStat
250 wrch $MFC_WrTagMask, oldmask
252 .global _ovly_debug_event
253 .type _ovly_debug_event, @function
255 /* GDB inserts debugger trap here. */
260 /* Conditionally re-enable interrupts. */
261 andi irq_stat, irq_stat, 1
262 ila irqtmp, __ovly_irq_restore
263 binze irq_stat, irqtmp
268 /* Restore saved registers. */
274 /* Branch to target address. */