From 464ac97154b08656ee0ebfa75bfeb238ae9eebd3 Mon Sep 17 00:00:00 2001 From: wyfcyx Date: Mon, 19 Feb 2024 14:37:23 +0000 Subject: [PATCH] deploy: eeac90057c77f21a7506d7c1084622abcaf786de --- ch3-coop/os/loader/fn.init_app_cx.html | 2 +- ch3-coop/os/loader/fn.load_apps.html | 2 +- ch3-coop/os/loader/index.html | 2 +- ch3-coop/src/os/loader.rs.html | 18 ++++++++++++++---- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ch3-coop/os/loader/fn.init_app_cx.html b/ch3-coop/os/loader/fn.init_app_cx.html index a287d15f..fc21e3cc 100644 --- a/ch3-coop/os/loader/fn.init_app_cx.html +++ b/ch3-coop/os/loader/fn.init_app_cx.html @@ -1,3 +1,3 @@ init_app_cx in os::loader - Rust -

Function os::loader::init_app_cx

source ·
pub fn init_app_cx(app_id: usize) -> usize
Expand description

get app info with entry and sp and save TrapContext in kernel stack

+

Function os::loader::init_app_cx

source ·
pub fn init_app_cx(app_id: usize) -> usize
Expand description

get app info with entry and sp and save TrapContext in kernel stack

\ No newline at end of file diff --git a/ch3-coop/os/loader/fn.load_apps.html b/ch3-coop/os/loader/fn.load_apps.html index 37eac8ec..13713904 100644 --- a/ch3-coop/os/loader/fn.load_apps.html +++ b/ch3-coop/os/loader/fn.load_apps.html @@ -1,4 +1,4 @@ load_apps in os::loader - Rust -

Function os::loader::load_apps

source ·
pub fn load_apps()
Expand description

Load nth user app at +

Function os::loader::load_apps

source ·
pub fn load_apps()
Expand description

Load nth user app at [APP_BASE_ADDRESS + n * APP_SIZE_LIMIT, APP_BASE_ADDRESS + (n+1) * APP_SIZE_LIMIT).

\ No newline at end of file diff --git a/ch3-coop/os/loader/index.html b/ch3-coop/os/loader/index.html index 266769fc..525aa0ff 100644 --- a/ch3-coop/os/loader/index.html +++ b/ch3-coop/os/loader/index.html @@ -1,5 +1,5 @@ os::loader - Rust -

Module os::loader

source ·
Expand description

Loading user applications into memory

+

Module os::loader

source ·
Expand description

Loading user applications into memory

For chapter 3, user applications are simply part of the data included in the kernel binary, so we only need to copy them to the space allocated for each app to load them. We also allocate fixed spaces for each task’s diff --git a/ch3-coop/src/os/loader.rs.html b/ch3-coop/src/os/loader.rs.html index 05fb4dc9..af594798 100644 --- a/ch3-coop/src/os/loader.rs.html +++ b/ch3-coop/src/os/loader.rs.html @@ -98,6 +98,11 @@ 96 97 98 +99 +100 +101 +102 +103

//! Loading user applications into memory
 //!
 //! For chapter 3, user applications are simply part of the data included in the
@@ -170,10 +175,6 @@
     let num_app_ptr = _num_app as usize as *const usize;
     let num_app = get_num_app();
     let app_start = unsafe { core::slice::from_raw_parts(num_app_ptr.add(1), num_app + 1) };
-    // clear i-cache first
-    unsafe {
-        asm!("fence.i");
-    }
     // load apps
     for i in 0..num_app {
         let base_i = get_base_i(i);
@@ -187,6 +188,15 @@
         let dst = unsafe { core::slice::from_raw_parts_mut(base_i as *mut u8, src.len()) };
         dst.copy_from_slice(src);
     }
+    // Memory fence about fetching the instruction memory
+    // It is guaranteed that a subsequent instruction fetch must
+    // observes all previous writes to the instruction memory.
+    // Therefore, fence.i must be executed after we have loaded
+    // the code of the next app into the instruction memory.
+    // See also: riscv non-priv spec chapter 3, 'Zifencei' extension.
+    unsafe {
+        asm!("fence.i");
+    }
 }
 
 /// get app info with entry and sp and save `TrapContext` in kernel stack