1 /* Copyright (C) 2013-2015 Free Software Foundation, Inc.
2 Contributed by Altera and Mentor Graphics, Inc.
4 This file is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 3, or (at your option) any
9 This file is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 Under Section 7 of GPL version 3, you are granted additional
15 permissions described in the GCC Runtime Library Exception, version
16 3.1, as published by the Free Software Foundation.
18 You should have received a copy of the GNU General Public License and
19 a copy of the GCC Runtime Library Exception along with this program;
20 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
21 <http://www.gnu.org/licenses/>. */
23 /* Set up trampolines.
24 R12 is the static chain register.
25 R2 is AT, the assembler temporary.
26 The trampoline code looks like:
36 #define MOVHI(reg,imm16) \
37 (((reg) << 22) | ((imm16) << 6) | 0x34)
38 #define ORI(reg,imm16) \
39 (((reg) << 27) | ((reg) << 22) | ((imm16) << 6) | 0x14)
41 (((reg) << 27) | (0x0d << 11) | 0x3a)
44 __trampoline_setup (unsigned int *addr
, void *fnptr
, void *chainptr
)
46 unsigned int fn
= (unsigned int) fnptr
;
47 unsigned int chain
= (unsigned int) chainptr
;
50 addr
[0] = MOVHI (SC_REGNO
, ((chain
>> 16) & 0xffff));
51 addr
[1] = ORI (SC_REGNO
, (chain
& 0xffff));
52 addr
[2] = MOVHI (2, ((fn
>> 16) & 0xffff));
53 addr
[3] = ORI (2, (fn
& 0xffff));
57 See Example 9-4 in the Nios II Software Developer's Handbook. */
58 for (i
= 0; i
< 5; i
++)
59 asm volatile ("flushd 0(%0); flushi %0" :: "r"(addr
+ i
) : "memory");
60 asm volatile ("flushp" ::: "memory");