From 20e3ce15bedd1a357d97021cba0c97e3e1748d37 Mon Sep 17 00:00:00 2001 From: Able Date: Wed, 5 Apr 2023 12:29:20 -0500 Subject: [PATCH] hacking in a wasm interpreter --- Cargo.lock | 356 +++++++++++++++++++++++++--------- kernel/Cargo.toml | 19 +- kernel/src/arch/x86_64/mod.rs | 1 + kernel/src/interp.rs | 46 +++++ kernel/src/kmain.rs | 32 ++- kernel/src/lib.rs | 1 + limine | 2 +- repbuild/limine.cfg | 4 +- repbuild/src/main.rs | 2 +- wasm_syscall_test.wasm | Bin 0 -> 4353 bytes 10 files changed, 355 insertions(+), 108 deletions(-) create mode 100644 kernel/src/interp.rs create mode 100755 wasm_syscall_test.wasm diff --git a/Cargo.lock b/Cargo.lock index bc18679..64b6843 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,28 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "ahash" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "0.7.20" @@ -51,9 +73,9 @@ checksum = "2b645c5c09a7d4035949cfce1a915785aaad6f17800c35fda8a8c311c491f284" [[package]] name = "bit_field" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4" +checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" [[package]] name = "bitflags" @@ -100,6 +122,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "clparse" +version = "0.1.0" +source = "git+https://git.ablecorp.us/ableos/ableos_userland#389c85d6a4ed06dce5aa044257e881d1547edfdb" +dependencies = [ + "hashbrown 0.13.2", + "log", + "toml", +] + [[package]] name = "codespan-reporting" version = "0.11.1" @@ -112,15 +144,15 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] name = "crossbeam-queue" -version = "0.3.6" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd42583b04998a5363558e5f9291ee5a5ff6b49944332103f251e7479a82aa7" +checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" dependencies = [ "cfg-if", "crossbeam-utils", @@ -128,18 +160,18 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.11" +version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" +checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" dependencies = [ "cfg-if", ] [[package]] name = "cxx" -version = "1.0.92" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a140f260e6f3f79013b8bfc65e7ce630c9ab4388c6a89c71e07226f49487b72" +checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93" dependencies = [ "cc", "cxxbridge-flags", @@ -149,9 +181,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.92" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da6383f459341ea689374bf0a42979739dc421874f112ff26f829b8040b8e613" +checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b" dependencies = [ "cc", "codespan-reporting", @@ -159,24 +191,24 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn", + "syn 2.0.13", ] [[package]] name = "cxxbridge-flags" -version = "1.0.92" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90201c1a650e95ccff1c8c0bb5a343213bdd317c6e600a93075bca2eff54ec97" +checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb" [[package]] name = "cxxbridge-macro" -version = "1.0.92" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b75aed41bb2e6367cae39e6326ef817a851db13c13e4f3263714ca3cfb8de56" +checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.13", ] [[package]] @@ -187,9 +219,15 @@ checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] +[[package]] +name = "downcast-rs" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" + [[package]] name = "env_logger" version = "0.10.0" @@ -211,7 +249,7 @@ checksum = "50d6a0976c999d473fe89ad888d5a284e55366d9dc9038b1ba2aa15128c4afa0" dependencies = [ "errno-dragonfly", "libc", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -256,6 +294,35 @@ dependencies = [ "log", ] +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash 0.7.6", +] + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash 0.8.3", +] + [[package]] name = "hermit-abi" version = "0.1.19" @@ -279,9 +346,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "iana-time-zone" -version = "0.1.55" +version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "716f12fbcfac6ffab0a5e9ec51d0a0ff70503742bb2dc7b99396394c9dc323f0" +checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -302,14 +369,20 @@ dependencies = [ ] [[package]] -name = "io-lifetimes" -version = "1.0.9" +name = "indexmap-nostd" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09270fd4fa1111bc614ed2246c7ef56239a3063d5be0d1ec3b589c505d400aeb" +checksum = "8e04e2fd2b8188ea827b32ef11de88377086d690286ab35747ef7f9bf3ccb590" + +[[package]] +name = "io-lifetimes" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" dependencies = [ "hermit-abi 0.3.1", "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -321,7 +394,7 @@ dependencies = [ "hermit-abi 0.3.1", "io-lifetimes", "rustix", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -343,6 +416,7 @@ dependencies = [ name = "kernel" version = "0.2.0" dependencies = [ + "clparse", "crossbeam-queue", "derive_more", "error-stack 0.3.1", @@ -353,20 +427,27 @@ dependencies = [ "spin", "uart_16550", "versioning", + "wasmi", "x2apic", "x86_64", ] [[package]] name = "libc" -version = "0.2.140" +version = "0.2.141" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" +checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" + +[[package]] +name = "libm" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" [[package]] name = "limine" version = "0.1.10" -source = "git+https://github.com/limine-bootloader/limine-rs#2f0ae642064749372a61cf3290f22ce71d21df27" +source = "git+https://github.com/limine-bootloader/limine-rs#d34b1863a0355e8606a0090663a9f4749c02f838" [[package]] name = "link-cplusplus" @@ -379,15 +460,15 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd550e73688e6d578f0ac2119e32b797a327631a42f9433e59d02e139c8df60d" +checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" [[package]] name = "lock_api" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" dependencies = [ "autocfg", "scopeguard", @@ -429,9 +510,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" [[package]] name = "owo-colors" @@ -450,18 +531,18 @@ checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" [[package]] name = "proc-macro2" -version = "1.0.43" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.21" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ "proc-macro2", ] @@ -513,23 +594,23 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.5" +version = "0.37.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e78cc525325c06b4a7ff02db283472f3c042b7ff0c391f96c6d5ac6f4f91b75" +checksum = "2aae838e49b3d63e9274e1c01833cc8139d3fec468c3b84688c628f44b1ae11d" dependencies = [ "bitflags", "errno", "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] name = "rustversion" -version = "1.0.9" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" +checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" [[package]] name = "sbi" @@ -557,38 +638,44 @@ checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" [[package]] name = "serde" -version = "1.0.141" +version = "1.0.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7af873f2c95b99fcb0bd0fe622a43e29514658873c8ceba88c4cb88833a22500" +checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.141" +version = "1.0.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75743a150d003dd863b51dc809bcad0d73f2102c53632f1e954e738192a3413f" +checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.13", ] [[package]] name = "slab" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" dependencies = [ "autocfg", ] [[package]] -name = "spin" -version = "0.9.4" +name = "smallvec" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" dependencies = [ "lock_api", ] @@ -605,9 +692,20 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.99" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c9da457c5285ac1f936ebd076af6dac17a61cfe7826f2076b4d015cf47bc8ec" dependencies = [ "proc-macro2", "quote", @@ -630,10 +728,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" dependencies = [ "libc", - "wasi", + "wasi 0.10.0+wasi-snapshot-preview1", "winapi", ] +[[package]] +name = "toml" +version = "0.5.9" +source = "git+https://git.ablecorp.us/theoddgarlic/toml-rs#34db433429f3ad38921d13ac9aba74c8a706f376" +dependencies = [ + "hashbrown 0.12.3", + "serde", +] + [[package]] name = "uart_16550" version = "0.2.18" @@ -647,29 +754,35 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.2" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" [[package]] name = "unicode-width" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "versioning" -version = "0.1.2" -source = "git+https://git.ablecorp.us/able/aos_userland#a9a2514de31c10c1f02956f3513a636e2c5190ff" +version = "0.1.3" +source = "git+https://git.ablecorp.us/ableos/ableos_userland#389c85d6a4ed06dce5aa044257e881d1547edfdb" dependencies = [ "serde", ] [[package]] name = "volatile" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3ca98349dda8a60ae74e04fd90c7fb4d6a4fbe01e6d3be095478aa0b76f6c0c" +checksum = "442887c63f2c839b346c192d047a7c87e73d0689c9157b00b53dcc27dd5ea793" [[package]] name = "wasi" @@ -677,6 +790,12 @@ version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "wasm-bindgen" version = "0.2.84" @@ -698,7 +817,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-shared", ] @@ -720,7 +839,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -731,6 +850,46 @@ version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +[[package]] +name = "wasmi" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677160b1166881badada1137afc6457777126f328ae63a18058b504f546f0828" +dependencies = [ + "smallvec", + "spin", + "wasmi_arena", + "wasmi_core", + "wasmparser-nostd", +] + +[[package]] +name = "wasmi_arena" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "401c1f35e413fac1846d4843745589d9ec678977ab35a384db8ae7830525d468" + +[[package]] +name = "wasmi_core" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624e6333e861ef49095d2d678b76ebf30b06bf37effca845be7e5b87c90071b7" +dependencies = [ + "downcast-rs", + "libm", + "num-traits", + "paste", +] + +[[package]] +name = "wasmparser-nostd" +version = "0.100.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9157cab83003221bfd385833ab587a039f5d6fa7304854042ba358a3b09e0724" +dependencies = [ + "indexmap-nostd", +] + [[package]] name = "winapi" version = "0.3.9" @@ -764,11 +923,11 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.47.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2649ff315bee4c98757f15dac226efe3d81927adbb6e882084bb1ee3e0c330a7" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" dependencies = [ - "windows-targets 0.47.0", + "windows-targets 0.48.0", ] [[package]] @@ -780,6 +939,15 @@ dependencies = [ "windows-targets 0.42.2", ] +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.0", +] + [[package]] name = "windows-targets" version = "0.42.2" @@ -797,17 +965,17 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.47.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f8996d3f43b4b2d44327cd71b7b0efd1284ab60e6e9d0e8b630e18555d87d3e" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" dependencies = [ - "windows_aarch64_gnullvm 0.47.0", - "windows_aarch64_msvc 0.47.0", - "windows_i686_gnu 0.47.0", - "windows_i686_msvc 0.47.0", - "windows_x86_64_gnu 0.47.0", - "windows_x86_64_gnullvm 0.47.0", - "windows_x86_64_msvc 0.47.0", + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] @@ -818,9 +986,9 @@ checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.47.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "831d567d53d4f3cb1db332b68e6e2b6260228eb4d99a777d8b2e8ed794027c90" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" [[package]] name = "windows_aarch64_msvc" @@ -830,9 +998,9 @@ checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" [[package]] name = "windows_aarch64_msvc" -version = "0.47.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a42d54a417c60ce4f0e31661eed628f0fa5aca73448c093ec4d45fab4c51cdf" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" [[package]] name = "windows_i686_gnu" @@ -842,9 +1010,9 @@ checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" [[package]] name = "windows_i686_gnu" -version = "0.47.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1925beafdbb22201a53a483db861a5644123157c1c3cee83323a2ed565d71e3" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" [[package]] name = "windows_i686_msvc" @@ -854,9 +1022,9 @@ checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" [[package]] name = "windows_i686_msvc" -version = "0.47.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a8ef8f2f1711b223947d9b69b596cf5a4e452c930fb58b6fc3fdae7d0ec6b31" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" [[package]] name = "windows_x86_64_gnu" @@ -866,9 +1034,9 @@ checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" [[package]] name = "windows_x86_64_gnu" -version = "0.47.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7acaa0c2cf0d2ef99b61c308a0c3dbae430a51b7345dedec470bd8f53f5a3642" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" [[package]] name = "windows_x86_64_gnullvm" @@ -878,9 +1046,9 @@ checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" [[package]] name = "windows_x86_64_gnullvm" -version = "0.47.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5a0628f71be1d11e17ca4a0e9e15b3a5180f6fbf1c2d55e3ba3f850378052c1" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" [[package]] name = "windows_x86_64_msvc" @@ -890,9 +1058,9 @@ checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" [[package]] name = "windows_x86_64_msvc" -version = "0.47.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6e62c256dc6d40b8c8707df17df8d774e60e39db723675241e7c15e910bce7" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "x2apic" diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 1c23509..8ad88d4 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -2,14 +2,20 @@ edition = "2021" name = "kernel" version = "0.2.0" +resolver = "2" [dependencies] -error-stack = { version = "0.3", default-features = false} -log = "0.4" -spin = "0.9" -uart_16550 = "0.2" -slab = { version = "0.4", default-features = false } -versioning = { git = "https://git.ablecorp.us/able/aos_userland" } +error-stack = { version = "0.3", default-features = false } +log = "0.4" +spin = "0.9" +uart_16550 = "0.2" +slab = { version = "0.4", default-features = false } +# xml = { git = "https://git.ablecorp.us/ableos/ableos_userland" } + +clparse = { git = "https://git.ablecorp.us/ableos/ableos_userland", default-features = false } +versioning = { git = "https://git.ablecorp.us/ableos/ableos_userland" } +wasmi = { version = "0.29.0", default-features = false } + [dependencies.crossbeam-queue] version = "0.3" @@ -32,6 +38,7 @@ features = [ "sum", ] + [target.'cfg(target_arch = "x86_64")'.dependencies] limine = { version = "0.1", git = "https://github.com/limine-bootloader/limine-rs" } x86_64 = "0.14" diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index d212e8d..3936b63 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -50,6 +50,7 @@ unsafe extern "C" fn _kernel_start() -> ! { static KFILE_REQ: KernelFileRequest = KernelFileRequest::new(0); static MOD_REQ: ModuleRequest = ModuleRequest::new(0); + crate::kmain::kmain( KFILE_REQ .get_response() diff --git a/kernel/src/interp.rs b/kernel/src/interp.rs new file mode 100644 index 0000000..029b3a6 --- /dev/null +++ b/kernel/src/interp.rs @@ -0,0 +1,46 @@ +use alloc::vec::Vec; +use log::trace; +use wasmi::{Caller, Func, Linker, Module, Store}; + +pub fn wasm() -> Result<(), wasmi::Error> { + use wasmi::Config; + use wasmi::Engine; + trace!(""); + let conf = Config::default(); + let engine = Engine::new(&conf); + trace!("Engine constructed"); + + let wasm = include_bytes!("../../wasm_syscall_test.wasm"); + + trace!("Loading WASM binary"); + let module = Module::new(&engine, &wasm[..]).unwrap(); + trace!("Constructing wasm module"); + + let mut store = Store::new(&engine, 42); + trace!("constructing host store"); + + let read_mem_addr = Func::wrap(&mut store, |caller: Caller<'_, HostState>, param: u64| { + read_memory_address(caller, param); + + panic!(":)") + }); + + let mut linker = >::new(&engine); + linker.define("host", "read_mem_addr", read_mem_addr)?; + trace!("Linked read_mem_addr"); + + let instance = linker.instantiate(&mut store, &module)?.start(&mut store)?; + trace!("Instanced the engine and module"); + + let hello = instance.get_typed_func::<(), ()>(&store, "_start")?; + + hello.call(&mut store, ())?; + trace!("Called _start"); + Ok(()) +} + +pub type HostState = u32; +pub fn read_memory_address(caller: Caller<'_, HostState>, address: u64) -> u64 { + trace!("Address: {}", address); + 0 +} diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index 79f1392..6b8b6bc 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -1,15 +1,39 @@ //! AbleOS Kernel Entrypoint +use log::{info, trace}; + +use crate::arch::sloop; +use crate::{interp, task}; + +use crate::alloc::string::ToString; + pub fn kmain(cmdline: &str, bootstrap: Option<&'static [u8]>) -> ! { log::debug!("Entered kmain"); - // TODO: Actual cmdline parsing (Serde?) - if cmdline.contains("baka=9") { + let mut cmdline = cmdline.to_string(); + cmdline.pop(); + cmdline.remove(0); + + let kcmd = clparse::Arguments::parse(cmdline.to_string()).unwrap(); + log::info!("Cmdline: {kcmd:?}"); + + if kcmd.arguments.get("baka") == Some(&"9".to_string()) { let _ = crate::arch::log(format_args!(include_str!("../data/⑨. バカ"))); } - log::info!("Cmdline: \"{cmdline}\""); - let bootstrap = bootstrap.expect("no bootstrap found"); + let bootstrap = bootstrap/*.expect("no bootstrap found")*/; + match bootstrap { + Some(bootstrap_mod) => {} + None => { + info!("No bootstrap module loaded.") + } + } + // use xml::XMLElement; + // let kcmd = XMLElement::new("cmdline"); + + let abc = interp::wasm(); + + trace!("{:?}", abc); crate::arch::sloop() } diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 9e644da..ad67405 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -15,6 +15,7 @@ extern crate alloc; mod allocator; mod arch; +pub mod interp; mod kmain; mod logger; mod memory; diff --git a/limine b/limine index 2b12406..751e802 160000 --- a/limine +++ b/limine @@ -1 +1 @@ -Subproject commit 2b12406a79d9bd0a4bc0c06f6261ecb72f51c9c2 +Subproject commit 751e802e173392e8637759e2b3c96bbf59456f87 diff --git a/repbuild/limine.cfg b/repbuild/limine.cfg index bfbe0b4..530a612 100644 --- a/repbuild/limine.cfg +++ b/repbuild/limine.cfg @@ -13,9 +13,9 @@ TERM_BACKDROP=008080 COMMENT=Default AbleOS boot entry. PROTOCOL=limine KERNEL_PATH=${ABLEOS_KERNEL} - KERNEL_CMDLINE= + KERNEL_CMDLINE="hi=true bye=false baka=9" # Setting a default resolution for the framebuffer RESOLUTION=1024x768x24 - # MODULE_PATH=boot:///boot/initrd.tar + MODULE_PATH=boot:///boot/fs.wasm # MODULE_CMDLINE=This is the first module. diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 04599ff..9ddc68e 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -156,7 +156,7 @@ fn run(release: bool, target: Target) -> Result<(), Error> { "-bios", std::env::var("REPBUILD_QEMU_FIRMWARE_PATH") .as_deref() - .unwrap_or("/usr/share/OVMF/OVMF_CODE.fd"), + .unwrap_or("/usr/share/ovmf/x64/OVMF_CODE.fd"), "-drive", "file=target/disk.img,format=raw", "-m", "4G", "-serial", "stdio", diff --git a/wasm_syscall_test.wasm b/wasm_syscall_test.wasm new file mode 100755 index 0000000000000000000000000000000000000000..282fca0a453167447d509592d9f7378b0fec4b52 GIT binary patch literal 4353 zcmcgvU2Ggz6+W{&GrQhDZ)_*EOHh}lv1~Q=+Hs>a+p?+~ImqCW)M;Eb!5wCI@2=OG zomu9`VQH&Wq7sFdDiROCOF?P{6+bFcRZ*3PN<086qC5~Gr1B#qC_*X^2!s$SD!aH z{x7myY5fJTzYaOvdJdDup)8X2HsS&+Uk2-#jIRDB$Wu(Jl=vFx%!?REq0ArTtgT_k zU26Zvll_n!?uVo#FaI94;A{?wBsnFBwxefE@YNIil-hG}azfQdLEpjtlKu^lr^D@4 zaK6HOa{5(}FM?Ex*vWkD0*0che+<*h_=lZqm}G?0`ol4qnZ7a1k0$ ztGQnd86RLs<1CfNv+}7@BRmZmp92RP$RKvE8m@M&bH4OlhxM2-m`#Yzb?nvtia}9Q z9X^9gM&T@d8_a8R!Dsvht5?Gn(nsp&Ht-~TM(!!x_0J%rZRRQpX}m*GZlJ_FpoCxk zdl*tm;yR{6T+Hgblzjdja5z_#k76Ifisa>hN}u0bP?-qCh;5Npp4tBk)-@Na8v5U2Bvf>|FT>aXE9|W6WVnasrnn3 zz6l;q`YA{@!Y6Se@=yCkU+w36)i}UX?Lh=6vi6U?YLACnl>Zy76;Tvya8(SS zy$&V*6$22Qh;nfTirwhAgC>YWTQ{2KHET! z*fAa2>6&)CUa444-SpdzU8$@^l!UydJrn6k3r~p8V!M50;i*dHY}fouAdZ!8c*<;P zt{NTh3NNs5pLIFkKQnu5(61HOb=)fP^Mpnvpw%45B2I|lUYSOL*Z!O!uArG&Vtg5N zEDn?>n^Snv^IcIVu7-1b#Z`1m;s@w%C|NiRLK}xXV(NJ?SI41nZx%?g zq#PUv0_7=U-7|&WGo>7YEHe(xXjgU$x6hTK#Rui@f~1 zV_k$L!Hwy5P0OTT*ONORPb9c`{bVE)g&eO?w@kZLT3g$As5IjSo?kER2-iaml@{ku zF3c~?+3nVrZ}mzu&BYVV1!10CDji=qzBIRhzk6n9>E;fVBY(;dlus-MOTC8e^(=q8 zyCWF3!eBpJtSrAgX~$338~YTwr{;ccYMAHg-B=^ z%j@gQj~VAzFRmDmJa%ryFow|Vf2jP9@I136$dSkWfxzepF=WC^?F zZ;`C57%01r*JeDVrtB`%Y+DvdN8EWn09e9Haz=zLjm}=?b`-+q z3ePtOv|((o1c-P|om`AyMpy~A7gZ_o5IW#FUDHc=}-0POWY+8)L#LWwRA zaUi7@AOWV_jfvsq1ZLpNG$si-Dx! zEzPr*!-tKbn$seFgjm_nn5;rV9$vJnH(g%JR4Bd7zM6KTfm0HC0#>%cY2 VK?E%DL}RYjQ#1+VM{fzf{|hLI*vbF^ literal 0 HcmV?d00001