41 lines
1.2 KiB
C
41 lines
1.2 KiB
C
// init.c - first user-mode process
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Syscall stubs
|
|
// ---------------------------------------------------------------------------
|
|
extern uint32_t SysCreateProcess(const char* path, uint32_t* handleOut,
|
|
const char* cmdline);
|
|
extern uint32_t SysCloseHandle(uint32_t handle);
|
|
extern void SysDebugPrint(const char* str);
|
|
extern uint32_t SysWaitForProcess(uint32_t handle);
|
|
extern void SysExitProcess(int code);
|
|
extern void SysYield(void);
|
|
|
|
#define STATUS_SUCCESS 0u
|
|
|
|
void _start()
|
|
{
|
|
uint32_t h = 0;
|
|
uint32_t s = 0;
|
|
|
|
SysDebugPrint("[init] starting shell\n");
|
|
s = SysCreateProcess("shell.exe", &h, NULL);
|
|
if (s != STATUS_SUCCESS) {
|
|
SysDebugPrint("[init] FATAL: failed to start shell.exe\n");
|
|
SysExitProcess(1);
|
|
}
|
|
|
|
SysDebugPrint("[init] waiting for shell\n");
|
|
s = SysWaitForProcess(h);
|
|
if (s != STATUS_SUCCESS)
|
|
SysDebugPrint("[init] WARNING: SysWaitForProcess returned error\n");
|
|
SysCloseHandle(h);
|
|
|
|
SysDebugPrint("[init] done\n");
|
|
|
|
SysExitProcess(0);
|
|
}
|