Skip to content

Commit

Permalink
Updated readme with note about setschedule; more progress on moving c…
Browse files Browse the repository at this point in the history
…ode to/from files
  • Loading branch information
John Paul Welsh committed Dec 9, 2014
1 parent d102d71 commit cd675b2
Show file tree
Hide file tree
Showing 12 changed files with 178 additions and 76 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ See https://github.com/labouseur/TSOS-2014 for full readme.
Notes for Alan (and others who are interested)
==============================================

(12-09-2014) To test setschedule, please change the schedule before loading programs. There's a bug where the scheduler insists on being Round Robin if there are already programs loaded in before you run setschedule.

(10-29-2014) To distinguish between fixes from Project 2 and new stuff for Project 3, the following is a breakdown of where my Project 2 fixes took place.

Running a program was fixed at this commit. I also added support for an interrupt being thrown when encountering an invalid opcode. This interrupt also ends the program: https://github.com/johnpaulwelsh/jip-os/commit/9c01ecae32a25e3d4fc2af23aaff878a3e82de75 .
Expand All @@ -23,6 +25,5 @@ Console scrolling was fixed at this commit: https://github.com/johnpaulwelsh/jip

Caret symbol (^) was fixed at this commit: https://github.com/johnpaulwelsh/jip-os/commit/702152264c24500303dfda7fe8de05c2a34c22bf (please ignore the code for line wrapping at this commit: it was really bad and I removed it the very next commit).


(9-23-2014) Some would say that command history (with up and down arrow keys) is buggy,
but I prefer to think of it as having unique features.
29 changes: 15 additions & 14 deletions dist/scripts/host/fileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var TSOS;
this.DATA_FILL = "~";
this.TSB_FILL = "*";
this.TSB_FILL_FULL = "***";
this.PROG_DATA_FILL = "00";
this.DATA_BEGIN = 4;
this.metaBytes = 4;
this.dataBytes = 120;
Expand Down Expand Up @@ -111,7 +112,7 @@ var TSOS;
data[1] = this.TSB_FILL;
data[2] = this.TSB_FILL;
data[3] = this.TSB_FILL;
for (var i = 4; i < this.dataBytes; i++) {
for (var i = 4; i < (this.metaBytes + this.dataBytes); i++) {
data[i] = this.DATA_FILL;
}

Expand Down Expand Up @@ -318,9 +319,9 @@ var TSOS;

var realFinalData;
if (isProgCode) {
realFinalData = this.enforceDataLength(dataArray.join(""));
realFinalData = this.enforceDataLength(finalData);
} else {
realFinalData = this.enforceDataLength(TSOS.Utils.asciiStrToCharHexStr(dataArray.join("")));
realFinalData = this.enforceDataLength(TSOS.Utils.asciiStrToCharHexStr(finalData));
}

this.setItem(myTSB, realFinalData);
Expand Down Expand Up @@ -360,14 +361,23 @@ var TSOS;

FileSystem.prototype.setDataBytesBlank = function (tsb) {
var data = this.getItem(tsb).split("");
for (var i = 4; i < this.dataBytes; i++) {
for (var i = 4; i < (this.metaBytes + this.dataBytes); i++) {
data[i] = this.DATA_FILL;
}
this.setItem(tsb, data.join(""));
};

/*
* Uses the above and below functions to set an entry blank, but
* Sets an entire entry to be blank.
*/
FileSystem.prototype.setFullBlank = function (tsb) {
this.setIsUsedByte(tsb, "0");
this.setTSBBytesBlank(tsb);
this.setDataBytesBlank(tsb);
};

/*
* Uses the above functions to set an entry blank, but
* follows the chain of linked entries if it needs to.
*/
FileSystem.prototype.setDataBytesWithLinksBlank = function (tsb) {
Expand All @@ -377,15 +387,6 @@ var TSOS;
}
this.setFullBlank(tsb);
};

/*
* Sets an entire entry to be blank.
*/
FileSystem.prototype.setFullBlank = function (tsb) {
this.setIsUsedByte(tsb, "0");
this.setTSBBytesBlank(tsb);
this.setDataBytesBlank(tsb);
};
return FileSystem;
})();
TSOS.FileSystem = FileSystem;
Expand Down
11 changes: 11 additions & 0 deletions dist/scripts/os/memoryManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ var TSOS;
currBlock[loc] = newCodeHex;
TSOS.Control.updateMemTableAtLoc(blockNum, Math.floor(loc / 8), loc % 8, newCodeHex);
};

