summaryrefslogtreecommitdiff
path: root/src/arch/riscv/bootblock.S
blob: 5092ec0405a76cd7ac44aa22b05c7d5213ff0f1c (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
/*
 * Early initialization code for aarch64 (a.k.a. armv8)
 *
 * Copyright 2013 Google Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; version 2 of
 * the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
 * GNU General Public License for more details.
 */
// See LICENSE for license details. relating to the _start code in this file.
#include <arch/encoding.h>

.section ".text._start", "ax", %progbits

.globl _start
_start:

#define STACK_START 0x80800000 /* 2GiB + 8MiB */
#define STACK_SIZE  0x0000fff0

	// pending figuring out this f-ing toolchain. Hardcode what we know works.
  li sp, STACK_START + STACK_SIZE

  # make room for HLS and initialize it
  addi sp, sp, -64 // MENTRY_FRAME_SIZE
  csrr a0, mhartid
  call hls_init

  //poison the stack
  li t1, STACK_START
  li t0, 0xdeadbeef
  sd t0, 0(t1)

  la t0, exception_handler
  csrw mtvec, t0

  # clear any pending interrupts
  csrwi mip, 0

  # set up the mstatus register for VM
  call mstatus_init
  call main
.=0x2000
    .space 0x800
# sbi interface lives here

# hart_id
.align 5
li a7, 0
ecall
ret

# num_harts
.align 4
li a0, 1
ret

# query_memory
.align 4
li a7, 8
ecall
ret

# console_putchar
.align 4
li a7, 1
ecall
ret

# send_device_request
.align 4
li a7, 2
ecall
ret

# receive_device_response
.align 4
li a7, 3
ecall
ret

# send ipi
.align 4
li a7, 4
ecall
ret

# clear ipi
.align 4
li a7, 5
ecall
ret

# timebase
.align 4
li a0, 10000000 # temporary, we should provide the correct answer
ret

# shutdown
.align 4
li a7, 6
ecall

# set_timer
.align 4
li a7, 7
ecall
ret

# end of SBI trampolines
.=0x4000
.stack:
.align 8
	.space 0xf00
.stacktop:
	.quad 0
.align 3
.stack_size:
	.quad 0xf00
.globl test_trap
exception_handler:
        call trap_handler
reset:
init_stack_loop:

	.word CONFIG_STACK_SIZE
	.section ".id", "a", %progbits

	.section ".id", "a", @progbits

	.globl __id_start
	// fix this bs later. What's wrong with the riscv gcc?
__id_start:
ver:
	.asciz "1" //COREBOOT_VERSION
vendor:
	.asciz "ucb" //CONFIG_MAINBOARD_VENDOR
part:
	.asciz "1" //CONFIG_MAINBOARD_PART_NUMBER
.long __id_end + CONFIG_ID_SECTION_OFFSET - ver  /* Reverse offset to the vendor id */
.long __id_end + CONFIG_ID_SECTION_OFFSET - vendor  /* Reverse offset to the vendor id */
.long __id_end + CONFIG_ID_SECTION_OFFSET - part    /* Reverse offset to the part number */
.long CONFIG_ROM_SIZE                               /* Size of this romimage */
	.globl __id_end

__id_end:
.previous