Skip to content

Commit e5c80b5

Browse files
committed
Kernel now starts a separate 'init' program
The 'init' program is the root process that is started by the kernel. A separate 'init' program allows 'complex' child processes to fail and call abort(), which was not possible if they where themselves the root process.
1 parent e10a9bf commit e5c80b5

File tree

6 files changed

+56
-11
lines changed

6 files changed

+56
-11
lines changed

include/x86/asm/mos.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060

6161
%define BOOT1_FILE "BOOT1 FLT"
6262
%define KERNEL_FILE "KERNEL FLT"
63+
%define INIT_FILE "INIT FLT"
6364
%ifdef GRAPHICS_MODE_ENABLED
6465
%define GUI0_APP_FILE "GUI0 FLT"
6566
%else

src/apps/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,31 @@ link(
6161
LINK_LIBRARIES cm
6262
)
6363

64+
# ---------------------------------------------------------------------------
65+
# Program - INIT
66+
# ---------------------------------------------------------------------------
67+
compile_lib(
68+
NAME init
69+
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/init.c
70+
FLAGS ${MOS_USER_GCC_FLAGS}
71+
DEFINITIONS ${MOS_USER_GCC_DEFINITIONS} DEBUG PORT_E9_ENABLED
72+
INCLUDE_DIRECTORIES ${MOS_USER_GCC_INCLUDE_DIRS}
73+
)
74+
75+
link(
76+
FLATTEN
77+
NAME init.flt
78+
DEPENDS init crta
79+
FLAGS ${MOS_LINKER_OPTIONS}
80+
LINKER_FILE ${MOS_USER_LINKER_SCRIPT_FILE}
81+
LINK_LIBRARIES cm
82+
)
83+
6484
#---------------------------------------------------------------------------
6585
# Add to the global 'build-all' target
6686
#---------------------------------------------------------------------------
87+
add_dependencies(build-all init.flt)
88+
6789
if (MOS_GRAPHICS_ENABLED)
6890
add_dependencies(build-all gui0.flt)
6991
else()

src/apps/init.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* -------------------------------------------------------------------------------------------------
3+
* Megha Operating System V2 - Application - Init program
4+
* -------------------------------------------------------------------------------------------------
5+
*/
6+
7+
#include <cm.h>
8+
#include <debug.h>
9+
10+
static void init_child_killed (OSIF_ProcessEvent const* const e)
11+
{
12+
#if defined(DEBUG) && defined(PORT_E9_ENABLED)
13+
CM_DBG_INFO ("Child process exited. Code: %x", e->data);
14+
#else
15+
(void)e;
16+
#endif
17+
}
18+
19+
void proc_main()
20+
{
21+
cm_process_register_event_handler (OSIF_PROCESS_EVENT_PROCCESS_CHILD_KILLED, init_child_killed);
22+
23+
cm_process_create ("MPDEMO.FLT", false);
24+
while (1) {
25+
cm_process_handle_events();
26+
}
27+
28+
// Should not return!
29+
// TODO: Place an assert() or panic() here.
30+
CM_DBG_ERROR ("Init process returning");
31+
}

src/apps/mpdemo.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ void proc_main()
8484
wait_for_all_child_exit();
8585

8686
cm_process_kill(1);
87-
s_printString (37, 0, BLACK, WHITE,
88-
"Cannot kill process 0. Make kernel thread slower for demo.");
8987
}
9088

9189
void thread0()

src/bootloader/x86/boot1/boot1.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ files: db KERNEL_FILE , "KERNEL.FLT",0,0,0
4141
db PROC1_FILE , "PROC1.FLT",0,0,0,0
4242
db MPDEMO_FILE , "MPDEMO.FLT",0,0,0
4343
%endif
44+
db INIT_FILE , "INIT.FLT",0,0,0,0,0
4445
db 0
4546

4647
msg_welcome: db 13,10,OS_NAME,13,10

src/kernel/x86/kernel.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,7 @@ static void run_root_process()
220220
{
221221
FUNC_ENTRY();
222222

223-
#ifdef GRAPHICS_MODE_ENABLED
224-
BootFileItem fileinfo = kboot_findBootFileItem("GUI0.FLT");
225-
#else
226-
#ifdef MPDEMO
227-
BootFileItem fileinfo = kboot_findBootFileItem("MPDEMO.FLT");
228-
#else
229-
BootFileItem fileinfo = kboot_findBootFileItem("PROC1.FLT");
230-
#endif // MPDEMO
231-
#endif // GRAPHICS_MODE_ENABLED
223+
BootFileItem fileinfo = kboot_findBootFileItem("INIT.FLT");
232224

233225
Physical startAddress = PHYSICAL (fileinfo.startLocation);
234226
SIZE lengthBytes = (SIZE)fileinfo.length;

0 commit comments

Comments
 (0)