aboutsummaryrefslogtreecommitdiff
path: root/test12.S
blob: ad9af70d6f7aaa3597d115f97c3e6e2a5f241194 (plain)
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
168
169
170
171
172
173
174
175
176
177
178
.thumb
.syntax unified

.section .text.start
.global _boot_reset
.align 7
_boot_reset:
.word _main_stack_top
.word _start /* reset */
.word _vec_stuck
.word _vec_HF
.word _vec_stuck
.word _vec_stuck
.word _vec_UF
.word _vec_stuck
.word _vec_stuck
.word _vec_stuck
.word _vec_stuck
.word _vec_SVC
.word _vec_stuck
.word _vec_stuck
.word _vec_stuck
.word _vec_stuck

.section .text

.global _start
.thumb_func
_start:
  /* zero bss */
  mov r0, #0
  ldr r1, =__bss_start
  ldr r2, =__bss_end

_bss_loop:
  cmp r1, r2
  itt ne
  strbne r0, [r1], 1
  bne _bss_loop

  /* copy data */
  ldr r1, =__data_start
  ldr r2, =__data_end
  ldr r3, =__data_load

_data_loop:
  cmp r1, r2
  ittt ne
  ldrbne r0, [r3], 1
  strbne r0, [r1], 1
  bne _data_loop

  ldr r1, =0xe000e000
  ldr r0, =0x00070000
  str r0, [r1, #0xd24]

  ldr r0, =0x80000000
  str r0, [r1, #0xd1c]

  blx board_setup

  ldr r0, =in_main
  blx puts

  cpsie if

  svc 42

.global abort
.thumb_func
abort:
  ldr sp, =_main_stack_top

  ldr r0, =0x05fa0004 /* reset request */
  ldr r1, =0xe000e000
  str r0, [r1, #0xd0c] /* AIRCR */
  dsb

_stuck:
  b _stuck

.global putc
.thumb_func
putc:
  ldr r1, =0x4000c000

  cmp r0, #'\n'
  bne putc_loop
  push {r0-r2,lr}
  mov r0, #'\r'
  blx putc
  pop {r0-r2,lr}

putc_loop:
  ldr r2, [r1, 0x18]
  tst r2, #0x20
  bne putc_loop

  strb r0, [r1]
  bx lr

.global puts
.thumb_func
puts:
  push {lr}
  mov r3, r0
puts_loop:
  ldrb r0, [r3], #1
  cmp r0, #0
  it eq
  popeq {pc}
  blx putc
  b puts_loop

.thumb_func
_vec_stuck:
  mov r0, #'S'
  ldr r1, =0x4000c000
  strb r0, [r1]
  mrs r0, IPSR
  strb r0, [r1]
  bl abort

.thumb_func
_vec_HF:
  ldr r0, =bad_HF
  blx puts
  b abort

.thumb_func
_vec_UF:
  /* Need to check CFSR to see if we got the right kind of fault */
  ldr r1, =0xe000e000
  ldr r0, [r1, #0xd28]
  tst r0, 0x00020000
  bne uf_invstate
  cmp r0, 0
  beq uf_no_cfsr
  ldr r0, =in_UF_wrong_fs
  blx puts
  b abort
uf_invstate:
  ldr r0, =in_UF_invstate
  blx puts
  b abort
uf_no_cfsr:
  ldr r0, =in_UF_no_fs
  blx puts
  b abort

/* omit .thumb_func */
_vec_SVC:
  ldr r0, =in_SVC
  blx puts
  bx lr

/* These strings are in tapit test output format */
in_main:
.string "1..1\n# In Main, trying to take SVC\n"
bad_HF:
.string "not ok 1 - Unexpected HF\n"
in_UF_no_fs:
.string "not ok 1 - In UsageFault but no CFSR bit set\n"
in_UF_invstate:
.string "ok 1 - In UsageFault with INVSTATE (pass)\n"
in_UF_wrong_fs:
.string "not ok 1 - In UsageFault with wrong CFSR bit set\n"
in_SVC:
.string "not ok 1 - In SVC, shouldn't be"

.section .bss
.align 4

.global _main_stack_bot
_main_stack_bot:
.skip 0x400
.global _main_stack_top
_main_stack_top: