]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgcc/config/nios2/tramp.c
Update copyright years.
[thirdparty/gcc.git] / libgcc / config / nios2 / tramp.c
CommitLineData
8d9254fc 1/* Copyright (C) 2013-2020 Free Software Foundation, Inc.
e430824f
CLT
2 Contributed by Altera and Mentor Graphics, Inc.
3
4This file is free software; you can redistribute it and/or modify it
5under the terms of the GNU General Public License as published by the
6Free Software Foundation; either version 3, or (at your option) any
7later version.
8
9This file is distributed in the hope that it will be useful, but
10WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12General Public License for more details.
13
14Under Section 7 of GPL version 3, you are granted additional
15permissions described in the GCC Runtime Library Exception, version
163.1, as published by the Free Software Foundation.
17
18You should have received a copy of the GNU General Public License and
19a copy of the GCC Runtime Library Exception along with this program;
20see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
21<http://www.gnu.org/licenses/>. */
22
23/* Set up trampolines.
24 R12 is the static chain register.
25 R2 is AT, the assembler temporary.
26 The trampoline code looks like:
27 movhi r12,%hi(chain)
28 ori r12,%lo(chain)
29 movhi r2,%hi(fn)
30 ori r2,%lo(fn)
31 jmp r2
32*/
33
34#define SC_REGNO 12
35
a03c6ae3
SL
36/* Instruction encodings depend on the ISA level. */
37#if __nios2_arch__ == 2
38#define MOVHI(reg,imm16) \
39 (((reg) << 11) | ((imm16) << 16) | 0x34)
40#define ORI(reg,imm16) \
41 (((reg) << 11) | ((reg) << 6) | ((imm16) << 16) | 0x14)
42#define JMP(reg) \
43 (((reg) << 6) | (0x0d << 26) | 0x20)
44
45#elif __nios2_arch__ == 1
46#define MOVHI(reg,imm16) \
e430824f 47 (((reg) << 22) | ((imm16) << 6) | 0x34)
a03c6ae3 48#define ORI(reg,imm16) \
e430824f 49 (((reg) << 27) | ((reg) << 22) | ((imm16) << 6) | 0x14)
a03c6ae3 50#define JMP(reg) \
e430824f
CLT
51 (((reg) << 27) | (0x0d << 11) | 0x3a)
52
a03c6ae3
SL
53#else
54#error "Unknown Nios II architecture level"
55#endif
56
e430824f
CLT
57void
58__trampoline_setup (unsigned int *addr, void *fnptr, void *chainptr)
59{
60 unsigned int fn = (unsigned int) fnptr;
61 unsigned int chain = (unsigned int) chainptr;
62 int i;
63
64 addr[0] = MOVHI (SC_REGNO, ((chain >> 16) & 0xffff));
65 addr[1] = ORI (SC_REGNO, (chain & 0xffff));
66 addr[2] = MOVHI (2, ((fn >> 16) & 0xffff));
67 addr[3] = ORI (2, (fn & 0xffff));
68 addr[4] = JMP (2);
69
70 /* Flush the caches.
71 See Example 9-4 in the Nios II Software Developer's Handbook. */
72 for (i = 0; i < 5; i++)
73 asm volatile ("flushd 0(%0); flushi %0" :: "r"(addr + i) : "memory");
74 asm volatile ("flushp" ::: "memory");
75}