1 /* Copyright 2018 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
5 #include <metal/machine.h>
7 struct metal_cpu* metal_cpu_get(int hartid)
9 if (hartid < __METAL_DT_MAX_HARTS) {
10 return (struct metal_cpu *)__metal_cpu_table[hartid];
15 int metal_cpu_get_current_hartid()
19 asm volatile("csrr %0, mhartid" : "=r" (mhartid));
24 int metal_cpu_get_num_harts()
26 return __METAL_DT_MAX_HARTS;
29 extern inline unsigned long long metal_cpu_get_timer(struct metal_cpu *cpu);
31 extern inline unsigned long long metal_cpu_get_timebase(struct metal_cpu *cpu);
33 extern inline unsigned long long metal_cpu_get_mtime(struct metal_cpu *cpu);
35 extern inline int metal_cpu_set_mtimecmp(struct metal_cpu *cpu, unsigned long long time);
37 extern inline struct metal_interrupt* metal_cpu_timer_interrupt_controller(struct metal_cpu *cpu);
39 extern inline int metal_cpu_timer_get_interrupt_id(struct metal_cpu *cpu);
41 extern inline struct metal_interrupt* metal_cpu_software_interrupt_controller(struct metal_cpu *cpu);
43 extern inline int metal_cpu_software_get_interrupt_id(struct metal_cpu *cpu);
45 extern inline int metal_cpu_software_set_ipi(struct metal_cpu *cpu, int hartid);
47 extern inline int metal_cpu_software_clear_ipi(struct metal_cpu *cpu, int hartid);
49 extern inline int metal_cpu_get_msip(struct metal_cpu *cpu, int hartid);
51 extern inline struct metal_interrupt* metal_cpu_interrupt_controller(struct metal_cpu *cpu);
53 extern inline int metal_cpu_exception_register(struct metal_cpu *cpu, int ecode, metal_exception_handler_t handler);
55 extern inline int metal_cpu_get_instruction_length(struct metal_cpu *cpu, uintptr_t epc);
57 extern inline uintptr_t metal_cpu_get_exception_pc(struct metal_cpu *cpu);
59 extern inline int metal_cpu_set_exception_pc(struct metal_cpu *cpu, uintptr_t epc);