aboutsummaryrefslogtreecommitdiff
path: root/machine/configstring.c
blob: d2f2a84130df5522c84914aceb54edfc71aca116 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "configstring.h"
#include "encoding.h"
#include "mtrap.h"
#include <stdio.h>

static void query_mem(const char* config_string)
{
  query_result res = query_config_string(config_string, "ram{0{addr");
  assert(res.start);
  uintptr_t base = get_uint(res);
  res = query_config_string(config_string, "ram{0{size");
  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{isa", core, hart);
      query_result res = query_config_string(config_string, buf);
      if (!res.start)
        break;
      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++;
    }
    if (!hart)
      break;
  }
  assert(num_harts);
  assert(num_harts <= MAX_HARTS);
}

void parse_config_string()
{
  const char* s = (const char*)read_csr(mcfgaddr);
  query_mem(s);
  query_rtc(s);
  query_harts(s);
}