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

Go to the source code of this file.

Functions

static void show_help (void)
 displays shell help
static void cmd_writefile (const char *name, const char *msg)
 cmd_writefile writes a text message to a new file
static void cmd_readfile (const char *name)
 cmd_readfile reads and displays a files contents
static void cmd_alloc (uint32_t size)
 cmd_alloc allocates memory from the command arena
void __shell (void *mb_info)
 shell is the interactive kernel command shell

Variables

arena_tcmd_arena
 the command processing child arena
arena_tfs_arena
 the filesystem child arena

Function Documentation

◆ __shell()

void __shell ( void * mb_info)

shell is the interactive kernel command shell

shell is a function that runs an infinite loop displaying the tape prompt and processing user commands

Parameters
mb_info,themultiboot info pointer passed from kmain for memory queries

shell supports the following commands: help, clear, ls, read, write, rm, echo, reboot, alloc, heap, panic, and info

using shell is done with

#include "../usr/shell.h" //or just shell.h
shell(mb_info);
#define shell
Definition shell.h:4
See also
kmain(), show_help(), cmd_arena

Definition at line 182 of file shell.c.

References atoi(), clscr, cmd_alloc(), cmd_arena, cmd_readfile(), cmd_writefile(), cnb, cob, disksize, editor, fsdelete, fsfind, fslist, getcpu, lines, MAX_ARGS, memsize, NORETURN, panic, pargs(), prt, prtd, prth, rdln, reboot, res, scrl, show_help(), strcmp(), and strlen().

◆ cmd_alloc()

void cmd_alloc ( uint32_t size)
static

cmd_alloc allocates memory from the command arena

cmd_alloc is a static function that allocates a block of memory from cmd_arena and prints the resulting pointer address

Parameters
size,thenumber of bytes to allocate (defaults to 100)
See also
alc(), cmd_arena, res()

Definition at line 145 of file shell.c.

References alc, cmd_arena, cnb, cob, prt, prtd, and prth.

Referenced by __shell().

◆ cmd_readfile()

void cmd_readfile ( const char * name)
static

cmd_readfile reads and displays a files contents

cmd_readfile is a static function that looks up a file on disk by name and prints its contents to the screen

Parameters
name,thename of the file to read
See also
cmd_writefile(), fsread()

Definition at line 97 of file shell.c.

References cnb, cob, fsfind, irsec, lines, and prt.

Referenced by __shell().

◆ cmd_writefile()

void cmd_writefile ( const char * name,
const char * msg )
static

cmd_writefile writes a text message to a new file

cmd_writefile is a static function that creates a new file with a given name and fills it with the provided text content

Parameters
name,thename of the file to create
msg,thetext content to write
See also
cmd_readfile(), fswrite(), fsadd()

Definition at line 68 of file shell.c.

References cnb, cob, fs_arena, fsadd, fsnextlba, iwrt, and prt.

Referenced by __shell().

◆ show_help()

void show_help ( void )
static

displays shell help

the show_help() internal function of shell.c displays kernel help adding help should be done with:

clscr(); //clear screen
int row = 0;
prt(0, row++, "tape kernel commands:", 0x01);
prt(0, row++, "help - this message", 0x0F);
(existing prints)
prt(0, row++, "mycmd [myint] - my description", 0x0F) //YOUR actual help message
row++; //increment cursor so help doesnt overwrite
cob(0, row++); set cursor
#define cob
Definition cm.h:7
#define prt
Definition vga.h:6
#define clscr
Definition vga.h:7

please use variable naming convention of '[param]' for ints and '' for strings

Definition at line 38 of file shell.c.

References clscr, cob, and prt.

Referenced by __shell().

Variable Documentation

◆ cmd_arena

arena_t* cmd_arena
extern

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
extern

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().