trampoline.S revision 1.1 1 1.1 mrg /* libgcc routines for RL78
2 1.1 mrg Copyright (C) 2011-2013 Free Software Foundation, Inc.
3 1.1 mrg Contributed by Red Hat.
4 1.1 mrg
5 1.1 mrg This file is part of GCC.
6 1.1 mrg
7 1.1 mrg GCC is free software; you can redistribute it and/or modify it
8 1.1 mrg under the terms of the GNU General Public License as published
9 1.1 mrg by the Free Software Foundation; either version 3, or (at your
10 1.1 mrg option) any later version.
11 1.1 mrg
12 1.1 mrg GCC is distributed in the hope that it will be useful, but WITHOUT
13 1.1 mrg ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 1.1 mrg or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 1.1 mrg License for more details.
16 1.1 mrg
17 1.1 mrg Under Section 7 of GPL version 3, you are granted additional
18 1.1 mrg permissions described in the GCC Runtime Library Exception, version
19 1.1 mrg 3.1, as published by the Free Software Foundation.
20 1.1 mrg
21 1.1 mrg You should have received a copy of the GNU General Public License and
22 1.1 mrg a copy of the GCC Runtime Library Exception along with this program;
23 1.1 mrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 1.1 mrg <http://www.gnu.org/licenses/>. */
25 1.1 mrg
26 1.1 mrg /* RL78 Trampoline support
27 1.1 mrg
28 1.1 mrg Since the RL78's RAM is not in the first 64k, we cannot "just" use a
29 1.1 mrg function pointer to point to a trampoline on the stack. So, we
30 1.1 mrg create N fixed trampolines that read from an array, and allocate
31 1.1 mrg them as needed.
32 1.1 mrg
33 1.1 mrg */
34 1.1 mrg
35 1.1 mrg r8 = 0xffef0
36 1.1 mrg r10 = 0xffef2
37 1.1 mrg r14 = 0xffef6
38 1.1 mrg
39 1.1 mrg .data
40 1.1 mrg .p2align 1
41 1.1 mrg trampoline_array:
42 1.1 mrg
43 1.1 mrg .macro stub n
44 1.1 mrg
45 1.1 mrg .text
46 1.1 mrg trampoline_\n:
47 1.1 mrg .type trampoline_\n, @function
48 1.1 mrg movw ax, !trampoline_chain_\n
49 1.1 mrg movw r14, ax
50 1.1 mrg movw ax, !trampoline_addr_\n
51 1.1 mrg br ax
52 1.1 mrg .size trampoline_\n, .-trampoline_\n
53 1.1 mrg
54 1.1 mrg .data
55 1.1 mrg trampoline_frame_\n:
56 1.1 mrg .short 0
57 1.1 mrg trampoline_stub_\n:
58 1.1 mrg .short trampoline_\n
59 1.1 mrg trampoline_chain_\n:
60 1.1 mrg .short 0
61 1.1 mrg trampoline_addr_\n:
62 1.1 mrg .short 0
63 1.1 mrg
64 1.1 mrg #define TO_FRAME 0
65 1.1 mrg #define TO_STUB 2
66 1.1 mrg #define TO_CHAIN 4
67 1.1 mrg #define TO_ADDR 6
68 1.1 mrg #define TO_SIZE 8
69 1.1 mrg
70 1.1 mrg .endm
71 1.1 mrg
72 1.1 mrg stub 0
73 1.1 mrg stub 1
74 1.1 mrg stub 2
75 1.1 mrg stub 3
76 1.1 mrg stub 4
77 1.1 mrg stub 5
78 1.1 mrg
79 1.1 mrg trampoline_array_end:
80 1.1 mrg
81 1.1 mrg /* Given the function pointer in R8 and the static chain
82 1.1 mrg pointer in R10, allocate a trampoline and return its address in
83 1.1 mrg R8. */
84 1.1 mrg
85 1.1 mrg .text
86 1.1 mrg .global ___trampoline_init
87 1.1 mrg .type ___trampoline_init, @function
88 1.1 mrg ___trampoline_init:
89 1.1 mrg
90 1.1 mrg movw hl, #trampoline_array
91 1.1 mrg 1:
92 1.1 mrg movw ax, [hl + TO_ADDR]
93 1.1 mrg cmpw ax, #0
94 1.1 mrg bz $2f
95 1.1 mrg
96 1.1 mrg movw ax, hl
97 1.1 mrg addw ax, #TO_SIZE
98 1.1 mrg movw hl, ax
99 1.1 mrg cmpw ax, #trampoline_array_end
100 1.1 mrg bnz $1b
101 1.1 mrg brk ; no more slots?
102 1.1 mrg
103 1.1 mrg 2: movw ax, r8
104 1.1 mrg movw [hl + TO_ADDR], ax
105 1.1 mrg movw ax, r10
106 1.1 mrg movw [hl + TO_CHAIN], ax
107 1.1 mrg movw ax, sp
108 1.1 mrg movw [hl + TO_FRAME], ax
109 1.1 mrg
110 1.1 mrg movw ax, [hl + TO_STUB]
111 1.1 mrg movw r8, ax
112 1.1 mrg
113 1.1 mrg ret
114 1.1 mrg .size ___trampoline_init, . - ___trampoline_init
115 1.1 mrg
116 1.1 mrg .global ___trampoline_uninit
117 1.1 mrg .type ___trampoline_uninit, @function
118 1.1 mrg ___trampoline_uninit:
119 1.1 mrg movw hl, #trampoline_array
120 1.1 mrg movw ax, sp
121 1.1 mrg movw bc, ax
122 1.1 mrg 1:
123 1.1 mrg movw ax, [hl + TO_FRAME]
124 1.1 mrg cmpw ax, bc
125 1.1 mrg bc $2f
126 1.1 mrg
127 1.1 mrg clrw ax
128 1.1 mrg movw [hl + TO_ADDR], ax
129 1.1 mrg
130 1.1 mrg 2:
131 1.1 mrg movw ax, hl
132 1.1 mrg addw ax, #TO_SIZE
133 1.1 mrg movw hl, ax
134 1.1 mrg cmpw ax, #trampoline_array_end
135 1.1 mrg bnz $1b
136 1.1 mrg
137 1.1 mrg ret
138 1.1 mrg .size ___trampoline_uninit, . - ___trampoline_uninit
139