diff options
author | Andrew Waterman <waterman@cs.berkeley.edu> | 2015-05-09 16:17:11 -0700 |
---|---|---|
committer | Andrew Waterman <waterman@cs.berkeley.edu> | 2015-05-09 16:41:10 -0700 |
commit | 1a8572a47db3151323ec390c430da37d831fc962 (patch) | |
tree | 0e84071d505a875c874460a7d036ff9aa4b8931a /pk/mtrap.h | |
parent | ac7853a1bc5fcbee820a4f1472aa59eaf074e4e9 (diff) | |
download | pk-1a8572a47db3151323ec390c430da37d831fc962.zip pk-1a8572a47db3151323ec390c430da37d831fc962.tar.gz pk-1a8572a47db3151323ec390c430da37d831fc962.tar.bz2 |
Upgrade to privileged architecture 1.7
Diffstat (limited to 'pk/mtrap.h')
-rw-r--r-- | pk/mtrap.h | 24 |
1 files changed, 20 insertions, 4 deletions
@@ -19,11 +19,10 @@ #define unpriv_mem_access_base(mstatus, mepc, code, o0, o1, i0, i1, i2) ({ \ register uintptr_t result asm("t0"); \ uintptr_t unused1, unused2 __attribute__((unused)); \ - uintptr_t scratch = ~(mstatus) & MSTATUS_PRV1; \ - scratch <<= CONST_CTZ32(MSTATUS_MPRV) - CONST_CTZ32(MSTATUS_PRV1); \ - asm volatile ("csrrc %[result], mstatus, %[scratch]\n" \ + uintptr_t scratch = MSTATUS_MPRV; \ + asm volatile ("csrrs %[result], mstatus, %[scratch]\n" \ "98: " code "\n" \ - "99: csrs mstatus, %[scratch]\n" \ + "99: csrc mstatus, %[scratch]\n" \ ".pushsection .unpriv,\"a\",@progbits\n" \ ".word 98b; .word 99b\n" \ ".popsection" \ @@ -204,6 +203,23 @@ static insn_fetch_t __attribute__((always_inline)) return fetch; } +static inline long __attribute__((pure)) cpuid() +{ + long res; + asm ("csrr %0, mcpuid" : "=r"(res)); // not volatile, so don't use read_csr() + return res; +} + +static inline int supports_extension(char ext) +{ + return cpuid() & (1 << (ext - 'A')); +} + +static inline int xlen() +{ + return cpuid() < 0 ? 64 : 32; +} + typedef struct { sbi_device_message* device_request_queue_head; size_t device_request_queue_size; |