2018-10-14 17:12:01 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2015 Travis Geiselbrecht
|
|
|
|
|
*
|
2019-07-05 17:22:23 -07:00
|
|
|
* Use of this source code is governed by a MIT-style
|
|
|
|
|
* license that can be found in the LICENSE file or at
|
|
|
|
|
* https://opensource.org/licenses/MIT
|
2018-10-14 17:12:01 -07:00
|
|
|
*/
|
2019-02-18 22:05:44 -08:00
|
|
|
#include <assert.h>
|
2019-06-17 18:28:51 -07:00
|
|
|
#include <lk/trace.h>
|
|
|
|
|
#include <lk/debug.h>
|
2018-10-14 17:12:01 -07:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <arch/riscv.h>
|
2019-02-18 22:05:44 -08:00
|
|
|
#include <arch/ops.h>
|
2018-10-14 17:12:01 -07:00
|
|
|
|
|
|
|
|
#define LOCAL_TRACE 0
|
|
|
|
|
|
|
|
|
|
void arch_early_init(void) {
|
|
|
|
|
// set the top level exception handler
|
|
|
|
|
riscv_csr_write(mtvec, (uintptr_t)&riscv_exception_entry);
|
|
|
|
|
|
|
|
|
|
// mask all exceptions, just in case
|
|
|
|
|
riscv_csr_clear(mstatus, RISCV_STATUS_MIE);
|
|
|
|
|
riscv_csr_clear(mie, RISCV_MIE_MTIE | RISCV_MIE_MSIE | RISCV_MIE_SEIE | RISCV_MIE_MEIE);
|
|
|
|
|
|
2019-02-18 22:05:44 -08:00
|
|
|
// enable cycle counter (disabled for now, unimplemented on sifive-e)
|
|
|
|
|
//riscv_csr_set(mcounteren, 1);
|
2018-10-14 17:12:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void arch_init(void) {
|
2019-02-18 22:05:44 -08:00
|
|
|
// print some arch info
|
|
|
|
|
dprintf(INFO, "RISCV: mvendorid %#lx marchid %#lx mimpid %#lx mhartid %#lx\n",
|
|
|
|
|
riscv_csr_read(mvendorid), riscv_csr_read(marchid),
|
|
|
|
|
riscv_csr_read(mimpid), riscv_csr_read(mhartid));
|
|
|
|
|
dprintf(INFO, "RISCV: misa %#lx\n", riscv_csr_read(misa));
|
|
|
|
|
|
2018-10-14 17:12:01 -07:00
|
|
|
// enable external interrupts
|
|
|
|
|
riscv_csr_set(mie, RISCV_MIE_MEIE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void arch_idle(void) {
|
|
|
|
|
// disabled for now, QEMU seems to have some trouble emulating wfi properly
|
2019-02-18 22:05:44 -08:00
|
|
|
// also have trouble breaking into sifive-e board with openocd when wfi
|
2019-11-02 18:13:02 -07:00
|
|
|
// NOTE: reenabling for now, will need to re-test on sifive board to see if this
|
|
|
|
|
// problem went away.
|
|
|
|
|
__asm__ volatile("wfi");
|
2018-10-14 17:12:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void arch_chain_load(void *entry, ulong arg0, ulong arg1, ulong arg2, ulong arg3) {
|
|
|
|
|
PANIC_UNIMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* unimplemented cache operations */
|
|
|
|
|
void arch_disable_cache(uint flags) { PANIC_UNIMPLEMENTED; }
|
|
|
|
|
void arch_enable_cache(uint flags) { PANIC_UNIMPLEMENTED; }
|
|
|
|
|
|
|
|
|
|
void arch_clean_cache_range(addr_t start, size_t len) { PANIC_UNIMPLEMENTED; }
|
|
|
|
|
void arch_clean_invalidate_cache_range(addr_t start, size_t len) { PANIC_UNIMPLEMENTED; }
|
|
|
|
|
void arch_invalidate_cache_range(addr_t start, size_t len) { PANIC_UNIMPLEMENTED; }
|
|
|
|
|
void arch_sync_cache_range(addr_t start, size_t len) { PANIC_UNIMPLEMENTED; }
|