jsos

college code for operating system fundamentals in js

git clone https://9o.is/git/jsos.git

commit e9c43ef362397273cf53d5606b3a7ea2927abb27
parent 013fe1ff6ed79bac502da8fe0a2129e9c67313c7
Author: Jul <jul@9o.is>
Date:   Sun, 25 Nov 2012 20:46:47 -0500

Able to show or set cpu scheduler. (fcfs & priority not implemented yet)

Diffstat:
Mglobals.js | 9+++++++++
Mscripts/os/shell.js | 147++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 151 insertions(+), 5 deletions(-)

diff --git a/globals.js b/globals.js @@ -32,6 +32,8 @@ var _OSclock = 0; // Page 23. var _Memory = null; +var _Disk = null; + var _Mode = 0; // 0 = Kernel Mode, 1 = User Mode. See page 21. // TODO: Fix the naming convention for these next five global vars. @@ -74,6 +76,7 @@ var _SarcasticMode = false; // Global Device Driver Objects - page 12 // var krnKeyboardDriver = null; +var krnFilesystemDriver = null; // memory size var TOTAL_PAGES = 4; @@ -93,5 +96,11 @@ var _ERROR_INVALID_OPERATOR = _ERROR+"INVALID OPERATOR"; var _ERROR_STACK_OVERFLOW = _ERROR+"STACK OVERFLOW"; var _ERROR_INVALID_BYTE_VALUE = _ERROR+"INVALID BYTE VALUE"; +// cpu scheduling +var CPU_STATE_RR = {name:"Round Robin", abbr:"rr"}; +var CPU_STATE_FCFS = {name:"First Come First Serve", abbr:"fcfs"}; +var CPU_STATE_PRIORITY = {name:"Non-preemptive Priority",abbr:"priority"}; +var CPU_STATE = CPU_STATE_RR.name; + // Round Robin Quantum var RR_QUANTUM = 6; diff --git a/scripts/os/shell.js b/scripts/os/shell.js @@ -159,6 +159,62 @@ function shellInit() sc.function = shellKill; this.commandList[this.commandList.length] = sc; + // create + sc = new ShellCommand(); + sc.command = "create"; + sc.description = "- Creates a new file in the filesystem."; + sc.function = shellCreate; + this.commandList[this.commandList.length] = sc; + + // read + sc = new ShellCommand(); + sc.command = "read"; + sc.description = "- Reads a file in the filesystem."; + sc.function = shellRead; + this.commandList[this.commandList.length] = sc; + + // write + sc = new ShellCommand(); + sc.command = "write"; + sc.description = "- Writes text to file in the filesystem."; + sc.function = shellWrite; + this.commandList[this.commandList.length] = sc; + + // delete + sc = new ShellCommand(); + sc.command = "delete"; + sc.description = "- Deletes a file in the filesystem."; + sc.function = shellDelete; + this.commandList[this.commandList.length] = sc; + + // format + sc = new ShellCommand(); + sc.command = "format"; + sc.description = "- Formats entire filesystem."; + sc.function = shellFormat; + this.commandList[this.commandList.length] = sc; + + // ls + sc = new ShellCommand(); + sc.command = "ls"; + sc.description = "- Lists the files currently stored on disk."; + sc.function = shellLs; + this.commandList[this.commandList.length] = sc; + + // setcpu + sc = new ShellCommand(); + sc.command = "setcpu"; + sc.description = "- Set cpu scheduling to rr, fcfs or priority."; + sc.function = shellSetcpu; + this.commandList[this.commandList.length] = sc; + + // whatcpu + sc = new ShellCommand(); + sc.command = "whatcpu"; + sc.description = "- Shows the currently running cpu schedule."; + sc.function = shellWhatcpu; + this.commandList[this.commandList.length] = sc; + // // Display the initial prompt. this.putPrompt(); @@ -560,14 +616,15 @@ function shellReset(args) { * Sets the Round-Robin quantum. */ function shellRRQuantum(args) { - var newQuantum = args[0].trim(); - console.log(newQuantum); - if(newQuantum == undefined) + var newQuantum = args[0]; + if(newQuantum == undefined) { _StdOut.putText("Usage: rrquantum <quantum number>"); - else if(!isInt(newQuantum)) + _Console.advanceLine(); + _StdOut.putText("Current Quantum: "+RR_QUANTUM); + } else if(!isInt(newQuantum.trim())) _StdOut.putText("Invalid quantum value."); else { - RR_QUANTUM = parseInt(newQuantum); + RR_QUANTUM = newQuantum.trim(); _StdOut.putText("Round-Robin Quantum set to "+RR_QUANTUM); } } @@ -606,3 +663,83 @@ function shellKill(args) { } } } + +/* + * Creates a new file. + */ +function shellCreate(args) { + var filename = args[0]; + // TODO +} + +/* + * Reads a file. + */ +function shellRead(args) { + var filename = args[0]; + // TODO +} + +/* + * Writes data to a file. + */ +function shellWrite(args) { + var filename = args[0]; + var data = args[1]; + // TODO +} + +/* + * Deletes a file. + */ +function shellDelete(args) { + var filename = args[0]; + // TODO +} + +/* + * Formats the entire filesystem. + */ +function shellFormat(args) { + // TODO +} + +/* + * Lists the files currently stored on disk. + */ +function shellLs(args) { + // TODO +} + +/* + * Set cpu scheduling to rr, fcfs or priority. + */ +function shellSetcpu(args) { + function setScheduler(schedule) { + CPU_STATE = schedule; + _StdOut.putText("CPU Scheduler set to "+schedule); + } + + var scheduling = args[0]; + + if(scheduling == undefined) + _StdOut.putText("Usage: setcpu <scheduler (rr, fcfs, priority)>"); + else { + scheduling = scheduling.trim().toLowerCase(); + if(CPU_STATE_RR.abbr == scheduling) + setScheduler(CPU_STATE_RR.name); + else if(CPU_STATE_FCFS.abbr == scheduling) + setScheduler(CPU_STATE_FCFS.name); + else if(CPU_STATE_PRIORITY.abbr == scheduling) + setScheduler(CPU_STATE_PRIORITY.name); + else + _StdOut.putText("Invalid. Values: rr, fcfs, priority"); + } +} + +/* + * Shows the currently running cpu scheduling. + */ +function shellWhatcpu(args) { + _StdOut.putText("CPU Scheduler set to "+CPU_STATE); +}