1 /* Copyright 2018 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
5 #include <metal/machine.h>
7 struct metal_cpu* metal_cpu_get(unsigned 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);