/*-1* Copyright (c) 2015-2018 Ruslan Bukin <[email protected]>2* All rights reserved.3*4* Portions of this software were developed by SRI International and the5* University of Cambridge Computer Laboratory under DARPA/AFRL contract6* FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme.7*8* Portions of this software were developed by the University of Cambridge9* Computer Laboratory as part of the CTSRD Project, with support from the10* UK Higher Education Innovation Fund (HEIF).11*12* Redistribution and use in source and binary forms, with or without13* modification, are permitted provided that the following conditions14* are met:15* 1. Redistributions of source code must retain the above copyright16* notice, this list of conditions and the following disclaimer.17* 2. Redistributions in binary form must reproduce the above copyright18* notice, this list of conditions and the following disclaimer in the19* documentation and/or other materials provided with the distribution.20*21* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND22* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE23* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE24* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE25* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL26* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS27* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)28* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT29* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY30* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF31* SUCH DAMAGE.32*/3334#ifndef _MACHINE_CPU_H_35#define _MACHINE_CPU_H_3637#ifndef LOCORE38#include <machine/atomic.h>39#include <machine/cpufunc.h>40#include <machine/frame.h>41#endif4243#define TRAPF_PC(tfp) ((tfp)->tf_sepc)44#define TRAPF_USERMODE(tfp) (((tfp)->tf_sstatus & SSTATUS_SPP) == 0)4546#define cpu_getstack(td) ((td)->td_frame->tf_sp)47#define cpu_setstack(td, sp) ((td)->td_frame->tf_sp = (sp))48#define cpu_spinwait() /* nothing */49#define cpu_lock_delay() DELAY(1)5051/*52* Core manufacturer IDs, as reported by the mvendorid CSR.53*/54#define MVENDORID_UNIMPL 0x055#define MVENDORID_SIFIVE 0x48956#define MVENDORID_THEAD 0x5b75758/*59* Micro-architecture ID register, marchid.60*61* IDs for open-source implementations are allocated globally. Commercial IDs62* will have the most-significant bit set.63*/64#define MARCHID_UNIMPL 0x065#define MARCHID_MSB (1ul << (XLEN - 1))66#define MARCHID_OPENSOURCE(v) (v)67#define MARCHID_COMMERCIAL(v) (MARCHID_MSB | (v))68#define MARCHID_IS_OPENSOURCE(m) (((m) & MARCHID_MSB) == 0)6970/*71* Open-source marchid values.72*73* https://github.com/riscv/riscv-isa-manual/blob/master/marchid.md74*/75#define MARCHID_UCB_ROCKET MARCHID_OPENSOURCE(1)76#define MARCHID_UCB_BOOM MARCHID_OPENSOURCE(2)77#define MARCHID_UCB_SPIKE MARCHID_OPENSOURCE(5)78#define MARCHID_UCAM_RVBS MARCHID_OPENSOURCE(10)7980/* SiFive marchid values */81#define MARCHID_SIFIVE_U7 MARCHID_COMMERCIAL(7)82#define MARCHID_SIFIVE_P5 MARCHID_COMMERCIAL(8)8384/*85* MMU virtual-addressing modes. Support for each level implies the previous,86* so Sv48-enabled systems MUST support Sv39, etc.87*/88#define MMU_SV39 0x1 /* 3-level paging */89#define MMU_SV48 0x2 /* 4-level paging */90#define MMU_SV57 0x4 /* 5-level paging */9192#ifdef _KERNEL93#ifndef LOCORE9495extern char btext[];96extern char etext[];9798void cpu_halt(void) __dead2;99void cpu_reset(void) __dead2;100void fork_trampoline(void);101void identify_cpu(u_int cpu);102void printcpuinfo(u_int cpu);103104static __inline uint64_t105get_cyclecount(void)106{107108return (rdcycle());109}110111#endif /* !LOCORE */112#endif /* _KERNEL */113114#endif /* !_MACHINE_CPU_H_ */115116117