Widget:SecondPageTableDemo: Difference between revisions

From COMP15212 Wiki
gravatar Yuron [userbureaucratinterface-adminsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPmludGVyZmFjZS1hZG1pbjxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
m (1 revision imported)
gravatar W81054ch [userbureaucratinterface-adminsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPmludGVyZmFjZS1hZG1pbjxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
m (1 revision imported)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<noinclude>
<noinclude>
This demonstration demonstrates the operation of a Two-level Page Table.
This demonstration demonstrates the operation of a Two-level Page Table.
[{{canonicalurl:Special:ShowWidget|widget=SecondPageTableDemo}} Dark-mode widget for embedding]
{{#widget:SecondPageTableDemo}}
{{#widget:SecondPageTableDemo}}
</noinclude>
</noinclude>
<includeonly>
<includeonly>
<div id="twoLevelPageTable">
<p><canvas id="page_2_canvas" width="920" height="770"></canvas></p>
<p><canvas id="page_2_canvas" width="920" height="770"></canvas></p>
<h4 id = 'mapping1'>Virtual Address in binary (8 bits)</h4>
<h4 id = 'mapping1'>Virtual Address in binary (8 bits)</h4>
<h4 id = 'mapping2'>Virtual Address = L1 PageTable index (2 bits) + L2 PageTable index (2 bits) + Offset (4 bits)</h4>
<h4 id = 'mapping2'>Virtual Address = L1 PageTable index (2 bits) + L2 PageTable index (2 bits) + Offset (4 bits)</h4>
<h4 id = 'mapping3'>Physical Address in binary (8 bits)</h4>
<h4 id = 'mapping3'>Physical Address in binary (8 bits)</h4>
</div>


<script>
<script>
var ctx = document.getElementById('page_2_canvas').getContext('2d');
// Set to use dark theme if the body's background color is too dark
var bodyColour = window.getComputedStyle(document.querySelector('body')).getPropertyValue("background-color").match(/rgba?\((.*)\)/)[1].split(',').map(Number);
var usingDarkTheme;
if (bodyColour[3] === 0)
    usingDarkTheme = false;
else
    usingDarkTheme = bodyColour.reduce((a, b) => a + b, 0) < 255 * 1.5;
   
// Mouse position
// Mouse position
var mousePosition;
var mousePosition;
Line 16: Line 28:
var mouseY;
var mouseY;
var canvas = document.getElementById("page_2_canvas");
var canvas = document.getElementById("page_2_canvas");
var ctx = canvas.getContext('2d');


// Constant for specifying invalid memory page
// Constant for specifying invalid memory page
Line 59: Line 72:


function draw() {
function draw() {
    // Set stroke style according to theme
    ctx.strokeStyle = usingDarkTheme ? "white" : "black";
   
    // Set colour of explanatory text
    document.getElementById("twoLevelPageTable").style.color = "white";
   
     //Draw Virtual Memory
     //Draw Virtual Memory
     drawVM();
     drawVM();
Line 104: Line 123:
function drawPageTable(label, startX, startY, blockNumber, entry, level, valid = true) {
function drawPageTable(label, startX, startY, blockNumber, entry, level, valid = true) {
     // Draw label
     // Draw label
     ctx.fillStyle = "purple";
     ctx.fillStyle = usingDarkTheme ? "mediumpurple" : "purple";
     ctx.font = "18px Arial";
     ctx.font = "18px Arial";
     if(level == 1)
     if(level == 1)
Line 118: Line 137:
         if(!valid) ctx.fillStyle = "mediumorchid"; // Table invalid
         if(!valid) ctx.fillStyle = "mediumorchid"; // Table invalid
         else if (entry[i] == NOT_FOUND) ctx.fillStyle = "orchid"; // Entry invalid
         else if (entry[i] == NOT_FOUND) ctx.fillStyle = "orchid"; // Entry invalid
         else ctx.fillStyle = "purple"; // Valid
         else ctx.fillStyle = usingDarkTheme ? "mediumpurple" : "purple"; // Valid
          
          
         ctx.fillRect(startX, startY + i * BLOCK_HEIGHT, blockLength, BLOCK_HEIGHT);
         ctx.fillRect(startX, startY + i * BLOCK_HEIGHT, blockLength, BLOCK_HEIGHT);
Line 159: Line 178:
function drawPhysicalMemory() {
function drawPhysicalMemory() {
     // Heading
     // Heading
     ctx.fillStyle = "blue";
     ctx.fillStyle = usingDarkTheme ? "aqua" : "blue";
     ctx.font = "20px Arial";
     ctx.font = "20px Arial";
     ctx.fillText("Physical Memory", 760, 80);
     ctx.fillText("Physical Memory", 760, 80);
Line 170: Line 189:
      
      
     // Physical address
     // Physical address
     ctx.fillStyle = "blue";
     ctx.fillStyle = usingDarkTheme ? "aqua" : "blue";
     for (var i = 0; i < PMBlockNumber; i++) {
     for (var i = 0; i < PMBlockNumber; i++) {
         ctx.fillText((i<<4).toString(16), PMStartx + PMBlockLength + 5, PMStarty + i * PMBlockHeight + 10);
         ctx.fillText((i<<4).toString(16), PMStartx + PMBlockLength + 5, PMStarty + i * PMBlockHeight + 10);
Line 367: Line 386:


// Draws a line with a width of 3, colour optional
// Draws a line with a width of 3, colour optional
function drawLine(ctx, x, y, a, b, style = "black") {
function drawLine(ctx, x, y, a, b, style = usingDarkTheme ? "white" : "black") {
     ctx.lineWidth = 3;
     ctx.lineWidth = 3;
     ctx.beginPath();
     ctx.beginPath();
Line 375: Line 394:
     ctx.stroke();
     ctx.stroke();
     ctx.lineWidth = 1;
     ctx.lineWidth = 1;
     ctx.strokeStyle = 'black';
     ctx.strokeStyle = usingDarkTheme ? "white" : 'black';
}
}



Latest revision as of 07:22, 14 August 2019

This demonstration demonstrates the operation of a Two-level Page Table.

Dark-mode widget for embedding

Virtual Address in binary (8 bits)

Virtual Address = L1 PageTable index (2 bits) + L2 PageTable index (2 bits) + Offset (4 bits)

Physical Address in binary (8 bits)