Skip to content

Commit

Permalink
Maybe final commit before deadline. Swap file is made but PSB is not …
Browse files Browse the repository at this point in the history
…enqueued. Sorry Alan, I couldn't be a winner in the end.
  • Loading branch information
John Paul Welsh committed Dec 9, 2014
1 parent cd675b2 commit 7be08e5
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 17 deletions.
8 changes: 8 additions & 0 deletions dist/scripts/os/memoryManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ var TSOS;
return "god dammit";
}
};

MemoryManager.prototype.getProgCodeFromMem = function (memBlock) {
var memCode = "";
for (var i = 0; i < SEGMENT_SIZE; i++) {
memCode += this.getMemoryFromLocation(memBlock, i);
}
return memCode;
};
return MemoryManager;
})();
TSOS.MemoryManager = MemoryManager;
Expand Down
16 changes: 14 additions & 2 deletions dist/scripts/os/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ var TSOS;
// TODO: use getDataBytesWithLinksKeepHex()
// TODO: dingo
_CurrPCB = _ReadyQueue.peek();
_CurrBlockOfMem = _CurrPCB.MemBlock;
if (_CurrPCB.location == "File System") {
_CurrBlockOfMem = this.moveFromMemToFile(_CurrPCB);
this.moveFromFileToMem(_CurrPCB.swapFileName, _CurrBlockOfMem);
} else {
_CurrBlockOfMem = _CurrPCB.MemBlock;
}
_CurrPCB.State = "Running";
_CPU.updateCPUWithPCBContents();
};
Expand All @@ -103,7 +108,14 @@ var TSOS;

_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]));
_KernelInterruptQueue.enqueue(new TSOS.Interrupt(FILE_SYSTEM_IRQ, [DISK_WRITE, pcb.swapFileName, memCode, true]));

pcb.location = "File System";
pcb.BaseReg = -1;
pcb.LimitReg = -1;

// TODO: not right
return 0;
};

Scheduler.prototype.changeMode = function (newMode) {
Expand Down
5 changes: 3 additions & 2 deletions dist/scripts/os/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,15 @@ spell certain doom for the small band of rebels struggling to restore freedom to
pcb.setSwapFileName(_krnFileSystemDriver.getSwapFileName(pcb.PID));

// ...put it in the Resident Queue...
_ResidentQueue.enqueue(pcb);

//_ResidentQueue.enqueue(pcb);
// ...create the swap file...
_KernelInterruptQueue.enqueue(new TSOS.Interrupt(FILE_SYSTEM_IRQ, [DISK_CREATE, pcb.swapFileName]));

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

_StdOut.putText("Memory is full, so we made a swap file, but it has not been given a PCB.");
}

// ...and print the PID.
Expand Down
13 changes: 10 additions & 3 deletions dist/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ var TSOS;
};

/*
* TODO COMMENTS HERE
* Splits the string into pairs of hex characters, and maps
* a function to each of the pairs that translates it into
* a decimal char code. This is then translated into its
* corresponding ascii character (except for DATA_FILL characters,
* which are left alone).
*/
Utils.charHexStrToAsciiStr = function (hexStr) {
var strArray = this.splitByTwos(hexStr);
Expand All @@ -111,7 +115,9 @@ var TSOS;
};

/*
* TODO: COMMENTS HERE
* Maps a function to every character in the ascii input string,
* which translates the given character into hex (unless it's a
* DATA_FILL character, which are left alone).
*/
Utils.asciiStrToCharHexStr = function (asciiStr) {
var strArray = asciiStr.split("");
Expand Down Expand Up @@ -160,7 +166,8 @@ var TSOS;
};

/*
* TODO: COMMENTS HERE
* Splits a string into pairs of characters. Useful for getting
* program hex code out of a file.
*/
Utils.splitByTwos = function (str) {
var strArray = [];
Expand Down
8 changes: 8 additions & 0 deletions source/scripts/os/memoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,13 @@ module TSOS {
return "god dammit";
}
}

