aboutsummaryrefslogtreecommitdiff
path: root/benchmarks/common/crt.S
blob: fb2cc25c692b4a8565d24dc12aa67e840dd0195e (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
#include "encoding.h"

  .data
  .globl _heapend
  .globl environ
_heapend:
  .word 0
environ:
  .word 0

  .text
  .globl _start

_start:
  li  x1, 0
  li  x2, 0
  li  x3, 0
  li  x4, 0
  li  x5, 0
  li  x6, 0
  li  x7, 0
  li  x8, 0
  li  x9, 0
  li  x10,0
  li  x11,0
  li  x12,0
  li  x13,0
  li  x14,0
  li  x15,0
  li  x16,0
  li  x17,0
  li  x18,0
  li  x19,0
  li  x20,0
  li  x21,0
  li  x22,0
  li  x23,0
  li  x24,0
  li  x25,0
  li  x26,0
  li  x27,0
  li  x28,0
  li  x29,0
  li  x30,0
  li  x31,0

#ifdef __riscv64
  li a0, SR_U64 | SR_S64
  csrs status, a0
#endif

  # enable fp and accelerator
  li a0, SR_EF | SR_EA
  csrs status, a0

  ## if that didn't stick, we don't have an FPU, so don't initialize it
  csrr t0, status
  and t0, t0, SR_EF
  beqz t0, 1f

  fssr    x0
  fmv.s.x f0, x0
  fmv.s.x f1, x0
  fmv.s.x f2, x0
  fmv.s.x f3, x0
  fmv.s.x f4, x0
  fmv.s.x f5, x0
  fmv.s.x f6, x0
  fmv.s.x f7, x0
  fmv.s.x f8, x0
  fmv.s.x f9, x0
  fmv.s.x f10,x0
  fmv.s.x f11,x0
  fmv.s.x f12,x0
  fmv.s.x f13,x0
  fmv.s.x f14,x0
  fmv.s.x f15,x0
  fmv.s.x f16,x0
  fmv.s.x f17,x0
  fmv.s.x f18,x0
  fmv.s.x f19,x0
  fmv.s.x f20,x0
  fmv.s.x f21,x0
  fmv.s.x f22,x0
  fmv.s.x f23,x0
  fmv.s.x f24,x0
  fmv.s.x f25,x0
  fmv.s.x f26,x0
  fmv.s.x f27,x0
  fmv.s.x f28,x0
  fmv.s.x f29,x0
  fmv.s.x f30,x0
  fmv.s.x f31,x0
1:

  la t0, trap_entry
  csrw evec, t0

  la  tp, _end + 63
  and tp, tp, -64

  # get core id and number of cores
  csrr a0, hartid
  lw a1, 4(zero)

  # give each core a 1KB TLS and a 127KB stack
#define STKSHIFT 17
  sll a2, a0, STKSHIFT
  add tp, tp, a2
  add sp, a0, 1
  sll sp, sp, STKSHIFT
  add sp, sp, tp
  add tp, tp, 1024

  jal _init
  unimp

trap_entry:
  csrw sup0, t0
  csrw sup1, t1
  la t0, uarch_insn
  lw t0, (t0)
  csrr t1, epc
  and t1, t1, ~3
  lw t1, (t1)
  and t1, t1, t0
  beq t1, t0, handle_uarch_insn

  # a trap occurred that shouldn't have.
  li t0, 1337
  csrw tohost, t0
1:j 1b

handle_uarch_insn:
  # we trapped on an illegal uarch-specific CSR.  just skip over it.
  csrr t1, epc
  add t1, t1, 4
  csrw epc, t1
  csrr t0, sup0
  csrr t1, sup1
  sret

uarch_insn:
  csrr x0, uarch0