Skip to content

Commit 916fcfa

Browse files
committed
add draft to support WebAssembly within the kernel
1 parent c41204e commit 916fcfa

File tree

11 files changed

+1076
-3
lines changed

11 files changed

+1076
-3
lines changed

Cargo.lock

Lines changed: 661 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ nostd = []
7070
semihosting = ["dep:semihosting"]
7171
shell = ["simple-shell"]
7272
idle-poll = []
73+
wasm = ["wasmtime"]
7374

7475
[dependencies]
7576
hermit-macro = { path = "hermit-macro" }
@@ -107,6 +108,7 @@ talc = { version = "4" }
107108
time = { version = "0.3", default-features = false }
108109
volatile = { version = "0.6", features = ["unstable"] }
109110
zerocopy = { version = "0.7", default-features = false }
111+
wasmtime = { version = "21.0", default-features = false, features = ["runtime", "gc", "component-model"], optional = true }
110112

111113
[dependencies.smoltcp]
112114
version = "0.11"

src/arch/x86_64/kernel/longjmp.s

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.section .text
2+
.global longjmp
3+
longjmp:
4+
xor eax,eax
5+
cmp esi, 1 /* CF = val ? 0 : 1 */
6+
adc eax, esi /* eax = val + !val */
7+
mov rbx, [rdi]
8+
mov rbp, [rdi+8]
9+
mov r12, [rdi+16]
10+
mov r13, [rdi+24]
11+
mov r14, [rdi+32]
12+
mov r15, [rdi+40]
13+
mov rsp, [rdi+48]
14+
jmp [rdi+56]

src/arch/x86_64/kernel/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#[cfg(feature = "common-os")]
22
use core::arch::asm;
3+
use core::arch::global_asm;
34
use core::num::NonZeroU64;
45
use core::ptr;
56
use core::sync::atomic::{AtomicPtr, AtomicU32, Ordering};
@@ -38,6 +39,9 @@ pub(crate) mod systemtime;
3839
#[cfg(feature = "vga")]
3940
mod vga;
4041

42+
global_asm!(include_str!("setjmp.s"));
43+
global_asm!(include_str!("longjmp.s"));
44+
4145
/// Kernel header to announce machine features
4246
#[cfg_attr(target_os = "none", link_section = ".data")]
4347
static mut RAW_BOOT_INFO: Option<&'static RawBootInfo> = None;

src/arch/x86_64/kernel/setjmp.s

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.section .text
2+
.global setjmp
3+
setjmp:
4+
mov [rdi], rbx
5+
mov [rdi+8], rbp
6+
mov [rdi+16], r12
7+
mov [rdi+24], r13
8+
mov [rdi+32], r14
9+
mov [rdi+40], r15
10+
lea rdx, [rsp+8] # rsp without current ret addr
11+
mov [rdi+48], rdx
12+
mov rdi, rsp # save return addr ptr for new rip
13+
mov [rdi+56], rdx
14+
xor rax, rax
15+
ret

src/arch/x86_64/mm/paging.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub fn virtual_to_physical(virtual_address: VirtAddr) -> Option<PhysAddr> {
106106

107107
match translate {
108108
TranslateResult::NotMapped | TranslateResult::InvalidFrameAddress(_) => {
109-
warn!(
109+
trace!(
110110
"Uable to determine the physical address of 0x{:X}",
111111
virtual_address
112112
);

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ mod shell;
9393
mod synch;
9494
pub mod syscalls;
9595
pub mod time;
96+
#[cfg(all(target_arch = "x86_64", feature = "wasm"))]
97+
mod wasm;
9698

9799
#[cfg(target_os = "none")]
98100
hermit_entry::define_entry_version!();
@@ -156,6 +158,11 @@ extern "C" fn initd(_arg: usize) {
156158
#[cfg(not(test))]
157159
let (argc, argv, environ) = syscalls::get_application_parameters();
158160

161+
#[cfg(all(target_arch = "x86_64", feature = "wasm"))]
162+
if crate::wasm::init().is_err() {
163+
error!("Unable to initialized wasm support")
164+
}
165+
159166
// give the IP thread time to initialize the network interface
160167
core_scheduler().reschedule();
161168

0 commit comments

Comments
 (0)