MemoryManager.prototype.getProgCodeFromFS = function (fileName) {
var tsbWithName = _FileSystem.getDirectoryWithName(fileName);
if (tsbWithName != undefined) {
var dataTSB = _FileSystem.getTSBBytes(tsbWithName);
return _FileSystem.getDataBytesWithLinksKeepHex(dataTSB).replace(/~/g, "");
} else {
_StdOut.putText("This should never happen");
return "god dammit";
}
};
return MemoryManager;
})();
TSOS.MemoryManager = MemoryManager;
Expand Down
14 changes: 14 additions & 0 deletions dist/scripts/os/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ var TSOS;
_CPU.updateCPUWithPCBContents();
};

Scheduler.prototype.moveFromFileToMem = function (fileName, memBlock) {
var fsCodeArray = TSOS.Utils.splitByTwos(_MemMan.getProgCodeFromFS(fileName));
_MemMan.fillMemoryWithProgram(memBlock, fsCodeArray);
};

Scheduler.prototype.moveFromMemToFile = function (pcb) {
// TODO: finish this
var memCode = "";

_KernelInterruptQueue.enqueue(new TSOS.Interrupt(FILE_SYSTEM_IRQ, [DISK_CREATE, pcb.swapFileName]));

_KernelInterruptQueue.enqueue(new TSOS.Interrupt(FILE_SYSTEM_IRQ, [DISK_WRITE, pcb.swapFileName, _ProgInput.join(""), true]));
};

Scheduler.prototype.changeMode = function (newMode) {
this.Mode = newMode;
};
Expand Down
7 changes: 4 additions & 3 deletions dist/scripts/os/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,8 @@ spell certain doom for the small band of rebels struggling to restore freedom to
_KernelInterruptQueue.enqueue(new TSOS.Interrupt(FILE_SYSTEM_IRQ, [DISK_CREATE, pcb.swapFileName]));

// ...fill the file with the program code...
_KernelInterruptQueue.enqueue(new TSOS.Interrupt(FILE_SYSTEM_IRQ, [DISK_WRITE, pcb.swapFileName, _ProgInput.join(""), true]));
var fullProgCode = TSOS.Utils.padProgCodeWithBlanks(_ProgInput).join("");
_KernelInterruptQueue.enqueue(new TSOS.Interrupt(FILE_SYSTEM_IRQ, [DISK_WRITE, pcb.swapFileName, fullProgCode, true]));
}

// ...and print the PID.
Expand Down Expand Up @@ -546,10 +547,10 @@ spell certain doom for the small band of rebels struggling to restore freedom to
_Scheduler.changeMode(ROUND_ROBIN);
break;
case "fcfs":
_Scheduler.changeMode(ROUND_ROBIN);
_Scheduler.changeMode(FCFS);
break;
case "priority":
_Scheduler.changeMode(ROUND_ROBIN);
_Scheduler.changeMode(PRIORITY);
break;
default:
_StdOut.putText("Invalid scheduling algorithm. Choose another.");
Expand Down
58 changes: 40 additions & 18 deletions dist/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,11 @@ var TSOS;
return decNum.toString(16);
};

