blob: 27c80ebd05ed40afa2b0d7267951df54cc13b7e0 [file] [log] [blame]
Ronald G. Minniche0e784a2014-11-26 19:25:47 +00001/*
2 * Early initialization code for aarch64 (a.k.a. armv8)
3 *
Thaminda Edirisooriyaa47738d2015-08-26 15:39:16 -07004 * Copyright 2013 Google Inc.
Ronald G. Minniche0e784a2014-11-26 19:25:47 +00005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
14 * GNU General Public License for more details.
Ronald G. Minniche0e784a2014-11-26 19:25:47 +000015 */
16// See LICENSE for license details. relating to the _start code in this file.
17#include <arch/encoding.h>
18
Julius Wernerec5e5e02014-08-20 15:29:56 -070019.section ".text._start", "ax", %progbits
Ronald G. Minniche0e784a2014-11-26 19:25:47 +000020// Maybe there's a better way.
Thaminda Edirisooriyaa47738d2015-08-26 15:39:16 -070021# machine mode handler when in supervisor mode
22.space 0x140
23supervisor_machine_handler:
24 j supervisor_trap_entry
25
26# handler for when
27.space 0x7c
28.globl machine_handler
29machine_handler:
30# call trap_handler
31 j trap_entry
32
33.space 0x3c
Ronald G. Minniche0e784a2014-11-26 19:25:47 +000034.globl _start
35_start:
36
37 // pending figuring out this f-ing toolchain. Hardcode what we know works.
Thaminda Edirisooriyaa47738d2015-08-26 15:39:16 -070038 la sp, 0x80FFF0 // stack start + stack size
Thaminda Edirisooriya8fad21d2015-07-29 17:43:20 -070039
Thaminda Edirisooriyaa47738d2015-08-26 15:39:16 -070040 # make room for HLS and initialize it
Thaminda Edirisooriya8fad21d2015-07-29 17:43:20 -070041 addi sp, sp, -64 // MENTRY_FRAME_SIZE
Thaminda Edirisooriyaa47738d2015-08-26 15:39:16 -070042 csrr a0, mhartid
43 call hls_init
Thaminda Edirisooriya8fad21d2015-07-29 17:43:20 -070044
45 //poison the stack
Thaminda Edirisooriyaa47738d2015-08-26 15:39:16 -070046 la t1, 0x800000
Thaminda Edirisooriya8fad21d2015-07-29 17:43:20 -070047 li t0, 0xdeadbeef
48 sd t0, 0(t1)
49
Thaminda Edirisooriyaa47738d2015-08-26 15:39:16 -070050 la t0, exception_handler
51 csrw stvec, t0
Ronald G. Minniche0e784a2014-11-26 19:25:47 +000052
53 # clear any pending interrupts
Thaminda Edirisooriya8fad21d2015-07-29 17:43:20 -070054 csrwi sip, 0
Ronald G. Minniche0e784a2014-11-26 19:25:47 +000055
Thaminda Edirisooriyaa47738d2015-08-26 15:39:16 -070056 # set up the mstatus register for VM
57 call mstatus_init
Ronald G. Minniche0e784a2014-11-26 19:25:47 +000058 call main
Thaminda Edirisooriyaa47738d2015-08-26 15:39:16 -070059.=0x2000
60 .space 0x800
61# sbi interface lives here
62
63# hart_id
64.align 5
65li a7, 0
66ecall
67ret
68
69# num_harts
70.align 4
71li a0, 1
72ret
73
74# query_memory
75.align 4
76li a7, 8
77ecall
78ret
79
80# console_putchar
81.align 4
82li a7, 1
83ecall
84ret
85
86# send_device_request
87.align 4
88li a7, 2
89ecall
90ret
91
92# receive_device_response
93.align 4
94li a7, 3
95ecall
96ret
97
98# send ipi
99.align 4
100li a7, 4
101ecall
102ret
103
104# clear ipi
105.align 4
106li a7, 5
107ecall
108ret
109
110# timebase
111.align 4
112li a0, 10000000 # temporary, we should provide the correct answer
113ret
114
115# shutdown
116.align 4
117li a7, 6
118ecall
119
120# set_timer
121.align 4
122li a7, 7
123ecall
124ret
125
126# end of SBI trampolines
Ronald G. Minniche0e784a2014-11-26 19:25:47 +0000127.=0x4000
128.stack:
129.align 8
130 .space 0xf00
131.stacktop:
132 .quad 0
133.align 3
134.stack_size:
135 .quad 0xf00
Thaminda Edirisooriyaa47738d2015-08-26 15:39:16 -0700136.globl test_trap
137exception_handler:
138 call trap_handler
Ronald G. Minniche0e784a2014-11-26 19:25:47 +0000139reset:
140init_stack_loop:
141
142 .word CONFIG_STACK_SIZE
143 .section ".id", "a", %progbits
144
145 .section ".id", "a", @progbits
146
147 .globl __id_start
148 // fix this bs later. What's wrong with the riscv gcc?
149__id_start:
150ver:
151 .asciz "1" //COREBOOT_VERSION
152vendor:
153 .asciz "ucb" //CONFIG_MAINBOARD_VENDOR
154part:
155 .asciz "1" //CONFIG_MAINBOARD_PART_NUMBER
156.long __id_end + CONFIG_ID_SECTION_OFFSET - ver /* Reverse offset to the vendor id */
157.long __id_end + CONFIG_ID_SECTION_OFFSET - vendor /* Reverse offset to the vendor id */
158.long __id_end + CONFIG_ID_SECTION_OFFSET - part /* Reverse offset to the part number */
159.long CONFIG_ROM_SIZE /* Size of this romimage */
160 .globl __id_end
161
162__id_end:
163.previous