summaryrefslogtreecommitdiff
path: root/src/user/bootstrap/main.c
blob: d27da39b8eb0fcba0b568887d04ac3ad16c87d70 (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
38
39
40
41
42
43
#include <_proc.h>
#include <camellia/flags.h>
#include <camellia/syscalls.h>
#include <stdio.h>
#include <string.h>
#include <elfload.h>
#include <camellia/fs/misc.h>

#include "tar.h"

extern char _bss_start;
extern char _bss_end;
extern char _initrd;

__attribute__((section(".text")))
int main(void) {
	_sys_memflag(_psdata_loc, 1, MEMFLAG_PRESENT);
	setprogname("bootstrap");

	_sys_mount(HANDLE_PROCFS, "/proc/", strlen("/proc/"));
	MOUNT_AT("/") {
		fs_dirinject2((const char*[]) {
			"/proc/",
			"/init/",
			NULL
		});
	}
	MOUNT_AT("/init/") {
		tar_driver(&_initrd);
	}

	const char *initpath = "bin/amd64/init";
	char *initargv[] = {"init", NULL};
	void *init = tar_find(initpath, strlen(initpath), &_initrd, ~0) + 512;
	if (init) {
		_klogf("execing init");
		elf_exec(init, initargv, NULL);
		_klogf("elf_exec failed");
	} else {
		_klogf("couldn't find init.elf");
	}
	_sys_exit(1);
}