public getProgCodeFromMem(memBlock): string {
var memCode = "";
for (var i = 0; i < SEGMENT_SIZE; i++) {
memCode += this.getMemoryFromLocation(memBlock, i);
}
return memCode;
}
}
}
6 changes: 3 additions & 3 deletions source/scripts/os/processControlBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ module TSOS {
this.location = "File System";
}

this.Priority = (priority != undefined) ? priority : 0;
this.State = "New";
this.Priority = (priority != undefined) ? priority : 0;
this.State = "New";
this.isFinished = false;
}

public getMemBlock(): number {
return this.MemBlock;
}

public setSwapFileName(name) {
public setSwapFileName(name): void {
this.swapFileName = name;
this.location = "File System";
}
Expand Down
18 changes: 15 additions & 3 deletions source/scripts/os/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ module TSOS {
// TODO: dingo

_CurrPCB = _ReadyQueue.peek();
_CurrBlockOfMem = _CurrPCB.MemBlock;
if (_CurrPCB.location == "File System") {
_CurrBlockOfMem = this.moveFromMemToFile(_CurrPCB);
this.moveFromFileToMem(_CurrPCB.swapFileName, _CurrBlockOfMem);
} else {
_CurrBlockOfMem = _CurrPCB.MemBlock;
}
_CurrPCB.State = "Running";
_CPU.updateCPUWithPCBContents();
}
Expand All @@ -110,15 +115,22 @@ module TSOS {
_MemMan.fillMemoryWithProgram(memBlock, fsCodeArray);
}

private moveFromMemToFile(pcb): void {
private moveFromMemToFile(pcb): number {
// 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]));
[DISK_WRITE, pcb.swapFileName, memCode, true]));

pcb.location = "File System";
pcb.BaseReg = -1;
pcb.LimitReg = -1;

// TODO: not right
return 0;
}

public changeMode(newMode): void {
Expand Down
4 changes: 3 additions & 1 deletion source/scripts/os/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ spell certain doom for the small band of rebels struggling to restore freedom to
// ...tell the pcb that it's stuff is in the swap file...
pcb.setSwapFileName(_krnFileSystemDriver.getSwapFileName(pcb.PID));
// ...put it in the Resident Queue...
_ResidentQueue.enqueue(pcb);
//_ResidentQueue.enqueue(pcb);
// ...create the swap file...
_KernelInterruptQueue.enqueue(new Interrupt(FILE_SYSTEM_IRQ,
[DISK_CREATE, pcb.swapFileName]));
Expand All @@ -496,6 +496,8 @@ spell certain doom for the small band of rebels struggling to restore freedom to
_KernelInterruptQueue.enqueue(new Interrupt(FILE_SYSTEM_IRQ,
[DISK_WRITE, pcb.swapFileName, fullProgCode, true]));

_StdOut.putText("Memory is full, so we made a swap file, but it has not been given a PCB.");

}
// ...and print the PID.
_StdOut.putText("PID = " + pcb.PID);
Expand Down
13 changes: 10 additions & 3 deletions source/scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ module TSOS {
}

/*
* TODO COMMENTS HERE
* Splits the string into pairs of hex characters, and maps
* a function to each of the pairs that translates it into
* a decimal char code. This is then translated into its
* corresponding ascii character (except for DATA_FILL characters,
* which are left alone).
*/
public static charHexStrToAsciiStr(hexStr): string {
var strArray = this.splitByTwos(hexStr);
Expand All @@ -112,7 +116,9 @@ module TSOS {
}

/*
* TODO: COMMENTS HERE
* Maps a function to every character in the ascii input string,
* which translates the given character into hex (unless it's a
* DATA_FILL character, which are left alone).
*/
public static asciiStrToCharHexStr(asciiStr): string {
var strArray = asciiStr.split("");
Expand Down Expand Up @@ -161,7 +167,8 @@ module TSOS {
}

/*
* TODO: COMMENTS HERE
* Splits a string into pairs of characters. Useful for getting
* program hex code out of a file.
*/
public static splitByTwos(str): string[] {
var strArray = [];
Expand Down

0 comments on commit 7be08e5

Please sign in to comment.