-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathmain.c
More file actions
141 lines (114 loc) · 2.81 KB
/
main.c
File metadata and controls
141 lines (114 loc) · 2.81 KB
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
/*
* Phoenix-RTOS
*
* Operating system kernel
*
* Kernel initialization
*
* Copyright 2012-2017, 2021 Phoenix Systems
* Copyright 2001, 2005-2006 Pawel Pisarczyk
* Author: Pawel Pisarczyk, Aleksander Kaminski, Hubert Buczynski
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/
#include "hal/hal.h"
#include "usrv.h"
#include "lib/lib.h"
#include "vm/vm.h"
#include "proc/proc.h"
#include "posix/posix.h"
#include "syscalls.h"
#include "syspage.h"
#include "test/test.h"
#include "perf/perf.h"
static struct {
vm_map_t kmap;
vm_object_t kernel;
page_t *page;
void *stack;
size_t stacksz;
} main_common;
static void main_initthr(void *unused)
{
int res;
unsigned int argc;
syspage_prog_t *prog;
char *argv[32], *cmdline;
/* Enable locking and multithreading related mechanisms */
_hal_start();
_usrv_start();
lib_printf("main: Starting syspage programs:");
syspage_progShow();
posix_init();
(void)posix_clone(-1);
/* Start programs from syspage */
prog = syspage_progList();
if (prog != NULL) {
do {
cmdline = prog->argv;
/* If app shouldn't be executed then args should be discarded */
if (*cmdline != 'X') {
while (*cmdline != ';' && *cmdline != '\0') {
++cmdline;
}
*cmdline = '\0';
continue;
}
/* 'X' is no longer useful */
++prog->argv;
cmdline = prog->argv;
argc = 0;
while (argc < (sizeof(argv) / sizeof(*argv) - 1U)) {
argv[argc] = cmdline;
argc++;
while (*cmdline != ';' && *cmdline != '\0') {
++cmdline;
}
if (*cmdline == '\0') {
break;
}
*(cmdline++) = '\0';
}
argv[argc] = NULL;
res = proc_syspageSpawn(prog, vm_getSharedMap((int)prog->imaps[0]), vm_getSharedMap((int)prog->dmaps[0]), argv[0], argv);
if (res < 0) {
lib_printf("main: failed to spawn %s (%d)\n", argv[0], res);
}
} while ((prog = prog->next) != syspage_progList());
}
for (;;) {
proc_reap();
}
}
int main(void)
{
char s[128];
syspage_init();
_hal_init();
_usrv_init();
hal_consolePrint(ATTR_BOLD, "Phoenix-RTOS microkernel v. " RELEASE " rev. " VERSION "\n");
lib_printf("hal: %s\n", hal_cpuInfo(s));
lib_printf("hal: %s\n", hal_cpuFeatures(s, sizeof(s)));
lib_printf("hal: %s\n", hal_interruptsFeatures(s, sizeof(s)));
lib_printf("hal: %s\n", hal_timerFeatures(s, sizeof(s)));
_vm_init(&main_common.kmap, &main_common.kernel);
(void)_perf_init(&main_common.kmap);
(void)_proc_init(&main_common.kmap, &main_common.kernel);
_syscalls_init();
#if 0 /* Basic kernel tests */
/* Start tests */
test_proc_threads1();
test_vm_kmallocsim();
test_proc_conditional();
test_vm_alloc();
test_vm_kmalloc();
test_proc_exit();
#endif
(void)proc_start(main_initthr, NULL, (const char *)"init");
/* Start scheduling, leave current stack */
hal_cpuEnableInterrupts();
(void)hal_cpuReschedule(NULL, NULL);
return 0;
}