-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
148 lines (125 loc) · 2.84 KB
/
main.c
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <stdbool.h>
#include <stdint.h>
#include "fdt.h"
#include "io_interface.h"
#include "memory_manager.h"
#include "memory_map.h"
#include "plic.h"
#include "sbi.h"
#include "timer.h"
#include "trap.h"
#include "uart.h"
#include "utils.h"
#include "virtio_mmio.h"
#include "virtual_memory.h"
#include "vmm/vcpu.h"
#include "vmm/vmm.h"
extern const struct memory_map_entry memory_map[];
static int count_kthread = 0;
static int count_main = 0;
void kthread_0(void)
{
write_char_by_uart('t');
write_char_by_uart('h');
write_char_by_uart('r');
write_char_by_uart('e');
write_char_by_uart('a');
write_char_by_uart('d');
write_char_by_uart('\n');
while (true)
{
count_kthread++;
__asm__ volatile("wfi");
}
}
void guest_func(void)
{
static int a = 0;
while (true)
{
a++;
}
sbi_shutdown();
}
void start_kernel(uint64_t hart_id, uintptr_t device_tree_base)
{
bool result;
result = pre_init_memory_manager();
if (!result)
{
// panic("failed the init_memory_manager");
return;
}
result = init_fdt(device_tree_base);
if (!result)
{
// panic("failed the init_fdt");
return;
}
result = post_init_memory_manager();
if (!result)
{
return;
}
result = init_trap(hart_id);
if (!result)
{
panic("failed the init_trap");
}
result = init_virtual_memory();
if (!result)
{
panic("failed at init_virtual_memory");
}
result = init_plic(&memory_map[VIRT_PLIC]);
if (!result)
{
panic("failed the init_plic.");
}
result = init_uart(&memory_map[VIRT_UART0]);
if (!result)
{
panic("failed the init_uart");
}
result = init_virtio_mmio(&memory_map[VIRT_VIRTIO]);
if (!result)
{
put_string("Failed to initialize virtio devices.\n"
"Any virtio devices are disabled\n");
// panic("failed the init_virtio");
}
result = init_timer();
if (!result)
{
panic("failed the init_timer");
}
bool is_vmm_enabled = init_vmm();
if (!is_vmm_enabled)
{
// panic("failed the init_vmm");
put_string("VMM module is disabled\n");
}
// void init_test_thread();
// init_test_thread(kthread_0);
put_string("hello\n");
enable_interrupt();
if(is_vmm_enabled)
{
bool run_test_guest(void);
result = run_test_guest();
if (!result)
{
panic("error occured in run_test_guest\n");
}
}
//void setup_test_guest(virtual_cpu_t * vcpu, uint64_t guest_func);
//virtual_cpu_t *vcpu = alloc_vcpu();
//setup_test_guest(vcpu, (uint64_t)guest_func);
//run_guest(vcpu);
// panic("finish");
while (true)
{
count_main++;
__asm__ volatile("wfi");
}
}