source: trunk/libs/newlib/src/libgloss/epiphany/epiphany-ivthandlers.S @ 588

Last change on this file since 588 was 444, checked in by satin@…, 7 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 5.2 KB
RevLine 
[444]1# EPIPHANY implementation of wrappers over user C ISR ()
2
3# Copyright (c) 2011, Adapteva, Inc.
4# All rights reserved.
5
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are met:
8#  * Redistributions of source code must retain the above copyright notice,
9#    this list of conditions and the following disclaimer.
10#  * Redistributions in binary form must reproduce the above copyright
11#    notice, this list of conditions and the following disclaimer in the
12#    documentation and/or other materials provided with the distribution.
13#  * Neither the name of Adapteva nor the names of its contributors may be
14#    used to endorse or promote products derived from this software without
15#    specific prior written permission.
16
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27# POSSIBILITY OF SUCH DAMAGE.
28
29.section RESERVED_CRT0,"a",@progbits     ;
30.set sw_exception_v_n, 1
31.set page_miss_v_n, 2
32.set timer0_expired_v_n, 3;
33.set timer1_expired_v_n, 4;
34.set message_v_n, 5;
35.set dma0_v_n, 6;
36.set dma1_v_n, 7;
37.set wand_v_n, 8;
38.set soft_v_n, 9
39
40// preserve isr-mods to ACTIVE, GID, KERNEL, WAND, & EXCAUSE bits in the status reg
41.set status_mask, 0x0007000f;
42// for the wand isr, preserve isr-mods to ACTIVE, GID, KERNEL, & EXCAUSE, but
43// clear the WAND bit.
44.set wand_status_mask, 0x00070007;
45
46//IVT wrappers
47
48.global _DEFAULT_ISR_CALLBACK;
49.balign 4
50.type   _DEFAULT_ISR_CALLBACK, %function
51_DEFAULT_ISR_CALLBACK:
52        rts
53.size  _DEFAULT_ISR_CALLBACK, .-_DEFAULT_ISR_CALLBACK
54
55
56.global _DEFAULT_ISR_CALLBACK_FOR_sw_exception_v;
57.balign 4
58.type   _DEFAULT_ISR_CALLBACK_FOR_sw_exception_v, %function
59_DEFAULT_ISR_CALLBACK_FOR_sw_exception_v:
60        trap 5;; FAIL
61.size  _DEFAULT_ISR_CALLBACK_FOR_sw_exception_v, .-_DEFAULT_ISR_CALLBACK_FOR_sw_exception_v
62
63
64.set NUMBER_ENTRIES_IN_IVT, 8
65.global _ISR_VECTOR;
66.balign 4
67.type   _ISR_VECTOR, %object
68_ISR_VECTOR:
69        .word _DEFAULT_ISR_CALLBACK_FOR_sw_exception_v; reset
70        .word _DEFAULT_ISR_CALLBACK_FOR_sw_exception_v; sw_exception
71        .word _DEFAULT_ISR_CALLBACK_FOR_sw_exception_v; page_miss
72        .rept   NUMBER_ENTRIES_IN_IVT
73                .word _DEFAULT_ISR_CALLBACK
74        .endr
75.size  _ISR_VECTOR, .-_ISR_VECTOR
76
77.macro IVT_ENTRY_CALL entry_v_
78        ;; assuming we have valid frame poiter
79
80        str fp, [sp],-0x10
81        str r0, [sp,+0xf]
82        str r1, [sp,+0xe]
83        mov r0, \entry_v_
84.if \entry_v_ == wand_v_n
85        mov   r1, %low(wand_status_mask)  ; this mask will exclude WAND, so it will
86        movt  r1, %high(wand_status_mask) ; be forcibly cleared
87.else
88        mov   r1, %low(status_mask)
89        movt  r1, %high(status_mask)
90.endif
91        str r1, [sp,0x9] ; save the status register isr-preserve mask on the stack
92        b   __dispatcher
93.endm
94
95.global __dispatcher;
96.balign 4
97.type   __dispatcher, %function
98__dispatcher:
99        str lr, [sp,+0xd]
100        movfs.l r1,status
101        str r1, [sp,+0xc]
102        movfs.l r1,iret
103        str r1, [sp,+0xb]
104        str r2, [sp,+0xa]
105        str r3, [sp,+0x8]
106
107        mov fp,sp
108
109        //TODO allow nesting
110        //gie
111
112        lsl r2, r0, 2
113        mov     r1, %low(_ISR_VECTOR)
114        add r2, r2, r1
115        ldr r1, [r2,0] ;; r1 = _ISR_VECTOR[entry_v]
116        mov r2, 3
117        add r0, r0, r2 ;; r0 = signum
118        jalr r1
119
120        mov sp,fp
121
122        //gid
123
124        // preserve isr-modifications to some of the bits in the status register,
125        // but restore the rest to pre-interrupt values.
126        // status = (status[post_isr] & status_mask) | (status[pre_isr] & ~status_mask)
127
128        ldr.l r2, [sp, 9] ; fetch the status register isr preserve mask from the stack
129        movfs r1, status
130        and   r1, r1, r2; (status[post_isr] & status_mask)
131
132        ldr  r0, [sp,+0xc]
133        mov  r2, %low(~status_mask)
134        movt r2, %high(~status_mask)
135        and  r0, r0, r2; (status[pre_isr] & ~status_mask)
136
137        orr r0, r0, r1 ; combine pre_isr & post_isr status bits
138        movts.l status, r0
139
140        ldr r0, [sp,+0xb]
141        movts.l iret,r0
142
143        ldr  lr,[sp,+0xd];
144        ldr  r1,[sp,+0xe]
145        ldr  r0,[sp,+0xf]
146        ldr  r2,[sp,+0xa]
147        ldr  r3,[sp,+0x8]
148        ldr  fp,[sp],+0x10
149        ldr  fp,[sp,0]
150        rti
151.size  __dispatcher, .-__dispatcher
152
153
154.global .sw_exception_v;
155.type   .sw_exception_v, %function
156.sw_exception_v:
157        IVT_ENTRY_CALL sw_exception_v_n;
158.size  .sw_exception_v, .-.sw_exception_v
159
160.global .page_miss_v;
161.type   .page_miss_v, %function
162.page_miss_v:
163        IVT_ENTRY_CALL page_miss_v_n;
164.size  .page_miss_v, .-.page_miss_v
165
166.global .timer0_expired_v;
167.timer0_expired_v:
168        IVT_ENTRY_CALL timer0_expired_v_n;
169
170.global .timer1_expired_v;
171.timer1_expired_v:
172        IVT_ENTRY_CALL timer1_expired_v_n;
173
174.global .message_v;
175.message_v:
176        IVT_ENTRY_CALL message_v_n;
177
178.global .dma0_v;
179.dma0_v:
180        IVT_ENTRY_CALL dma0_v_n;
181
182.global .dma1_v;
183.dma1_v:
184        IVT_ENTRY_CALL dma1_v_n;
185
186.global .wand_v;
187.wand_v:
188        IVT_ENTRY_CALL wand_v_n;
189
190.global .soft_v;
191.soft_v:
192        IVT_ENTRY_CALL soft_v_n;
Note: See TracBrowser for help on using the repository browser.