summaryrefslogtreecommitdiffstats
path: root/bsps/epiphany/epiphany_sim/start/start.S
blob: c79d23dc86940b7bacc200fccf3206eca73bcc95 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
 * Copyright (c) 2015 University of York.
 * Hesham ALMatary <hmka501@york.ac.uk>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */
#include <bsp/linker-symbols.h>
#include <rtems/asm.h>

EXTERN(bsp_section_bss_begin)
EXTERN(bsp_section_bss_end)
EXTERN(_ISR_Handler)
EXTERN(bsp_start_vector_table_end)
EXTERN(bsp_start_vector_table_size)
EXTERN(bsp_vector_table_size)
EXTERN(_ISR_Stack_area_end)

PUBLIC(_EPIPHANY_Exception_default)
PUBLIC(bsp_start_vector_table_begin)
PUBLIC(_start)

.section .vector, "wax"
TYPE_FUNC(_start)
SYM(_start):
  .balign 4 ;
    b .normal_start

  .balign 4 ; 0x4
    b .sw_exception

  .balign 4 ; 0x8
    b .normal_start

  .balign 4 ; 0xc
    b .clock_isr

  .balign 4 ; 0x10
    b .timer1_isr

  .balign 4 ; 0x14
    b _EPIPHANY_Exception_default

  .balign 4 ; 0x18
    b _EPIPHANY_Exception_default

  .balign 4 ; 0x1c
    b _EPIPHANY_Exception_default

  .balign 4 ; 0x20
    b _EPIPHANY_Exception_default

  .balign 4 ; 0x24
    b _EPIPHANY_Exception_default

bsp_start_vector_table_begin:
  .word .normal_start /* Reset */
  .word _EPIPHANY_Exception_default /* SW exception */
  .word _EPIPHANY_Exception_default /* Data Page Fault */
  .word _EPIPHANY_Exception_default /* Timer 0 */
  .word _EPIPHANY_Exception_default /* Timer 1 */
  .word _EPIPHANY_Exception_default /* Message int */
  .word _EPIPHANY_Exception_default /* DMA0 int */
  .word _EPIPHANY_Exception_default /* DMA1 int */
  .word _EPIPHANY_Exception_default /* WAND */
  .word _EPIPHANY_Exception_default /* User interrupt */

_bsp_start_vector_table_end:

.size  _start, .-_start

.section .start,"ax"
.align  4
.type   _external_start, %function
.normal_start:
  /* Initialize the stack and frame pointers */
  mov  sp, %low(_ISR_Stack_area_end)
  movt sp, %high(_ISR_Stack_area_end)
  mov  fp, sp

cpu0:
  /* Zero .bss section */
  mov  r0, %low(bsp_section_bss_begin)
  movt r0, %high(bsp_section_bss_begin)
  mov  r1, sp
  mov  r2,#0
  mov  r3,#0

_bss_clear_loop:
  strd  r2, [r0], +#1
  sub   r5, r1, r0
  bne   _bss_clear_loop

  /* Clear the reset interrupt flag */
  mov   r0, %low(_jump_to_c)
  movt  r0, %high(_jump_to_c)
  movts iret, r0
  rti

_jump_to_c:
  /* Jump to bootcard */
  mov  r3, %low(boot_card)
  movt r3, %high(boot_card)
  jalr r3

 /* Should never reach here */
 idle

.size  .normal_start, .-.normal_start

.balign 4
.type   .sw_exception, %function
.sw_exception:
  idle

.balign 4
.type   .clock_isr, %function
.clock_isr:
  /*
   * r62 and r63 are saved here, and restored from _ISR_Handler, they
   * and hold vector number and _ISR_Handler address repsectively.
   */
  add  sp, sp, #-8
  str  r62, [sp, #0]
  str  r63, [sp, #4]
  mov  r62, 3
  mov  r63, %low(_ISR_Handler)
  movt r63, %high(_ISR_Handler)
  jr   r6

.balign 4
.type   .timer1_isr, %function
.timer1_isr:
  /*
   * r62 and r63 are saved here, and restored from _ISR_Handler, they
   * and hold vector number and _ISR_Handler address repsectively.
   */
  add  sp, sp, #-8
  str  r62, [sp, 0]
  str  r63, [sp, 4]
  mov  r62, 4
  mov  r63, %low(_ISR_Handler)
  movt r63, %high(_ISR_Handler)
  jr   r63

.balign 4
TYPE_FUNC(_EPIPHANY_Exception_default)
SYM(_EPIPHANY_Exception_default):
  idle