Ronald G. Minnich | e0e784a | 2014-11-26 19:25:47 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Early initialization code for aarch64 (a.k.a. armv8) |
| 3 | * |
Thaminda Edirisooriya | a47738d | 2015-08-26 15:39:16 -0700 | [diff] [blame] | 4 | * Copyright 2013 Google Inc. |
Ronald G. Minnich | e0e784a | 2014-11-26 19:25:47 +0000 | [diff] [blame] | 5 | * |
| 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. Minnich | e0e784a | 2014-11-26 19:25:47 +0000 | [diff] [blame] | 15 | */ |
| 16 | // See LICENSE for license details. relating to the _start code in this file. |
| 17 | #include <arch/encoding.h> |
| 18 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 19 | .section ".text._start", "ax", %progbits |
Ronald G. Minnich | e0e784a | 2014-11-26 19:25:47 +0000 | [diff] [blame] | 20 | // Maybe there's a better way. |
Thaminda Edirisooriya | a47738d | 2015-08-26 15:39:16 -0700 | [diff] [blame] | 21 | # machine mode handler when in supervisor mode |
| 22 | .space 0x140 |
| 23 | supervisor_machine_handler: |
| 24 | j supervisor_trap_entry |
| 25 | |
| 26 | # handler for when |
| 27 | .space 0x7c |
| 28 | .globl machine_handler |
| 29 | machine_handler: |
| 30 | # call trap_handler |
| 31 | j trap_entry |
| 32 | |
| 33 | .space 0x3c |
Ronald G. Minnich | e0e784a | 2014-11-26 19:25:47 +0000 | [diff] [blame] | 34 | .globl _start |
| 35 | _start: |
| 36 | |
| 37 | // pending figuring out this f-ing toolchain. Hardcode what we know works. |
Thaminda Edirisooriya | a47738d | 2015-08-26 15:39:16 -0700 | [diff] [blame] | 38 | la sp, 0x80FFF0 // stack start + stack size |
Thaminda Edirisooriya | 8fad21d | 2015-07-29 17:43:20 -0700 | [diff] [blame] | 39 | |
Thaminda Edirisooriya | a47738d | 2015-08-26 15:39:16 -0700 | [diff] [blame] | 40 | # make room for HLS and initialize it |
Thaminda Edirisooriya | 8fad21d | 2015-07-29 17:43:20 -0700 | [diff] [blame] | 41 | addi sp, sp, -64 // MENTRY_FRAME_SIZE |
Thaminda Edirisooriya | a47738d | 2015-08-26 15:39:16 -0700 | [diff] [blame] | 42 | csrr a0, mhartid |
| 43 | call hls_init |
Thaminda Edirisooriya | 8fad21d | 2015-07-29 17:43:20 -0700 | [diff] [blame] | 44 | |
| 45 | //poison the stack |
Thaminda Edirisooriya | a47738d | 2015-08-26 15:39:16 -0700 | [diff] [blame] | 46 | la t1, 0x800000 |
Thaminda Edirisooriya | 8fad21d | 2015-07-29 17:43:20 -0700 | [diff] [blame] | 47 | li t0, 0xdeadbeef |
| 48 | sd t0, 0(t1) |
| 49 | |
Thaminda Edirisooriya | a47738d | 2015-08-26 15:39:16 -0700 | [diff] [blame] | 50 | la t0, exception_handler |
| 51 | csrw stvec, t0 |
Ronald G. Minnich | e0e784a | 2014-11-26 19:25:47 +0000 | [diff] [blame] | 52 | |
| 53 | # clear any pending interrupts |
Thaminda Edirisooriya | 8fad21d | 2015-07-29 17:43:20 -0700 | [diff] [blame] | 54 | csrwi sip, 0 |
Ronald G. Minnich | e0e784a | 2014-11-26 19:25:47 +0000 | [diff] [blame] | 55 | |
Thaminda Edirisooriya | a47738d | 2015-08-26 15:39:16 -0700 | [diff] [blame] | 56 | # set up the mstatus register for VM |
| 57 | call mstatus_init |
Ronald G. Minnich | e0e784a | 2014-11-26 19:25:47 +0000 | [diff] [blame] | 58 | call main |
Thaminda Edirisooriya | a47738d | 2015-08-26 15:39:16 -0700 | [diff] [blame] | 59 | .=0x2000 |
| 60 | .space 0x800 |
| 61 | # sbi interface lives here |
| 62 | |
| 63 | # hart_id |
| 64 | .align 5 |
| 65 | li a7, 0 |
| 66 | ecall |
| 67 | ret |
| 68 | |
| 69 | # num_harts |
| 70 | .align 4 |
| 71 | li a0, 1 |
| 72 | ret |
| 73 | |
| 74 | # query_memory |
| 75 | .align 4 |
| 76 | li a7, 8 |
| 77 | ecall |
| 78 | ret |
| 79 | |
| 80 | # console_putchar |
| 81 | .align 4 |
| 82 | li a7, 1 |
| 83 | ecall |
| 84 | ret |
| 85 | |
| 86 | # send_device_request |
| 87 | .align 4 |
| 88 | li a7, 2 |
| 89 | ecall |
| 90 | ret |
| 91 | |
| 92 | # receive_device_response |
| 93 | .align 4 |
| 94 | li a7, 3 |
| 95 | ecall |
| 96 | ret |
| 97 | |
| 98 | # send ipi |
| 99 | .align 4 |
| 100 | li a7, 4 |
| 101 | ecall |
| 102 | ret |
| 103 | |
| 104 | # clear ipi |
| 105 | .align 4 |
| 106 | li a7, 5 |
| 107 | ecall |
| 108 | ret |
| 109 | |
| 110 | # timebase |
| 111 | .align 4 |
| 112 | li a0, 10000000 # temporary, we should provide the correct answer |
| 113 | ret |
| 114 | |
| 115 | # shutdown |
| 116 | .align 4 |
| 117 | li a7, 6 |
| 118 | ecall |
| 119 | |
| 120 | # set_timer |
| 121 | .align 4 |
| 122 | li a7, 7 |
| 123 | ecall |
| 124 | ret |
| 125 | |
| 126 | # end of SBI trampolines |
Ronald G. Minnich | e0e784a | 2014-11-26 19:25:47 +0000 | [diff] [blame] | 127 | .=0x4000 |
| 128 | .stack: |
| 129 | .align 8 |
| 130 | .space 0xf00 |
| 131 | .stacktop: |
| 132 | .quad 0 |
| 133 | .align 3 |
| 134 | .stack_size: |
| 135 | .quad 0xf00 |
Thaminda Edirisooriya | a47738d | 2015-08-26 15:39:16 -0700 | [diff] [blame] | 136 | .globl test_trap |
| 137 | exception_handler: |
| 138 | call trap_handler |
Ronald G. Minnich | e0e784a | 2014-11-26 19:25:47 +0000 | [diff] [blame] | 139 | reset: |
| 140 | init_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: |
| 150 | ver: |
| 151 | .asciz "1" //COREBOOT_VERSION |
| 152 | vendor: |
| 153 | .asciz "ucb" //CONFIG_MAINBOARD_VENDOR |
| 154 | part: |
| 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 |