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{ipi", core, hart); query_result res = query_config_string(config_string, buf); if (!res.start) break; hls_t* hls = hls_init(num_harts); hls->ipi = (void*)(uintptr_t)get_uint(res); snprintf(buf, sizeof buf, "core{%d{%d{timecmp", core, hart); res = query_config_string(config_string, buf); assert(res.start); hls->timecmp = (void*)(uintptr_t)get_uint(res); num_harts++; } if (!hart) break; } assert(num_harts); assert(num_harts <= MAX_HARTS); }
static void query_mem(const char* config_string) { query_result res = query_config_string(config_string, "ram{0{addr"); assert(res.start); mem_base = get_uint(res); res = query_config_string(config_string, "ram{0{size"); mem_size = get_uint(res); }
static void query_plic(const char* config_string) { query_result res = query_config_string(config_string, "plic{priority"); if (!res.start) return; plic_priorities = (uint32_t*)(uintptr_t)get_uint(res); res = query_config_string(config_string, "plic{ndevs"); if (!res.start) return; plic_ndevs = get_uint(res); }
static void query_hart_plic(const char* config_string, hls_t* hls, int core, int hart) { char buf[32]; snprintf(buf, sizeof buf, "core{%d{%d{plic{m{ie", core, hart); query_result res = query_config_string(config_string, buf); if (res.start) hls->plic_m_ie = (void*)(uintptr_t)get_uint(res); snprintf(buf, sizeof buf, "core{%d{%d{plic{m{thresh", core, hart); res = query_config_string(config_string, buf); if (res.start) hls->plic_m_thresh = (void*)(uintptr_t)get_uint(res); snprintf(buf, sizeof buf, "core{%d{%d{plic{s{ie", core, hart); res = query_config_string(config_string, buf); if (res.start) hls->plic_s_ie = (void*)(uintptr_t)get_uint(res); snprintf(buf, sizeof buf, "core{%d{%d{plic{s{thresh", core, hart); res = query_config_string(config_string, buf); if (res.start) hls->plic_s_thresh = (void*)(uintptr_t)get_uint(res); }
static query_result query_config_string(const char* str, const char* k) { size_t ksize = 0; while (k[ksize] && k[ksize] != '{') ksize++; int last = !k[ksize]; query_result res = {0, 0}; while (1) { const char* key_start = str = skip_whitespace(str); const char* key_end = str = skip_key(str); int match = (key_end - key_start) == ksize; if (match) for (size_t i = 0; i < ksize; i++) if (key_start[i] != k[i]) match = 0; const char* value_start = str = skip_whitespace(str); while (*str != ';') { if (!*str) { return res; } else if (*str == '"') { str = skip_string(str+1); } else if (*str == '{') { const char* search_key = match && !last ? k + ksize + 1 : ""; query_result inner_res = query_config_string(str + 1, search_key); if (inner_res.start) return inner_res; str = inner_res.end + 1; } else { str = skip_key(str); } str = skip_whitespace(str); } res.end = str; if (match && last) { res.start = value_start; return res; } str = skip_whitespace(str+1); if (*str == '}') { res.end = str; return 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); 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); num_harts++; assert(hart_id == num_harts-1); } if (!hart) break; } assert(num_harts); assert(num_harts <= MAX_HARTS); }
static void query_rtc(const char* config_string) { query_result res = query_config_string(config_string, "rtc{addr"); assert(res.start); mtime = (void*)(uintptr_t)get_uint(res); }