mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 11:16:42 +01:00
loader.wasm binary now includes compressed base
This commit is contained in:
@@ -1,16 +1,24 @@
|
||||
import "env.memory" memory(9);
|
||||
|
||||
export fn load_uw8(module_start: i32, module_end: i32, base_start: i32, base_end: i32) -> i32 {
|
||||
if ?module_start == 0 {
|
||||
let lazy length = module_end - module_start;
|
||||
copy(base_end, module_start, length);
|
||||
return base_end + length;
|
||||
global mut base_end: i32 = 0;
|
||||
|
||||
export fn load_uw8(module_size: i32) -> i32 {
|
||||
let lazy version = ?0 - 1;
|
||||
if version < 0 {
|
||||
return module_size;
|
||||
}
|
||||
|
||||
copy(base_end, base_start, 8);
|
||||
base_start = base_start + 8;
|
||||
let dest = base_end + 8;
|
||||
let src = module_start + 1;
|
||||
let module_end = 0x40000 + module_size;
|
||||
if version & 1 {
|
||||
module_end = uncompress(1, 0x40001);
|
||||
} else {
|
||||
copy(0x40000, 0, module_size);
|
||||
}
|
||||
copy(0, 0x84000, 8);
|
||||
|
||||
let base_start = 0x84008;
|
||||
let dest = 8;
|
||||
let src = 0x40001;
|
||||
|
||||
loop sections {
|
||||
if src < module_end & (base_start >= base_end | ?src <= ?base_start) {
|
||||
@@ -171,4 +179,12 @@ fn upkr_append_byte() {
|
||||
upkr_src_ptr = upkr_src_ptr + 1;
|
||||
upkr_low = (upkr_low & i64.extend_i32_u(-1)) << 8i64;
|
||||
upkr_range = upkr_range << 8i64;
|
||||
}
|
||||
|
||||
start fn unpack_base() {
|
||||
base_end = uncompress(0, 0x84000);
|
||||
}
|
||||
|
||||
data 0 {
|
||||
file("../uw8-tool/base.upk")
|
||||
}
|
||||
49
uw8-tool/Cargo.lock
generated
49
uw8-tool/Cargo.lock
generated
@@ -8,24 +8,73 @@ version = "1.0.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee10e43ae4a853c0a3591d4e2ada1719e553be18199d9da9d4a83f5927c2f5c7"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.72"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
|
||||
|
||||
[[package]]
|
||||
name = "cdivsufsort"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "edefce019197609da416762da75bb000bbd2224b2d89a7e722c2296cbff79b8c"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"sacabase",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "leb128"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pico-args"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468"
|
||||
|
||||
[[package]]
|
||||
name = "sacabase"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9883fc3d6ce3d78bb54d908602f8bc1f7b5f983afe601dabe083009d86267a84"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "upkr"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/exoticorn/upkr.git?rev=479a2e2#479a2e2c899a7aa24fa1fd9b4ebd371f8bc39f8e"
|
||||
dependencies = [
|
||||
"cdivsufsort",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uw8-tool"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"pico-args",
|
||||
"upkr",
|
||||
"wasm-encoder",
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
@@ -9,4 +9,5 @@ edition = "2021"
|
||||
wasmparser = "0.81"
|
||||
wasm-encoder = "0.8"
|
||||
anyhow = "1"
|
||||
pico-args = "0.4"
|
||||
pico-args = "0.4"
|
||||
upkr = { git = "https://github.com/exoticorn/upkr.git", rev = "479a2e2" }
|
||||
@@ -1,6 +1,5 @@
|
||||
import loaderUrl from "data-url:../../platform/loader.wasm";
|
||||
import platformUrl from "data-url:../../platform/platform.wasm";
|
||||
import baseUrl from "data-url:../../uw8-tool/base.upk";
|
||||
|
||||
async function loadWasm(url, imports) {
|
||||
let wasm_module = await (await fetch(url)).arrayBuffer();
|
||||
@@ -66,21 +65,14 @@ async function runModule(data) {
|
||||
let loadMem = loaderImport.env.memory.buffer;
|
||||
let loader = await loadWasm(loaderUrl, loaderImport);
|
||||
|
||||
let packedBaseModule = await (await fetch(baseUrl)).arrayBuffer();
|
||||
|
||||
if (dataU8Array[0] != 0) {
|
||||
new Uint8Array(loadMem).set(new Uint8Array(packedBaseModule));
|
||||
let baseEnd = loader.exports.uncompress(0, 0x84000);
|
||||
let baseModule = loadMem.slice(0x84000, baseEnd);
|
||||
|
||||
new Uint8Array(loadMem).set(dataU8Array);
|
||||
new Uint8Array(loadMem).set(new Uint8Array(baseModule), data.byteLength);
|
||||
|
||||
let destOffset = data.byteLength + baseModule.byteLength;
|
||||
let endOffset = loader.exports.load_uw8(0, data.byteLength, data.byteLength, destOffset);
|
||||
let length = loader.exports.load_uw8(data.byteLength);
|
||||
|
||||
data = new ArrayBuffer(endOffset - destOffset);
|
||||
new Uint8Array(data).set(new Uint8Array(loadMem).slice(destOffset, endOffset));
|
||||
data = new ArrayBuffer(length);
|
||||
new Uint8Array(data).set(new Uint8Array(loadMem).slice(0, length));
|
||||
}
|
||||
|
||||
let importObject = {
|
||||
|
||||
Reference in New Issue
Block a user