summaryrefslogtreecommitdiff
path: root/emulator/main.c
blob: a00a7177aac79550d2bcafa07ca3d7c9cbb618bf (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
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

#include "emulator/hart.h"
#include "emulator/elf.h"

int main(int argc, char* argv[])
{
    if (argc < 2)
    {
        printf("Usage: %s <input elf>\n", argv[0]);
        return EXIT_FAILURE;
    }

    uint32_t mem_size = 16 * 1024 * 1024;
    char* mem = (char*)malloc(mem_size);
    uint32_t start_address = 0;

    if (!load_elf(argv[1], mem, mem_size, &start_address))
    {
        printf("Error loading ELF into memory\n");
        return EXIT_FAILURE;
    }

    struct Hart hart = {0};
    hart.mem = mem;
    hart.mem_size = mem_size;

    execute_from(&hart, start_address);

    return EXIT_SUCCESS;
}

#include "emulator/hart.c"
#include "emulator/elf.c"