// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (C) 2023, Ventana Micro Systems Inc., Andrew Jones <ajones@ventanamicro.com>
 */
#include <libcflat.h>
#include <asm/csr.h>
#include <asm/isa.h>
#include <asm/processor.h>
#include <asm/setup.h>

extern unsigned long ImageBase;

void show_regs(struct pt_regs *regs)
{
	struct thread_info *info = current_thread_info();
	uintptr_t loadaddr = (uintptr_t)&ImageBase;
	unsigned int w = __riscv_xlen / 4;

	printf("Load address: %" PRIxPTR "\n", loadaddr);
	printf("CPU%3d : hartid=%lx\n", info->cpu, info->hartid);
	printf("status : %.*lx\n", w, regs->status);
	printf("cause  : %.*lx\n", w, regs->cause);
	printf("badaddr: %.*lx\n", w, regs->badaddr);
	printf("pc: %.*lx (%lx) ra: %.*lx (%lx)\n", w, regs->epc, regs->epc - loadaddr, w, regs->ra, regs->ra - loadaddr);
	printf("sp: %.*lx gp: %.*lx tp : %.*lx\n", w, regs->sp, w, regs->gp, w, regs->tp);
	printf("a0: %.*lx a1: %.*lx a2 : %.*lx a3 : %.*lx\n", w, regs->a0, w, regs->a1, w, regs->a2, w, regs->a3);
	printf("a4: %.*lx a5: %.*lx a6 : %.*lx a7 : %.*lx\n", w, regs->a4, w, regs->a5, w, regs->a6, w, regs->a7);
	printf("t0: %.*lx t1: %.*lx t2 : %.*lx t3 : %.*lx\n", w, regs->t0, w, regs->t1, w, regs->t2, w, regs->t3);
	printf("t4: %.*lx t5: %.*lx t6 : %.*lx\n", w, regs->t4, w, regs->t5, w, regs->t6);
	printf("s0: %.*lx s1: %.*lx s2 : %.*lx s3 : %.*lx\n", w, regs->s0, w, regs->s1, w, regs->s2, w, regs->s3);
	printf("s4: %.*lx s5: %.*lx s6 : %.*lx s7 : %.*lx\n", w, regs->s4, w, regs->s5, w, regs->s6, w, regs->s7);
	printf("s8: %.*lx s9: %.*lx s10: %.*lx s11: %.*lx\n", w, regs->s8, w, regs->s9, w, regs->s10, w, regs->s11);
}

void do_handle_exception(struct pt_regs *regs)
{
	struct thread_info *info = current_thread_info();

	assert(regs->cause < EXCEPTION_CAUSE_MAX);
	if (info->exception_handlers[regs->cause]) {
		info->exception_handlers[regs->cause](regs);
		return;
	}

	show_regs(regs);
	dump_frame_stack((void *)regs->epc, (void *)regs->s0);
	abort();
}

void install_exception_handler(unsigned long cause, void (*handler)(struct pt_regs *))
{
	struct thread_info *info = current_thread_info();

	assert(cause < EXCEPTION_CAUSE_MAX);
	info->exception_handlers[cause] = handler;
}

void thread_info_init(void)
{
	unsigned long hartid = csr_read(CSR_SSCRATCH);
	int cpu = hartid_to_cpu(hartid);

	isa_init(&cpus[cpu]);
	csr_write(CSR_SSCRATCH, &cpus[cpu]);
}
