Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for user specified image file #22

Open
wants to merge 2 commits into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion instmacros.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
sed 's/inst.get_opcode()/(raw \& 0x7F)/g' < inst_src.js > inst.js
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sed 's/inst.get_rd()/((raw >>> 7) \& 0x1F)/g' -i inst.js
sed 's/inst.get_rs1()/((raw >>> 15) \& 0x1F)/g' -i inst.js
sed 's/inst.get_rs1()/((raw >>> 15) \& 0x1F)/g' -i inst.js
sed 's/inst.get_rs2()/((raw >>> 20) \& 0x1F)/g' -i inst.js
sed 's/inst.get_funct3()/((raw >>> 12) \& 0x7)/g' -i inst.js
sed 's/inst.get_funct7()/((raw >>> 25) \& 0x7F)/g' -i inst.js
Expand All @@ -11,6 +12,21 @@ sed 's/inst.get_B_imm()/(((((raw >> 20) \& 0xFFFFFFE0) | ((raw >>> 7) \& 0x00000
sed 's/inst.get_U_imm()/((raw \& 0xFFFFF000))/g' -i inst.js
sed 's/inst.get_J_imm()/(((raw >> 20) \& 0xFFF007FE) | ((raw >>> 9) \& 0x00000800) | (raw \& 0x000FF000))/g' -i inst.js

else

sed -i'' -e 's/inst.get_rd()/((raw >>> 7) \& 0x1F)/g' inst.js
sed -i'' -e 's/inst.get_rs1()/((raw >>> 15) \& 0x1F)/g' inst.js
sed -i'' -e 's/inst.get_rs2()/((raw >>> 20) \& 0x1F)/g' inst.js
sed -i'' -e 's/inst.get_funct3()/((raw >>> 12) \& 0x7)/g' inst.js
sed -i'' -e 's/inst.get_funct7()/((raw >>> 25) \& 0x7F)/g' inst.js
sed -i'' -e 's/inst.get_CSR_imm()/((raw >>> 20))/g' inst.js
sed -i'' -e 's/inst.get_I_imm()/((raw >> 20))/g' ./inst.js
sed -i'' -e 's/inst.get_S_imm()/(((raw >> 20) \& 0xFFFFFFE0) | ((raw >>> 7) \& 0x0000001F))/g' ./inst.js
sed -i'' -e 's/inst.get_B_imm()/(((((raw >> 20) \& 0xFFFFFFE0) | ((raw >>> 7) \& 0x0000001F)) \& 0xFFFFF7FE) | (( (((raw >> 20) \& 0xFFFFFFE0) | ((raw >>> 7) \& 0x0000001F)) \& 0x00000001) << 11))/g' ./inst.js
sed -i'' -e 's/inst.get_U_imm()/((raw \& 0xFFFFF000))/g' ./inst.js
sed -i'' -e 's/inst.get_J_imm()/(((raw >> 20) \& 0xFFF007FE) | ((raw >>> 9) \& 0x00000800) | (raw \& 0x000FF000))/g' ./inst.js
rm inst.js-e
fi

