tape-kernel 1.0
a modular modern independent kernel
Loading...
Searching...
No Matches
main.c File Reference
#include "../usr/shell.h"
#include "../io/vga.h"
#include "../io/cm.h"
#include "../lib/utils.h"
#include "../mem/heap.h"
#include "../fs/ide.h"
#include "../fs/ffs.h"
#include "../fs/fs.h"
#include "../lib/err.h"
#include "../io/io.h"
#include "../lib/pit.h"
#include "../mem/mem.h"
Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define KHEAP_SIZE   (1024 * 1024)
#define FS_ARENA_SIZE   (256 * 1024)
#define CMD_ARENA_SIZE   (128 * 1024)

Functions

void ___init (void)
 ___init initializes all kernel subsystems
void * malloc (uint32_t size)
 malloc is a gdb friendly wrapper around alc
void ___kmain (uint32_t magic, void *mb_info)
 ___kmain is the main kernel entry point after boot

Variables

static uint8_t kmem [(1024 *1024)]
 description of heap sizes in src/kernel/main.c
arena_t kheap
arena_tfs_arena
 the filesystem child arena
arena_tcmd_arena
 the command processing child arena
static int ___init_called = 0

Macro Definition Documentation

◆ CMD_ARENA_SIZE

#define CMD_ARENA_SIZE   (128 * 1024)

Definition at line 18 of file main.c.

Referenced by ___init().

◆ FS_ARENA_SIZE

#define FS_ARENA_SIZE   (256 * 1024)

Definition at line 17 of file main.c.

Referenced by ___init().

◆ KHEAP_SIZE

#define KHEAP_SIZE   (1024 * 1024)

Definition at line 16 of file main.c.

Function Documentation

◆ ___init()

void ___init ( void )

___init initializes all kernel subsystems

___init is a function that sets up the kernel heap, child arenas, pit timer, ide disk controller, flat filesystem, and filesystem tooling, then runs a full sanity check suite before returning

___init is called once at boot time and will panic if called twice

using ___init is done with

void ___init(void)
___init initializes all kernel subsystems
Definition main.c:86
See also
kmain(), hinit(), ideinit(), fsinit()

Definition at line 86 of file main.c.

References ___init_called, alc, anew, assert, clscr, cmd_arena, CMD_ARENA_SIZE, cnb, cob, ffsinit, fs_arena, FS_ARENA_SIZE, fsdelete, fsfind, fsinit, fsread, fswrite, hcur, hinit, ideinit, inb, irsec, iwrt, kheap, kmem, NULL, panic, pinit, prt, scur, and strcmp().

Referenced by ___kmain().

◆ ___kmain()

void ___kmain ( uint32_t magic,
void * mb_info )

___kmain is the main kernel entry point after boot

___kmain is a function called by the multiboot bootloader that verifies the multiboot magic, runs kernel initialization, and enters the infinite interactive shell loop

Parameters
magic,themultiboot magic number (should be 0x2BADB002)
mb_info,apointer to the multiboot information structure

using ___kmain is done with

//called from boot.s with multiboot info:
___kmain(0x2BADB002, multiboot_info_ptr);
void ___kmain(uint32_t magic, void *mb_info)
___kmain is the main kernel entry point after boot
Definition main.c:270
See also
___init(), boot.s, shell()

Definition at line 270 of file main.c.

References ___init(), NORETURN, panic, and shell.

◆ malloc()

void * malloc ( uint32_t size)

malloc is a gdb friendly wrapper around alc

malloc is a function that allocates memory from the main kernel heap, it exists primarily for gdb compatibility

Parameters
size,thenumber of bytes to allocate
Warning
when writing kernel code, use alc directly instead of malloc, since malloc is only a thin wrapper for debugging
See also
alc(), kheap

Definition at line 249 of file main.c.

References alc, and kheap.

Variable Documentation

◆ ___init_called

int ___init_called = 0
static

Definition at line 68 of file main.c.

Referenced by ___init().

◆ cmd_arena

arena_t* cmd_arena

the command processing child arena

cmd_arena is a 128kb arena allocated from kheap and reset before each shell command to provide temporary scratch space

See also
kheap, fs_arena, res()

Definition at line 66 of file main.c.

Referenced by ___init(), __shell(), and cmd_alloc().

◆ fs_arena

arena_t* fs_arena

the filesystem child arena

fs_arena is a 256kb arena allocated from kheap and used for filesystem operations like storing filenames and file data

See also
kheap, cmd_arena, anew()

Definition at line 56 of file main.c.

Referenced by ___init(), cmd_writefile(), and editor_save().

◆ kheap

arena_t kheap

Definition at line 46 of file main.c.

Referenced by ___init(), and malloc().

◆ kmem

uint8_t kmem[(1024 *1024)]
static

description of heap sizes in src/kernel/main.c

there are 3 heaps in the kernel, kheap (kernel heap) with childs of fs_arena (filesystem arena) and cmd_arena (command arena) kheap is 1mb total fs_arena is 256kb from kheap cmd_arena is 128kb from kheap

this leaves 640kb~ of space in kheap

See also
hinit(), anew(), res(), and alc()

the main kernel heap

kheap is the primary 1mb arena that all kernel allocations come from, child arenas are carved out of this heap

See also
fs_arena, cmd_arena, hinit(), alc()

Definition at line 45 of file main.c.

Referenced by ___init().