diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-08-04 20:50:41 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-08-04 20:50:41 +0300 |
| commit | e16f5f81dfb2e97a554ec19b941ec05a7942fd2d (patch) | |
| tree | 46f0609b5be009d4d1057fa02ece4461732941e0 /arch/riscv64/kernel/arch.c | |
| parent | 5f30284181fcfe5b16dfb94d4fba9a9ed4a2dc6a (diff) | |
| download | kmi-e16f5f81dfb2e97a554ec19b941ec05a7942fd2d.tar.gz kmi-e16f5f81dfb2e97a554ec19b941ec05a7942fd2d.zip | |
add initial smp bringup
Diffstat (limited to 'arch/riscv64/kernel/arch.c')
| -rw-r--r-- | arch/riscv64/kernel/arch.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/arch/riscv64/kernel/arch.c b/arch/riscv64/kernel/arch.c new file mode 100644 index 0000000..c4009e7 --- /dev/null +++ b/arch/riscv64/kernel/arch.c @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: copyleft-next-0.3.1 */ +/* Copyright 2023, Kim Kuparinen < kimi.h.kuparinen@gmail.com > */ + +/** + * @file arch.c + * Misc riscv specific stuff implementations. + */ + +#include <kmi/assert.h> +#include <kmi/debug.h> +#include "csr.h" +#include "arch.h" + +id_t __cpuid_to_hartid[MAX_CPUS]; + +id_t hartid_to_cpuid(id_t hart) +{ + for (size_t i = 0; i < MAX_CPUS; ++i) + if (cpuid_to_hartid(i) == hart) + return i; + + error("failed to match hart id %d to cpu id\n", hart); + /* default to zero, though this should maybe be a panic? */ + return 0; +} + +pm_t branch_to_satp(struct vmem *branch, enum mm_mode mode) +{ + /* Sv57 && Sv64 in the future? */ + branch = (struct vmem *)__pa(branch); + pm_t pn = (pm_t)(branch) >> page_shift(); + + pm_t m = DEFAULT_Sv_MODE; + + switch (mode) { + case Sv32: m = SATP_MODE_Sv32; break; + case Sv39: m = SATP_MODE_Sv39; break; + case Sv48: m = SATP_MODE_Sv48; break; + default: bug("unknown satp mode\n"); break; + } + + return m | pn; +} |