echo '0a
//################################################################################
Expand Down
59 changes: 59 additions & 0 deletions run.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,22 @@
<!-- angel functions -->
<script>
function runWorker() {
var fileList = document.getElementById("file-selector");
var file = fileList.files;
if(file.length != 0) {
var fileSize = file[0].size - 1;
var fsizegb = Math.round((fileSize / (1024 * 1024)));
if (fsizegb > 3 ) {
if (!(confirm("File too Big!! Size greater that 3Gb Continue?"))) {
window.location.reload();
}
}
}
$('#bootButton').attr('disabled', true);
$('#bootButton').html("Running...");
$('#bootButton').prop("onclick", null);
$('#file-selector').attr('disabled', true);
$('#file-selector').prop("onclick", null);
myWorker = new Worker("webworker.js");
myWorker.onmessage = function(oEvent) {
if (oEvent.data.type == "t") {
Expand All @@ -74,6 +87,47 @@
document.getElementById("mipsCount").innerHTML = oEvent.data.d;
}
};
var binaryBuffer;
var offset = 0;
const CHUNK_SIZE = 64 * 4 * 1024; // Chunk multiple of 4K
var ReadFunction = function(e) {
if (e.target.error == null) {

if(offset == 0) {
binaryBuffer = e.target.result;
} else {
binaryBuffer = binaryBuffer.concat( e.target.result);
}
offset += e.target.result.length;

//Update the prog bar
document.getElementById("bar").style.width = ((offset/fileSize)*100).toString() + "%";

if (offset >= fileSize) {
console.log("Done reading file");
myWorker.postMessage({"type": "f", "inp": binaryBuffer});
return;
}
ReadImageFile(offset, file);
} else {
console.error("File read error!!: " + e.target.error.code);
}
}
function ReadImageFile(offset, _file) {
var fr = new FileReader();
var start = offset;
//var end = offset + CHUNK_SIZE;
var end = Math.min((offset + CHUNK_SIZE), _file[0].size);
var slice = _file[0].slice(start, end);
fr.onload = ReadFunction;
fr.readAsBinaryString(slice);
}

if (fileList.files.length == 0) {
myWorker.postMessage({"type": "f", "inp": fileList.value});
} else {
ReadImageFile(offset, file);
}
}
</script>
</head>
Expand Down Expand Up @@ -404,6 +458,11 @@ <h5>Execution controls: </h5><a class="btn btn-medium btn-primary" data-toggle=
</div>

</div>
<!-- Select boot file. -->
<input type="file" id="file-selector" single>
<div class="col-20 mx-auto col-md-8 message-container text-left p-3">
<h4 class="text-capitalize">Enter the Image File</h4>
</div>
</body>

<!-- misc end-of-page scripts -->
Expand Down
2 changes: 1 addition & 1 deletion ui/shepherdconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
});
shepherd.addStep('welcome', {
title: '<strong>Welcome to ANGEL!</strong>',
text: ['ANGEL is a JavaScript simulator for the <a href="http://riscv.org">RISC-V architecture</a> <br>that boots <a href="http://github.com/ucb-bar/riscv-linux">Linux</a> inside your browser.', 'Click "Learn More" for a tour or hit "Close & Boot Linux" to <br> use ANGEL immediately'],
text: ['ANGEL is a JavaScript simulator for the <a href="http://riscv.org">RISC-V architecture</a> <br>that boots <a href="http://github.com/ucb-bar/riscv-linux">Linux</a> inside your browser.', 'Click "Learn More" for a tour or hit "Close & Boot Linux" to <br> use ANGEL immediately', 'PS: You can use your own boot file by selecting a file in the dialogue box below.' ],
attachTo: '#ANGELtitle bottom',
classes: 'shepherd shepherd-open shepherd-theme-arrows shepherd-transparent-text',
buttons: [
Expand Down
23 changes: 17 additions & 6 deletions webworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,28 @@ self.addEventListener("message", function (oEvent) {
}
}
elfRunNextInst();
} else if (oEvent.data.type == "f") {
filesList = oEvent.data.inp;
runCodeC(filesList);
}
}, false);

function runNer(input) {
//We do not execute untill we have a file selected
console.log('In runner');
}
function runCodeC(userIn) {
//compilestat = document.getElementById("compilestatus");
//compilestat.innerHTML = "Compile Status: Compiling, waiting for server response.";
filesList = ["lib/riscv_compiled/vmlinux" ];

handle_file_continue(filesList);

RISCV = new CPU();
if (userIn.length == 0) {
filesList = ["lib/riscv_compiled/vmlinux" ];
handle_file_continue(filesList);
RISCV = new CPU();
} else {
filesList = ["lib/riscv_compiled/vmlinux" ];
RISCV = new CPU();
chainedFileLoader(userIn, 'vmlinux', filesList.slice(1, filesList.length));
}
}

function handle_file_continue(filesList) {
Expand All @@ -57,4 +68,4 @@ function handle_file_continue(filesList) {
GetBinaryFile(filesList[0], chainedFileLoader, filesList.slice(1, filesList.length));
}

runCodeC();
runNer();