BarryServer : Git

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

// Related

Nucleus

Barry Driver core e4c4dfe (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 <string.h>
#include <nucleus/panic.h>
#include <nucleus/memory.h>
#include <nucleus/task.h>
#include <nucleus/vfs.h>
#include "multiboot.h"
#include "desc.h"
#include "acpi/acpi.h"

extern char _bss[], _end[];

/* Per-CPU Setup */
void
cpu_load(void)
{
	/* Initialise SSE */
	asm volatile(
		"mov %cr0, %eax;"
		"andl $0xfffffffb, %eax;"
		"orl $0x2, %eax;"
		"mov %eax, %cr0;"
		"mov %cr4, %eax;"
		"orl $0x600, %eax;"
		"mov %eax, %cr4;"
	);

	/* Initialise CR4.PGE */
	asm volatile(
		"mov %cr4, %eax;"
		"orl $0x10, %eax;"
		"mov %eax, %cr4;"
	);

	/* Tables */
	cpu_load_idt();
	cpu_load_gdt();

	asm volatile("sti");
}

/* 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();

	/* Initialise paging */
	init_paging();
	/* Initialise multitasking */
	init_tasking();
	/* Initialise the VFS */
	init_vfs();
	/* Search ACPI tables */
	init_acpi(ebda);
	init_pci();

	panic("End of kernel!");
}