BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / blob / master / kernel / main.c

// Related

Nucleus

Barry Object manager and heap in kernel library 08afe80 (3 years, 2 months ago)
/*
 * This file contains the entrance point for the Kernel proper.  The code here
 * is called by the bootloader when it finishes.  The kmain routine is
 * responsible for setting up memory and starting the processes running.
 */

#include <stdint.h>
#include <sys/exec.h>
#include <sys/fs.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <nucleus/kernel.h>
#include <nucleus/lib.h>
#include <nucleus/memory.h>
#include <nucleus/task.h>
#include <nucleus/vfs.h>
#include "acpi/acpi.h"
#include "desc.h"
#include "multiboot.h"

extern char _bss[], _end[];
void ipiq_handler(struct InterruptFrame *frame);
void cpu_load(void);

/* Kernel main function */
_Noreturn void
kmain(struct MultibootInfo *mbinfo)
{
	void *ebda = (void *) (*((uint16_t *) 0x040E) << 4);
	memset(_bss, 0, _end - _bss);

	/* Setup frame allocator */
	init_frames(mbinfo->mmapLen, (void *) mbinfo->mmapAddr);

	/* Processor startup */
	init_idt();
	init_pic();
	cpu_load();
	register_ipi(0, ipiq_handler);

	/* Initialise sub-systems */
	init_paging();
	init_tasking();
	init_vfs();
	/* Search ACPI tables */
	init_acpi(ebda);
	init_pci();

	/* Mount drive */
	mkdir("root", 0);
	mount("/dev/hd0", "/root", "ext2fs", MS_RDONLY, NULL);
	chroot("/root");
	chdir("/");
	mount("devfs", "/dev", "devfs", 0, NULL);
	mount("tmpfs", "/tmp", "tmpfs", 0, NULL);

	/* Start init */
	char *argv[] = { "init", NULL };
	execve("/bin/init", argv, NULL);
	panic("Could not run init");
}