aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@cs.berkeley.edu>2016-04-29 10:54:40 -0700
committerAndrew Waterman <waterman@cs.berkeley.edu>2016-04-29 10:54:40 -0700
commit66776bbc3efce7fb4176ca03fb949f556c2c2d57 (patch)
treea05be0f4527f9c58fadc934b652a59457d009561
parentde16a763e6bf266ad49384fa131a502a6174e7ba (diff)
downloadpk-66776bbc3efce7fb4176ca03fb949f556c2c2d57.zip
pk-66776bbc3efce7fb4176ca03fb949f556c2c2d57.tar.gz
pk-66776bbc3efce7fb4176ca03fb949f556c2c2d57.tar.bz2
Remove mtime/mtimecmp
-rw-r--r--machine/configstring.c21
-rw-r--r--machine/emulation.c7
-rw-r--r--machine/encoding.h8
-rw-r--r--machine/minit.c9
-rw-r--r--machine/mtrap.c10
-rw-r--r--machine/mtrap.h7
6 files changed, 30 insertions, 32 deletions
diff --git a/machine/configstring.c b/machine/configstring.c
index 847cd4d..3d0eda3 100644
--- a/machine/configstring.c
+++ b/machine/configstring.c
@@ -170,20 +170,30 @@ static void query_mem(const char* config_string)
mem_size = get_uint(res);
}
+static void query_rtc(const char* config_string)
+{
+ query_result res = query_config_string(config_string, "rtc{addr");
+ assert(res.start);
+ mtime = (void*)get_uint(res);
+}
+
static void query_harts(const char* config_string)
{
for (int core = 0, hart; ; core++) {
for (hart = 0; ; hart++) {
char buf[32];
- snprintf(buf, sizeof buf, "core{%d{%d{addr", core, hart);
+ snprintf(buf, sizeof buf, "core{%d{%d{isa", core, hart);
query_result res = query_config_string(config_string, buf);
if (!res.start)
break;
- csr_t* base = (csr_t*)get_uint(res);
- uintptr_t hart_id = base[CSR_MHARTID];
- hls_init(hart_id, base);
+ hls_t* hls = hls_init(num_harts);
+
+ snprintf(buf, sizeof buf, "core{%d{%d{timecmp", core, hart);
+ res = query_config_string(config_string, buf);
+ assert(res.start);
+ hls->timecmp = (void*)get_uint(res);
+
num_harts++;
- assert(hart_id == num_harts-1);
}
if (!hart)
break;
@@ -196,5 +206,6 @@ void parse_config_string()
{
const char* s = (const char*)read_csr(mcfgaddr);
query_mem(s);
+ query_rtc(s);
query_harts(s);
}
diff --git a/machine/emulation.c b/machine/emulation.c
index dad86f9..70169fd 100644
--- a/machine/emulation.c
+++ b/machine/emulation.c
@@ -91,7 +91,7 @@ static inline int emulate_read_csr(int num, uintptr_t mstatus, uintptr_t* result
switch (num)
{
case CSR_TIME:
- *result = read_csr(mtime) + HLS()->utime_delta;
+ *result = *mtime + HLS()->utime_delta;
return 0;
case CSR_CYCLE:
*result = read_csr(mcycle) + HLS()->ucycle_delta;
@@ -100,7 +100,7 @@ static inline int emulate_read_csr(int num, uintptr_t mstatus, uintptr_t* result
*result = read_csr(minstret) + HLS()->uinstret_delta;
return 0;
case CSR_STIME:
- *result = read_csr(mtime) + HLS()->stime_delta;
+ *result = *mtime + HLS()->stime_delta;
return 0;
case CSR_SCYCLE:
*result = read_csr(mcycle) + HLS()->scycle_delta;
@@ -110,8 +110,7 @@ static inline int emulate_read_csr(int num, uintptr_t mstatus, uintptr_t* result
return 0;
#ifdef __riscv32
case CSR_TIMEH:
- *result = (((uint64_t)read_csr(mtimeh) << 32) + read_csr(mtime)
- + HLS()->stime_delta) >> 32;
+ *result = (*mtime + HLS()->stime_delta) >> 32;
return 0;
case CSR_CYCLEH:
*result = (((uint64_t)read_csr(mcycleh) << 32) + read_csr(mcycle)
diff --git a/machine/encoding.h b/machine/encoding.h
index c57804d..6668932 100644
--- a/machine/encoding.h
+++ b/machine/encoding.h
@@ -647,7 +647,6 @@
#define CSR_MIDELEG 0x303
#define CSR_MIE 0x304
#define CSR_MTVEC 0x305
-#define CSR_MTIMECMP 0x321
#define CSR_MSCRATCH 0x340
#define CSR_MEPC 0x341
#define CSR_MCAUSE 0x342
@@ -663,7 +662,6 @@
#define CSR_MSTIME_DELTA 0x705
#define CSR_MSINSTRET_DELTA 0x706
#define CSR_MCYCLE 0xf00
-#define CSR_MTIME 0xf01
#define CSR_MINSTRET 0xf02
#define CSR_MISA 0xf10
#define CSR_MVENDORID 0xf11
@@ -677,7 +675,6 @@
#define CSR_CYCLEH 0xc80
#define CSR_TIMEH 0xc81
#define CSR_INSTRETH 0xc82
-#define CSR_MTIMECMPH 0x361
#define CSR_MUCYCLE_DELTAH 0x780
#define CSR_MUTIME_DELTAH 0x781
#define CSR_MUINSTRET_DELTAH 0x782
@@ -685,7 +682,6 @@
#define CSR_MSTIME_DELTAH 0x785
#define CSR_MSINSTRET_DELTAH 0x786
#define CSR_MCYCLEH 0xf80
-#define CSR_MTIMEH 0xf81
#define CSR_MINSTRETH 0xf82
#define CAUSE_MISALIGNED_FETCH 0x0
#define CAUSE_FAULT_FETCH 0x1
@@ -952,7 +948,6 @@ DECLARE_CSR(medeleg, CSR_MEDELEG)
DECLARE_CSR(mideleg, CSR_MIDELEG)
DECLARE_CSR(mie, CSR_MIE)
DECLARE_CSR(mtvec, CSR_MTVEC)
-DECLARE_CSR(mtimecmp, CSR_MTIMECMP)
DECLARE_CSR(mscratch, CSR_MSCRATCH)
DECLARE_CSR(mepc, CSR_MEPC)
DECLARE_CSR(mcause, CSR_MCAUSE)
@@ -968,7 +963,6 @@ DECLARE_CSR(mscycle_delta, CSR_MSCYCLE_DELTA)
DECLARE_CSR(mstime_delta, CSR_MSTIME_DELTA)
DECLARE_CSR(msinstret_delta, CSR_MSINSTRET_DELTA)
DECLARE_CSR(mcycle, CSR_MCYCLE)
-DECLARE_CSR(mtime, CSR_MTIME)
DECLARE_CSR(minstret, CSR_MINSTRET)
DECLARE_CSR(misa, CSR_MISA)
DECLARE_CSR(mvendorid, CSR_MVENDORID)
@@ -982,7 +976,6 @@ DECLARE_CSR(mreset, CSR_MRESET)
DECLARE_CSR(cycleh, CSR_CYCLEH)
DECLARE_CSR(timeh, CSR_TIMEH)
DECLARE_CSR(instreth, CSR_INSTRETH)
-DECLARE_CSR(mtimecmph, CSR_MTIMECMPH)
DECLARE_CSR(mucycle_deltah, CSR_MUCYCLE_DELTAH)
DECLARE_CSR(mutime_deltah, CSR_MUTIME_DELTAH)
DECLARE_CSR(muinstret_deltah, CSR_MUINSTRET_DELTAH)
@@ -990,7 +983,6 @@ DECLARE_CSR(mscycle_deltah, CSR_MSCYCLE_DELTAH)
DECLARE_CSR(mstime_deltah, CSR_MSTIME_DELTAH)
DECLARE_CSR(msinstret_deltah, CSR_MSINSTRET_DELTAH)
DECLARE_CSR(mcycleh, CSR_MCYCLEH)
-DECLARE_CSR(mtimeh, CSR_MTIMEH)
DECLARE_CSR(minstreth, CSR_MINSTRETH)
#endif
#ifdef DECLARE_CAUSE
diff --git a/machine/minit.c b/machine/minit.c
index 055fdb3..c19e9e1 100644
--- a/machine/minit.c
+++ b/machine/minit.c
@@ -8,6 +8,7 @@ pte_t* root_page_table;
uintptr_t first_free_paddr;
uintptr_t mem_size;
uintptr_t num_harts;
+volatile uint64_t* mtime;
static void mstatus_init()
{
@@ -62,11 +63,11 @@ static void fp_init()
#endif
}
-void hls_init(uintptr_t id, csr_t* csrs)
+hls_t* hls_init(uintptr_t id)
{
hls_t* hls = OTHER_HLS(id);
memset(hls, 0, sizeof(*hls));
- hls->csrs = csrs;
+ return hls;
}
static uintptr_t sbi_top_paddr()
@@ -91,7 +92,7 @@ static void hart_init()
void init_first_hart()
{
hart_init();
- hls_init(0, NULL); // this might get called again from parse_config_string
+ hls_init(0); // this might get called again from parse_config_string
parse_config_string();
memory_init();
boot_loader();
@@ -102,7 +103,7 @@ void init_other_hart()
hart_init();
// wait until hart 0 discovers us
- while (*(csr_t * volatile *)&HLS()->csrs == NULL)
+ while (*(uint64_t * volatile *)&HLS()->timecmp == NULL)
;
boot_other_hart();
diff --git a/machine/mtrap.c b/machine/mtrap.c
index 1c310f9..4087a67 100644
--- a/machine/mtrap.c
+++ b/machine/mtrap.c
@@ -91,7 +91,8 @@ static void send_ipi(uintptr_t recipient, int event)
{
if ((atomic_or(&OTHER_HLS(recipient)->mipi_pending, event) & event) == 0) {
mb();
- OTHER_HLS(recipient)->csrs[CSR_MIPI] = 1;
+ if (recipient != read_const_csr(mhartid))
+ assert(!"IPIs temporarily missing");
}
}
@@ -136,12 +137,7 @@ static uintptr_t mcall_shutdown()
static uintptr_t mcall_set_timer(uint64_t when)
{
- // bbl/pk don't use the timer, so there's no need to virtualize it
-#ifdef __riscv32
- write_csr(mtimecmp, -1);
- write_csr(mtimecmph, (uintptr_t)(when >> 32));
-#endif
- write_csr(mtimecmp, (uintptr_t)when);
+ *HLS()->timecmp = when;
clear_csr(mip, MIP_STIP);
set_csr(mie, MIP_MTIP);
return 0;
diff --git a/machine/mtrap.h b/machine/mtrap.h
index 6defd67..514df98 100644
--- a/machine/mtrap.h
+++ b/machine/mtrap.h
@@ -31,11 +31,10 @@ static inline int xlen()
extern uintptr_t first_free_paddr;
extern uintptr_t mem_size;
extern uintptr_t num_harts;
-
-typedef uintptr_t csr_t; // TODO this might become uint128_t for RV128
+extern volatile uint64_t* mtime;
typedef struct {
- volatile csr_t* csrs;
+ uint64_t* timecmp;
volatile int mipi_pending;
volatile int sipi_pending;
int console_ibuf;
@@ -60,7 +59,7 @@ typedef struct {
#define HLS() ((hls_t*)(MACHINE_STACK_TOP() - HLS_SIZE))
#define OTHER_HLS(id) ((hls_t*)((void*)HLS() + RISCV_PGSIZE * ((id) - read_const_csr(mhartid))))
-void hls_init(uintptr_t hart_id, csr_t* csrs);
+hls_t* hls_init(uintptr_t hart_id);
void parse_config_string();
void poweroff(void) __attribute((noreturn));
void printm(const char* s, ...);