/*
* TODO COMMENTS HERE
*/
Utils.charHexStrToAsciiStr = function (hexStr) {
var strArray = [];
var i = 0;
while (i < hexStr.length) {
if (hexStr.charAt(i) == _FileSystem.DATA_FILL) {
strArray.push(hexStr.substr(i, 1));
i += 1;
} else {
strArray.push(hexStr.substr(i, 2));
i += 2;
}
}
var strArray = this.splitByTwos(hexStr);

strArray = strArray.map(function (hex) {
var decCharCode = Utils.hexStrToDecNum(hex);
Expand All @@ -117,6 +110,9 @@ var TSOS;
return strArray.join("");
};

/*
* TODO: COMMENTS HERE
*/
Utils.asciiStrToCharHexStr = function (asciiStr) {
var strArray = asciiStr.split("");
strArray = strArray.map(function (ascii) {
Expand All @@ -136,13 +132,14 @@ var TSOS;
return strArray.join("");
};

// The regular isNaN function will trigger as false if our opcode has a digit as its
// first character, and those opcodes that do all have a 'D' in them as the second character.
// We override isNaN so that when it comes across '6D' or '8D', it knows it isn't a number.
// We also have a situation where 00 can be a number (for memory) or a string (for the system
// call). So we also want to give back 00 as a string by default, and then parseInt on it once
// we know it isn't an opcode. We also parseInt on the outside, to make sure that 00 is a number
// exactly when we need it to be.
/* The regular isNaN function will trigger as false if our opcode has a digit as its
* first character, and those opcodes that do all have a 'D' in them as the second character.
* We override isNaN so that when it comes across '6D' or '8D', it knows it isn't a number.
* We also have a situation where 00 can be a number (for memory) or a string (for the system
* call). So we also want to give back 00 as a string by default, and then parseInt on it once
* we know it isn't an opcode. We also parseInt on the outside, to make sure that 00 is a number
* exactly when we need it to be.
*/
Utils.isNaNOverride = function (val) {
return (val[1] === "D" || val === "00" || isNaN(val));
};
Expand All @@ -154,6 +151,31 @@ var TSOS;
Utils.contains = function (str, subStr) {
return (str.indexOf(subStr) > -1);
};

Utils.padProgCodeWithBlanks = function (codeArray) {
for (var i = codeArray.length; i < 255; i++) {
codeArray.push("00");
}
return codeArray;
};

/*
* TODO: COMMENTS HERE
*/
Utils.splitByTwos = function (str) {
var strArray = [];
var i = 0;
while (i < str.length) {
if (str.charAt(i) == _FileSystem.DATA_FILL) {
strArray.push(str.substr(i, 1));
i += 1;
} else {
strArray.push(str.substr(i, 2));
i += 2;
}
}
return strArray;
};
return Utils;
})();
TSOS.Utils = Utils;
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
</label>
</div>

<div id="divReadyQueueDisplay" class="pageDivs" style="width: 430px;">
<div id="divReadyQueueDisplay" class="pageDivs" style="width: 450px;">
<label>
Ready Queue
<br>
Expand Down
35 changes: 18 additions & 17 deletions source/scripts/host/fileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
module TSOS {
export class FileSystem {

DATA_FILL: string = "~";
TSB_FILL: string = "*";
TSB_FILL_FULL: string = "***";
DATA_FILL: string = "~";
TSB_FILL: string = "*";
TSB_FILL_FULL: string = "***";
PROG_DATA_FILL: string = "00";

DATA_BEGIN: number = 4;

Expand Down Expand Up @@ -120,7 +121,7 @@ module TSOS {
data[1] = this.TSB_FILL;
data[2] = this.TSB_FILL;
data[3] = this.TSB_FILL;
for (var i = 4; i < this.dataBytes; i++) {
for (var i = 4; i < (this.metaBytes + this.dataBytes); i++) {
data[i] = this.DATA_FILL;
}

Expand Down Expand Up @@ -340,9 +341,9 @@ module TSOS {

var realFinalData;
if (isProgCode) {
realFinalData = this.enforceDataLength(dataArray.join(""));
realFinalData = this.enforceDataLength(finalData);
} else {
realFinalData = this.enforceDataLength(Utils.asciiStrToCharHexStr(dataArray.join("")));
realFinalData = this.enforceDataLength(Utils.asciiStrToCharHexStr(finalData));
}

this.setItem(myTSB, realFinalData);
Expand Down Expand Up @@ -385,14 +386,23 @@ module TSOS {

public setDataBytesBlank(tsb) {
var data = this.getItem(tsb).split("");
for (var i = 4; i < this.dataBytes; i++) {
for (var i = 4; i < (this.metaBytes + this.dataBytes); i++) {
data[i] = this.DATA_FILL;
}
this.setItem(tsb, data.join(""));
}

/*
* Uses the above and below functions to set an entry blank, but
* Sets an entire entry to be blank.
*/
public setFullBlank(tsb) {
this.setIsUsedByte(tsb, "0");
this.setTSBBytesBlank(tsb);
this.setDataBytesBlank(tsb);
}

/*
* Uses the above functions to set an entry blank, but
* follows the chain of linked entries if it needs to.
*/
public setDataBytesWithLinksBlank(tsb) {
Expand All @@ -402,14 +412,5 @@ module TSOS {
}
this.setFullBlank(tsb);
}

/*
* Sets an entire entry to be blank.
*/
public setFullBlank(tsb) {
this.setIsUsedByte(tsb, "0");
this.setTSBBytesBlank(tsb);
this.setDataBytesBlank(tsb);
}
}
}
11 changes: 11 additions & 0 deletions source/scripts/os/memoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,16 @@ module TSOS {
currBlock[loc] = newCodeHex;
Control.updateMemTableAtLoc(blockNum, Math.floor(loc / 8), loc % 8, newCodeHex);
}

public getProgCodeFromFS(fileName): string {
var tsbWithName = _FileSystem.getDirectoryWithName(fileName);
if (tsbWithName != undefined) {
var dataTSB = _FileSystem.getTSBBytes(tsbWithName);
return _FileSystem.getDataBytesWithLinksKeepHex(dataTSB).replace(/~/g, "");
} else {
_StdOut.putText("This should never happen");
return "god dammit";
}
}
}
}
16 changes: 16 additions & 0 deletions source/scripts/os/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ module TSOS {
_CPU.updateCPUWithPCBContents();
}

private moveFromFileToMem(fileName, memBlock): void {
var fsCodeArray = Utils.splitByTwos(_MemMan.getProgCodeFromFS(fileName));
_MemMan.fillMemoryWithProgram(memBlock, fsCodeArray);
}

private moveFromMemToFile(pcb): void {
// TODO: finish this
var memCode = "";

_KernelInterruptQueue.enqueue(new Interrupt(FILE_SYSTEM_IRQ,
[DISK_CREATE, pcb.swapFileName]));

_KernelInterruptQueue.enqueue(new Interrupt(FILE_SYSTEM_IRQ,
[DISK_WRITE, pcb.swapFileName, _ProgInput.join(""), true]));
}

public changeMode(newMode): void {
this.Mode = newMode;
}
Expand Down
10 changes: 6 additions & 4 deletions source/scripts/os/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,12 @@ spell certain doom for the small band of rebels struggling to restore freedom to
_ResidentQueue.enqueue(pcb);
// ...create the swap file...
_KernelInterruptQueue.enqueue(new Interrupt(FILE_SYSTEM_IRQ,
[DISK_CREATE, pcb.swapFileName]));
[DISK_CREATE, pcb.swapFileName]));
// ...fill the file with the program code...
var fullProgCode = Utils.padProgCodeWithBlanks(_ProgInput).join("");
_KernelInterruptQueue.enqueue(new Interrupt(FILE_SYSTEM_IRQ,
[DISK_WRITE, pcb.swapFileName, _ProgInput.join(""), true]));
[DISK_WRITE, pcb.swapFileName, fullProgCode, true]));

}
// ...and print the PID.
_StdOut.putText("PID = " + pcb.PID);
Expand Down Expand Up @@ -608,10 +610,10 @@ spell certain doom for the small band of rebels struggling to restore freedom to
_Scheduler.changeMode(ROUND_ROBIN);
break;
case "fcfs":
_Scheduler.changeMode(ROUND_ROBIN);
_Scheduler.changeMode(FCFS);
break;
case "priority":
_Scheduler.changeMode(ROUND_ROBIN);
_Scheduler.changeMode(PRIORITY);
break;
default:
_StdOut.putText("Invalid scheduling algorithm. Choose another.");
Expand Down
Loading

0 comments on commit cd675b2

Please sign in to comment.