aboutsummaryrefslogtreecommitdiff
path: root/tests/simple_riscv64/sim.c
blob: f92be9632fac42211ef0bc77be275f2aafcf8cfa (plain) (blame)
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
/* SPDX-License-Identifier: copyleft-next-0.3.1 */
/* Copyright 2023 Kim Kuparinen < kimi.h.kuparinen@gmail.com > */

#include <assert.h>

#include <gran/root.h>
#include <gran/mem/simple_mem.h>
#include <gran/cpu/riscv/simple_riscv64.h>

unsigned char simple_sum[] = {
	0x13, 0x05, 0x00, 0x00, 0xb7, 0x45, 0x0f, 0x00, 0x93, 0x85, 0x05, 0x24,
	0x13, 0x06, 0x00, 0x00, 0x63, 0x08, 0xb5, 0x00, 0x33, 0x06, 0xa6, 0x00,
	0x13, 0x05, 0x15, 0x00, 0x6f, 0xf0, 0x5f, 0xff, 0x73, 0x00, 0x10, 0x00
};

unsigned int simple_sum_len = 36;

int main()
{
	const size_t size = 4096;
	struct component *imem = create_simple_mem(size);

	/* This works for simple memory, but feels kind of hacky */
	init_simple_mem(imem, 0, simple_sum_len, simple_sum);

	struct component *dmem = create_simple_mem(size);
	struct component *rv64 = create_simple_riscv64(4096, 0, imem, dmem);

	struct clock_domain *clk = create_clock_domain(NS(1));
	clock_domain_add(clk, rv64);
	clock_domain_add(clk, imem);
	clock_domain_add(clk, dmem);

	struct gran_root *root = create_root();
	root_add_clock(root, clk);

	assert(root_run(root) == OK);

	destroy_root(root);
}