diff --git a/ch3-coop/os/all.html b/ch3-coop/os/all.html index f3f9eb49..ce41dda2 100644 --- a/ch3-coop/os/all.html +++ b/ch3-coop/os/all.html @@ -1,5 +1,5 @@ List of all items in this crate

List of all items

Structs

Enums

Macros

Functions

Statics

Constants

+ Change settings

List of all items

Structs

Enums

Macros

Functions

Statics

Constants

\ No newline at end of file diff --git a/ch3-coop/os/config/constant.APP_BASE_ADDRESS.html b/ch3-coop/os/config/constant.APP_BASE_ADDRESS.html index 5d446f18..207048eb 100644 --- a/ch3-coop/os/config/constant.APP_BASE_ADDRESS.html +++ b/ch3-coop/os/config/constant.APP_BASE_ADDRESS.html @@ -2,5 +2,5 @@
pub const APP_BASE_ADDRESS: usize = 0x80400000;
+

Constant os::config::APP_BASE_ADDRESS

source · []
pub const APP_BASE_ADDRESS: usize = 0x80400000;
\ No newline at end of file diff --git a/ch3-coop/os/config/constant.APP_SIZE_LIMIT.html b/ch3-coop/os/config/constant.APP_SIZE_LIMIT.html index 4d3d930d..562a1392 100644 --- a/ch3-coop/os/config/constant.APP_SIZE_LIMIT.html +++ b/ch3-coop/os/config/constant.APP_SIZE_LIMIT.html @@ -2,5 +2,5 @@
pub const APP_SIZE_LIMIT: usize = 0x20000;
+

Constant os::config::APP_SIZE_LIMIT

source · []
pub const APP_SIZE_LIMIT: usize = 0x20000;
\ No newline at end of file diff --git a/ch3-coop/os/config/constant.KERNEL_STACK_SIZE.html b/ch3-coop/os/config/constant.KERNEL_STACK_SIZE.html index 0501d039..0870895a 100644 --- a/ch3-coop/os/config/constant.KERNEL_STACK_SIZE.html +++ b/ch3-coop/os/config/constant.KERNEL_STACK_SIZE.html @@ -2,5 +2,5 @@
pub const KERNEL_STACK_SIZE: usize = 4096 * 2; // 0x0000_0000_0000_2000usize
+

Constant os::config::KERNEL_STACK_SIZE

source · []
pub const KERNEL_STACK_SIZE: usize = 4096 * 2; // 0x0000_0000_0000_2000usize
\ No newline at end of file diff --git a/ch3-coop/os/config/constant.MAX_APP_NUM.html b/ch3-coop/os/config/constant.MAX_APP_NUM.html index 74b72214..5fd584c4 100644 --- a/ch3-coop/os/config/constant.MAX_APP_NUM.html +++ b/ch3-coop/os/config/constant.MAX_APP_NUM.html @@ -2,5 +2,5 @@
-

Constant os::config::MAX_APP_NUM

source · []
pub const MAX_APP_NUM: usize = 4;
+

Constant os::config::MAX_APP_NUM

source · []
pub const MAX_APP_NUM: usize = 4;
\ No newline at end of file diff --git a/ch3-coop/os/config/constant.USER_STACK_SIZE.html b/ch3-coop/os/config/constant.USER_STACK_SIZE.html index 0d920560..7b13b4aa 100644 --- a/ch3-coop/os/config/constant.USER_STACK_SIZE.html +++ b/ch3-coop/os/config/constant.USER_STACK_SIZE.html @@ -2,5 +2,5 @@
pub const USER_STACK_SIZE: usize = 4096 * 2; // 0x0000_0000_0000_2000usize
+

Constant os::config::USER_STACK_SIZE

source · []
pub const USER_STACK_SIZE: usize = 4096 * 2; // 0x0000_0000_0000_2000usize
\ No newline at end of file diff --git a/ch3-coop/os/config/index.html b/ch3-coop/os/config/index.html index cbb4ca3d..90eac120 100644 --- a/ch3-coop/os/config/index.html +++ b/ch3-coop/os/config/index.html @@ -1,7 +1,8 @@ -os::config - Rust +os::config - Rust
-

Module os::config

source · []

Constants

+

Module os::config

source · []
Expand description

Constants used in rCore

+

Constants

\ No newline at end of file diff --git a/ch3-coop/os/console/fn.print.html b/ch3-coop/os/console/fn.print.html index 11eb46a6..cfcc29ed 100644 --- a/ch3-coop/os/console/fn.print.html +++ b/ch3-coop/os/console/fn.print.html @@ -2,5 +2,5 @@
-

Function os::console::print

source · []
pub fn print(args: Arguments<'_>)
+

Function os::console::print

source · []
pub fn print(args: Arguments<'_>)
\ No newline at end of file diff --git a/ch3-coop/os/console/index.html b/ch3-coop/os/console/index.html index 20aa4929..d3626af6 100644 --- a/ch3-coop/os/console/index.html +++ b/ch3-coop/os/console/index.html @@ -1,8 +1,9 @@ -os::console - Rust +os::console - Rust
-

Module os::console

source · []

Structs

+

Module os::console

source · []
Expand description

SBI console driver, for text output

+

Structs

Functions

\ No newline at end of file diff --git a/ch3-coop/os/console/struct.Stdout.html b/ch3-coop/os/console/struct.Stdout.html index aacab1d0..38dd2dcd 100644 --- a/ch3-coop/os/console/struct.Stdout.html +++ b/ch3-coop/os/console/struct.Stdout.html @@ -2,7 +2,7 @@
-

Struct os::console::Stdout

source · []
struct Stdout;

Trait Implementations

Writes a string slice into this writer, returning whether the write +

Struct os::console::Stdout

source · []
struct Stdout;

Trait Implementations

Writes a string slice into this writer, returning whether the write succeeded. Read more

Writes a char into this writer, returning whether the write succeeded. Read more

Glue for usage of the write! macro with implementors of this trait. Read more

diff --git a/ch3-coop/os/fn.clear_bss.html b/ch3-coop/os/fn.clear_bss.html index f0ea84b0..57859753 100644 --- a/ch3-coop/os/fn.clear_bss.html +++ b/ch3-coop/os/fn.clear_bss.html @@ -1,6 +1,7 @@ -clear_bss in os - Rust +clear_bss in os - Rust
-

Function os::clear_bss

source · []
pub(crate) fn clear_bss()
+

Function os::clear_bss

source · []
pub(crate) fn clear_bss()
Expand description

clear BSS segment

+
\ No newline at end of file diff --git a/ch3-coop/os/fn.rust_main.html b/ch3-coop/os/fn.rust_main.html index cd535573..2715d356 100644 --- a/ch3-coop/os/fn.rust_main.html +++ b/ch3-coop/os/fn.rust_main.html @@ -1,7 +1,8 @@ -rust_main in os - Rust +rust_main in os - Rust
-

Function os::rust_main

source · []
#[no_mangle]
-pub fn rust_main() -> !
+

Function os::rust_main

source · []
#[no_mangle]
+pub fn rust_main() -> !
Expand description

the rust entry-point of os

+
\ No newline at end of file diff --git a/ch3-coop/os/index.html b/ch3-coop/os/index.html index 1b24e54f..917705ad 100644 --- a/ch3-coop/os/index.html +++ b/ch3-coop/os/index.html @@ -1,9 +1,36 @@ -os - Rust +os - Rust
-

Crate os

source · []

Modules

-

Macros

-

Functions

-
+

Crate os

source · []
Expand description

The main module and entrypoint

+

Various facilities of the kernels are implemented as submodules. The most +important ones are:

+ +

The operating system also starts in this module. Kernel code starts +executing from entry.asm, after which rust_main() is called to +initialize various pieces of functionality. (See its source code for +details.)

+

We then call task::run_first_task() and for the first time go to +userspace.

+

Modules

+

Constants used in rCore

+

SBI console driver, for text output

+

The panic handler

+

Loading user applications into memory

+

SBI call wrappers

+

Synchronization and interior mutability primitives

+

Implementation of syscalls

+

Task management implementation

+

Trap handling functionality

+

Macros

+

print string macro

+

println string macro

+

Functions

+

clear BSS segment

+

the rust entry-point of os

+
\ No newline at end of file diff --git a/ch3-coop/os/lang_items/fn.panic.html b/ch3-coop/os/lang_items/fn.panic.html index 4109a3bb..6665430c 100644 --- a/ch3-coop/os/lang_items/fn.panic.html +++ b/ch3-coop/os/lang_items/fn.panic.html @@ -2,5 +2,5 @@
-

Function os::lang_items::panic

source · []
fn panic(info: &PanicInfo<'_>) -> !
+

Function os::lang_items::panic

source · []
fn panic(info: &PanicInfo<'_>) -> !
\ No newline at end of file diff --git a/ch3-coop/os/lang_items/index.html b/ch3-coop/os/lang_items/index.html index c333ed12..752216ad 100644 --- a/ch3-coop/os/lang_items/index.html +++ b/ch3-coop/os/lang_items/index.html @@ -1,7 +1,8 @@ -os::lang_items - Rust +os::lang_items - Rust
-

Module os::lang_items

source · []

Functions

+

Module os::lang_items

source · []
Expand description

The panic handler

+

Functions

\ No newline at end of file diff --git a/ch3-coop/os/loader/fn.get_base_i.html b/ch3-coop/os/loader/fn.get_base_i.html index 434485aa..41435638 100644 --- a/ch3-coop/os/loader/fn.get_base_i.html +++ b/ch3-coop/os/loader/fn.get_base_i.html @@ -2,6 +2,6 @@
-

Function os::loader::get_base_i

source · []
fn get_base_i(app_id: usize) -> usize
Expand description

Get base address of app i.

+

Function os::loader::get_base_i

source · []
fn get_base_i(app_id: usize) -> usize
Expand description

Get base address of app i.

\ No newline at end of file diff --git a/ch3-coop/os/loader/fn.get_num_app.html b/ch3-coop/os/loader/fn.get_num_app.html index 4a6761d2..e9fa2cf1 100644 --- a/ch3-coop/os/loader/fn.get_num_app.html +++ b/ch3-coop/os/loader/fn.get_num_app.html @@ -2,6 +2,6 @@
-

Function os::loader::get_num_app

source · []
pub fn get_num_app() -> usize
Expand description

Get the total number of applications.

+

Function os::loader::get_num_app

source · []
pub fn get_num_app() -> usize
Expand description

Get the total number of applications.

\ No newline at end of file diff --git a/ch3-coop/os/loader/fn.init_app_cx.html b/ch3-coop/os/loader/fn.init_app_cx.html index c88c286a..b8b518ea 100644 --- a/ch3-coop/os/loader/fn.init_app_cx.html +++ b/ch3-coop/os/loader/fn.init_app_cx.html @@ -2,6 +2,6 @@
-

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 21e5962b..59b98c97 100644 --- a/ch3-coop/os/loader/fn.load_apps.html +++ b/ch3-coop/os/loader/fn.load_apps.html @@ -2,7 +2,7 @@
-

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 58ba6fa2..cc37a437 100644 --- a/ch3-coop/os/loader/index.html +++ b/ch3-coop/os/loader/index.html @@ -1,8 +1,13 @@ -os::loader - Rust +os::loader - Rust
-

Module os::loader

source · []

Structs

+

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 +KernelStack and UserStack.

+

Structs

Statics

Functions

Get base address of app i.

diff --git a/ch3-coop/os/loader/static.KERNEL_STACK.html b/ch3-coop/os/loader/static.KERNEL_STACK.html index 12045da1..8cdbea23 100644 --- a/ch3-coop/os/loader/static.KERNEL_STACK.html +++ b/ch3-coop/os/loader/static.KERNEL_STACK.html @@ -2,5 +2,5 @@
static KERNEL_STACK: [KernelStack; 4]
+

Static os::loader::KERNEL_STACK

source · []
static KERNEL_STACK: [KernelStack; 4]
\ No newline at end of file diff --git a/ch3-coop/os/loader/static.USER_STACK.html b/ch3-coop/os/loader/static.USER_STACK.html index 12c7cef5..ccb045c6 100644 --- a/ch3-coop/os/loader/static.USER_STACK.html +++ b/ch3-coop/os/loader/static.USER_STACK.html @@ -2,5 +2,5 @@
static USER_STACK: [UserStack; 4]
+

Static os::loader::USER_STACK

source · []
static USER_STACK: [UserStack; 4]
\ No newline at end of file diff --git a/ch3-coop/os/loader/struct.KernelStack.html b/ch3-coop/os/loader/struct.KernelStack.html index b9a1270e..8639a632 100644 --- a/ch3-coop/os/loader/struct.KernelStack.html +++ b/ch3-coop/os/loader/struct.KernelStack.html @@ -2,11 +2,11 @@
#[repr(align(4096))]
struct KernelStack { +

Struct os::loader::KernelStack

source · []
#[repr(align(4096))]
struct KernelStack { data: [u8; 8192], -}

Fields

data: [u8; 8192]

Implementations

Trait Implementations

Returns a copy of the value. Read more

+}

Fields

data: [u8; 8192]

Implementations

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

-

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

diff --git a/ch3-coop/os/loader/struct.UserStack.html b/ch3-coop/os/loader/struct.UserStack.html index 6f64b06b..ed652fe0 100644 --- a/ch3-coop/os/loader/struct.UserStack.html +++ b/ch3-coop/os/loader/struct.UserStack.html @@ -2,11 +2,11 @@
#[repr(align(4096))]
struct UserStack { +

Struct os::loader::UserStack

source · []
#[repr(align(4096))]
struct UserStack { data: [u8; 8192], -}

Fields

data: [u8; 8192]

Implementations

Trait Implementations

Returns a copy of the value. Read more

+}

Fields

data: [u8; 8192]

Implementations

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

-

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

diff --git a/ch3-coop/os/macro.print.html b/ch3-coop/os/macro.print.html index 17d519f7..bb6aceda 100644 --- a/ch3-coop/os/macro.print.html +++ b/ch3-coop/os/macro.print.html @@ -1,9 +1,10 @@ -print in os - Rust +print in os - Rust
-

Macro os::print

source · []
macro_rules! print {
+    

Macro os::print

source · []
macro_rules! print {
     ($fmt: literal $(, $($arg: tt)+)?) => { ... };
 }
-
+
Expand description

print string macro

+
\ No newline at end of file diff --git a/ch3-coop/os/macro.println.html b/ch3-coop/os/macro.println.html index 6f58012d..229b7103 100644 --- a/ch3-coop/os/macro.println.html +++ b/ch3-coop/os/macro.println.html @@ -1,9 +1,10 @@ -println in os - Rust +println in os - Rust
-

Macro os::println

source · []
macro_rules! println {
+    

Macro os::println

source · []
macro_rules! println {
     ($fmt: literal $(, $($arg: tt)+)?) => { ... };
 }
-
+
Expand description

println string macro

+
\ No newline at end of file diff --git a/ch3-coop/os/sbi/constant.SBI_CLEAR_IPI.html b/ch3-coop/os/sbi/constant.SBI_CLEAR_IPI.html deleted file mode 100644 index c191974c..00000000 --- a/ch3-coop/os/sbi/constant.SBI_CLEAR_IPI.html +++ /dev/null @@ -1,6 +0,0 @@ -SBI_CLEAR_IPI in os::sbi - Rust -
-

Constant os::sbi::SBI_CLEAR_IPI

source · []
const SBI_CLEAR_IPI: usize = 3;
- \ No newline at end of file diff --git a/ch3-coop/os/sbi/constant.SBI_CONSOLE_GETCHAR.html b/ch3-coop/os/sbi/constant.SBI_CONSOLE_GETCHAR.html deleted file mode 100644 index 12640c16..00000000 --- a/ch3-coop/os/sbi/constant.SBI_CONSOLE_GETCHAR.html +++ /dev/null @@ -1,6 +0,0 @@ -SBI_CONSOLE_GETCHAR in os::sbi - Rust -
const SBI_CONSOLE_GETCHAR: usize = 2;
- \ No newline at end of file diff --git a/ch3-coop/os/sbi/constant.SBI_CONSOLE_PUTCHAR.html b/ch3-coop/os/sbi/constant.SBI_CONSOLE_PUTCHAR.html index 11240f3f..9ec312e1 100644 --- a/ch3-coop/os/sbi/constant.SBI_CONSOLE_PUTCHAR.html +++ b/ch3-coop/os/sbi/constant.SBI_CONSOLE_PUTCHAR.html @@ -2,5 +2,5 @@
const SBI_CONSOLE_PUTCHAR: usize = 1;
+

Constant os::sbi::SBI_CONSOLE_PUTCHAR

source · []
const SBI_CONSOLE_PUTCHAR: usize = 1;
\ No newline at end of file diff --git a/ch3-coop/os/sbi/constant.SBI_REMOTE_FENCE_I.html b/ch3-coop/os/sbi/constant.SBI_REMOTE_FENCE_I.html deleted file mode 100644 index 35e0c19e..00000000 --- a/ch3-coop/os/sbi/constant.SBI_REMOTE_FENCE_I.html +++ /dev/null @@ -1,6 +0,0 @@ -SBI_REMOTE_FENCE_I in os::sbi - Rust -
const SBI_REMOTE_FENCE_I: usize = 5;
- \ No newline at end of file diff --git a/ch3-coop/os/sbi/constant.SBI_REMOTE_SFENCE_VMA.html b/ch3-coop/os/sbi/constant.SBI_REMOTE_SFENCE_VMA.html deleted file mode 100644 index 4bedd2b5..00000000 --- a/ch3-coop/os/sbi/constant.SBI_REMOTE_SFENCE_VMA.html +++ /dev/null @@ -1,6 +0,0 @@ -SBI_REMOTE_SFENCE_VMA in os::sbi - Rust -
const SBI_REMOTE_SFENCE_VMA: usize = 6;
- \ No newline at end of file diff --git a/ch3-coop/os/sbi/constant.SBI_REMOTE_SFENCE_VMA_ASID.html b/ch3-coop/os/sbi/constant.SBI_REMOTE_SFENCE_VMA_ASID.html deleted file mode 100644 index 06c69ce2..00000000 --- a/ch3-coop/os/sbi/constant.SBI_REMOTE_SFENCE_VMA_ASID.html +++ /dev/null @@ -1,6 +0,0 @@ -SBI_REMOTE_SFENCE_VMA_ASID in os::sbi - Rust -
const SBI_REMOTE_SFENCE_VMA_ASID: usize = 7;
- \ No newline at end of file diff --git a/ch3-coop/os/sbi/constant.SBI_SEND_IPI.html b/ch3-coop/os/sbi/constant.SBI_SEND_IPI.html deleted file mode 100644 index a3da3df2..00000000 --- a/ch3-coop/os/sbi/constant.SBI_SEND_IPI.html +++ /dev/null @@ -1,6 +0,0 @@ -SBI_SEND_IPI in os::sbi - Rust -
-

Constant os::sbi::SBI_SEND_IPI

source · []
const SBI_SEND_IPI: usize = 4;
- \ No newline at end of file diff --git a/ch3-coop/os/sbi/constant.SBI_SET_TIMER.html b/ch3-coop/os/sbi/constant.SBI_SET_TIMER.html deleted file mode 100644 index b8c22ab8..00000000 --- a/ch3-coop/os/sbi/constant.SBI_SET_TIMER.html +++ /dev/null @@ -1,6 +0,0 @@ -SBI_SET_TIMER in os::sbi - Rust -
-

Constant os::sbi::SBI_SET_TIMER

source · []
const SBI_SET_TIMER: usize = 0;
- \ No newline at end of file diff --git a/ch3-coop/os/sbi/constant.SBI_SHUTDOWN.html b/ch3-coop/os/sbi/constant.SBI_SHUTDOWN.html index 1019984f..4326bff5 100644 --- a/ch3-coop/os/sbi/constant.SBI_SHUTDOWN.html +++ b/ch3-coop/os/sbi/constant.SBI_SHUTDOWN.html @@ -2,5 +2,5 @@
-

Constant os::sbi::SBI_SHUTDOWN

source · []
const SBI_SHUTDOWN: usize = 8;
+

Constant os::sbi::SBI_SHUTDOWN

source · []
const SBI_SHUTDOWN: usize = 8;
\ No newline at end of file diff --git a/ch3-coop/os/sbi/fn.console_getchar.html b/ch3-coop/os/sbi/fn.console_getchar.html deleted file mode 100644 index 77867c6e..00000000 --- a/ch3-coop/os/sbi/fn.console_getchar.html +++ /dev/null @@ -1,7 +0,0 @@ -console_getchar in os::sbi - Rust -
pub fn console_getchar() -> usize
Expand description

use sbi call to getchar from console (qemu uart handler)

-
- \ No newline at end of file diff --git a/ch3-coop/os/sbi/fn.console_putchar.html b/ch3-coop/os/sbi/fn.console_putchar.html index 0cf1da13..42daa833 100644 --- a/ch3-coop/os/sbi/fn.console_putchar.html +++ b/ch3-coop/os/sbi/fn.console_putchar.html @@ -2,6 +2,6 @@
pub fn console_putchar(c: usize)
Expand description

use sbi call to putchar in console (qemu uart handler)

+

Function os::sbi::console_putchar

source · []
pub fn console_putchar(c: usize)
Expand description

use sbi call to putchar in console (qemu uart handler)

\ No newline at end of file diff --git a/ch3-coop/os/sbi/fn.sbi_call.html b/ch3-coop/os/sbi/fn.sbi_call.html index 00731305..6235e7f1 100644 --- a/ch3-coop/os/sbi/fn.sbi_call.html +++ b/ch3-coop/os/sbi/fn.sbi_call.html @@ -1,6 +1,7 @@ -sbi_call in os::sbi - Rust +sbi_call in os::sbi - Rust
-

Function os::sbi::sbi_call

source · []
fn sbi_call(which: usize, arg0: usize, arg1: usize, arg2: usize) -> usize
+

Function os::sbi::sbi_call

source · []
fn sbi_call(which: usize, arg0: usize, arg1: usize, arg2: usize) -> usize
Expand description

handle SBI call with which SBI_id and other arguments

+
\ No newline at end of file diff --git a/ch3-coop/os/sbi/fn.shutdown.html b/ch3-coop/os/sbi/fn.shutdown.html index 61b32df2..821fbf25 100644 --- a/ch3-coop/os/sbi/fn.shutdown.html +++ b/ch3-coop/os/sbi/fn.shutdown.html @@ -1,7 +1,8 @@ -shutdown in os::sbi - Rust +shutdown in os::sbi - Rust
-

Function os::sbi::shutdown

source · []
pub fn shutdown() -> !
Expand description

use sbi call to shutdown the kernel

+

Function os::sbi::shutdown

source · []
pub fn shutdown() -> !
Expand description

use sbi call to getchar from console (qemu uart handler) +use sbi call to shutdown the kernel

\ No newline at end of file diff --git a/ch3-coop/os/sbi/index.html b/ch3-coop/os/sbi/index.html index e9e82a59..20c93b16 100644 --- a/ch3-coop/os/sbi/index.html +++ b/ch3-coop/os/sbi/index.html @@ -1,11 +1,13 @@ -os::sbi - Rust +os::sbi - Rust
-

Module os::sbi

source · []

Constants

-

Functions

-

use sbi call to getchar from console (qemu uart handler)

-

use sbi call to putchar in console (qemu uart handler)

-

use sbi call to shutdown the kernel

+

Module os::sbi

source · []
Expand description

SBI call wrappers

+

Constants

+

Functions

+

use sbi call to putchar in console (qemu uart handler)

+

handle SBI call with which SBI_id and other arguments

+

use sbi call to getchar from console (qemu uart handler) +use sbi call to shutdown the kernel

\ No newline at end of file diff --git a/ch3-coop/os/sbi/sidebar-items.js b/ch3-coop/os/sbi/sidebar-items.js index 57e03764..d7d2fdc2 100644 --- a/ch3-coop/os/sbi/sidebar-items.js +++ b/ch3-coop/os/sbi/sidebar-items.js @@ -1 +1 @@ -initSidebarItems({"constant":[["SBI_CLEAR_IPI",""],["SBI_CONSOLE_GETCHAR",""],["SBI_CONSOLE_PUTCHAR",""],["SBI_REMOTE_FENCE_I",""],["SBI_REMOTE_SFENCE_VMA",""],["SBI_REMOTE_SFENCE_VMA_ASID",""],["SBI_SEND_IPI",""],["SBI_SET_TIMER",""],["SBI_SHUTDOWN",""]],"fn":[["console_getchar","use sbi call to getchar from console (qemu uart handler)"],["console_putchar","use sbi call to putchar in console (qemu uart handler)"],["sbi_call",""],["shutdown","use sbi call to shutdown the kernel"]]}); \ No newline at end of file +initSidebarItems({"constant":[["SBI_CONSOLE_PUTCHAR",""],["SBI_SHUTDOWN",""]],"fn":[["console_putchar","use sbi call to putchar in console (qemu uart handler)"],["sbi_call","handle SBI call with `which` SBI_id and other arguments"],["shutdown","use sbi call to getchar from console (qemu uart handler) use sbi call to shutdown the kernel"]]}); \ No newline at end of file diff --git a/ch3-coop/os/sidebar-items.js b/ch3-coop/os/sidebar-items.js index 0df58e87..d93a081c 100644 --- a/ch3-coop/os/sidebar-items.js +++ b/ch3-coop/os/sidebar-items.js @@ -1 +1 @@ -initSidebarItems({"fn":[["clear_bss",""],["rust_main",""]],"macro":[["print",""],["println",""]],"mod":[["config",""],["console",""],["lang_items",""],["loader",""],["sbi",""],["sync",""],["syscall",""],["task",""],["trap",""]]}); \ No newline at end of file +initSidebarItems({"fn":[["clear_bss","clear BSS segment"],["rust_main","the rust entry-point of os"]],"macro":[["print","print string macro"],["println","println string macro"]],"mod":[["config","Constants used in rCore"],["console","SBI console driver, for text output"],["lang_items","The panic handler"],["loader","Loading user applications into memory"],["sbi","SBI call wrappers"],["sync","Synchronization and interior mutability primitives"],["syscall","Implementation of syscalls"],["task","Task management implementation"],["trap","Trap handling functionality"]]}); \ No newline at end of file diff --git a/ch3-coop/os/sync/index.html b/ch3-coop/os/sync/index.html index 26fd3968..effcc859 100644 --- a/ch3-coop/os/sync/index.html +++ b/ch3-coop/os/sync/index.html @@ -1,8 +1,10 @@ -os::sync - Rust +os::sync - Rust
-

Module os::sync

source · []

Re-exports

+

Module os::sync

source · []
Expand description

Synchronization and interior mutability primitives

+

Re-exports

pub use up::UPSafeCell;

Modules

-
+

Uniprocessor interior mutability primitives

+
\ No newline at end of file diff --git a/ch3-coop/os/sync/sidebar-items.js b/ch3-coop/os/sync/sidebar-items.js index 440fc425..09d6027e 100644 --- a/ch3-coop/os/sync/sidebar-items.js +++ b/ch3-coop/os/sync/sidebar-items.js @@ -1 +1 @@ -initSidebarItems({"mod":[["up",""]]}); \ No newline at end of file +initSidebarItems({"mod":[["up","Uniprocessor interior mutability primitives"]]}); \ No newline at end of file diff --git a/ch3-coop/os/sync/up/index.html b/ch3-coop/os/sync/up/index.html index 26f07349..4faef20d 100644 --- a/ch3-coop/os/sync/up/index.html +++ b/ch3-coop/os/sync/up/index.html @@ -1,8 +1,9 @@ -os::sync::up - Rust +os::sync::up - Rust
-

Module os::sync::up

source · []

Structs

+

Module os::sync::up

source · []
Expand description

Uniprocessor interior mutability primitives

+

Structs

Wrap a static data structure inside it so that we are able to access it without any unsafe.

diff --git a/ch3-coop/os/sync/up/struct.UPSafeCell.html b/ch3-coop/os/sync/up/struct.UPSafeCell.html index d29e93de..006b5c1b 100644 --- a/ch3-coop/os/sync/up/struct.UPSafeCell.html +++ b/ch3-coop/os/sync/up/struct.UPSafeCell.html @@ -2,7 +2,7 @@
-

Struct os::sync::up::UPSafeCell

source · []
pub struct UPSafeCell<T> {
+    

Struct os::sync::up::UPSafeCell

source · []
pub struct UPSafeCell<T> {
     inner: RefCell<T>,
 }
Expand description

Wrap a static data structure inside it so that we are able to access it without any unsafe.

@@ -10,10 +10,10 @@ able to access it without any unsafe.

In order to get mutable reference of inner data, call exclusive_access.

Fields

inner: RefCell<T>

inner data

-

Implementations

User is responsible to guarantee that inner struct is only used in +

Implementations

User is responsible to guarantee that inner struct is only used in uniprocessor.

-

Panic if the data has been borrowed.

-

Trait Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+

Exclusive access inner data in UPSafeCell. Panic if the data has been borrowed.

+

Trait Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

diff --git a/ch3-coop/os/syscall/constant.SYSCALL_EXIT.html b/ch3-coop/os/syscall/constant.SYSCALL_EXIT.html index 53cf68dc..a7ac151b 100644 --- a/ch3-coop/os/syscall/constant.SYSCALL_EXIT.html +++ b/ch3-coop/os/syscall/constant.SYSCALL_EXIT.html @@ -2,5 +2,5 @@
const SYSCALL_EXIT: usize = 93;
+

Constant os::syscall::SYSCALL_EXIT

source · []
const SYSCALL_EXIT: usize = 93;
\ No newline at end of file diff --git a/ch3-coop/os/syscall/constant.SYSCALL_WRITE.html b/ch3-coop/os/syscall/constant.SYSCALL_WRITE.html index a37aec89..608006c0 100644 --- a/ch3-coop/os/syscall/constant.SYSCALL_WRITE.html +++ b/ch3-coop/os/syscall/constant.SYSCALL_WRITE.html @@ -2,5 +2,5 @@
const SYSCALL_WRITE: usize = 64;
+

Constant os::syscall::SYSCALL_WRITE

source · []
const SYSCALL_WRITE: usize = 64;
\ No newline at end of file diff --git a/ch3-coop/os/syscall/constant.SYSCALL_YIELD.html b/ch3-coop/os/syscall/constant.SYSCALL_YIELD.html index 126073c7..4bfc058a 100644 --- a/ch3-coop/os/syscall/constant.SYSCALL_YIELD.html +++ b/ch3-coop/os/syscall/constant.SYSCALL_YIELD.html @@ -2,5 +2,5 @@
const SYSCALL_YIELD: usize = 124;
+

Constant os::syscall::SYSCALL_YIELD

source · []
const SYSCALL_YIELD: usize = 124;
\ No newline at end of file diff --git a/ch3-coop/os/syscall/fn.syscall.html b/ch3-coop/os/syscall/fn.syscall.html index e0beff7f..23696945 100644 --- a/ch3-coop/os/syscall/fn.syscall.html +++ b/ch3-coop/os/syscall/fn.syscall.html @@ -2,6 +2,6 @@
-

Function os::syscall::syscall

source · []
pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize
Expand description

handle syscall exception with syscall_id and other arguments

+

Function os::syscall::syscall

source · []
pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize
Expand description

handle syscall exception with syscall_id and other arguments

\ No newline at end of file diff --git a/ch3-coop/os/syscall/fs/constant.FD_STDOUT.html b/ch3-coop/os/syscall/fs/constant.FD_STDOUT.html index a2a9bff0..e70dc6aa 100644 --- a/ch3-coop/os/syscall/fs/constant.FD_STDOUT.html +++ b/ch3-coop/os/syscall/fs/constant.FD_STDOUT.html @@ -2,5 +2,5 @@
-

Constant os::syscall::fs::FD_STDOUT

source · []
const FD_STDOUT: usize = 1;
+

Constant os::syscall::fs::FD_STDOUT

source · []
const FD_STDOUT: usize = 1;
\ No newline at end of file diff --git a/ch3-coop/os/syscall/fs/fn.sys_write.html b/ch3-coop/os/syscall/fs/fn.sys_write.html index b1b2e869..f99ebf0e 100644 --- a/ch3-coop/os/syscall/fs/fn.sys_write.html +++ b/ch3-coop/os/syscall/fs/fn.sys_write.html @@ -1,6 +1,7 @@ -sys_write in os::syscall::fs - Rust +sys_write in os::syscall::fs - Rust
-

Function os::syscall::fs::sys_write

source · []
pub fn sys_write(fd: usize, buf: *const u8, len: usize) -> isize
+

Function os::syscall::fs::sys_write

source · []
pub fn sys_write(fd: usize, buf: *const u8, len: usize) -> isize
Expand description

write buf of length len to a file with fd

+
\ No newline at end of file diff --git a/ch3-coop/os/syscall/fs/index.html b/ch3-coop/os/syscall/fs/index.html index 31b9eef4..fcb8e96f 100644 --- a/ch3-coop/os/syscall/fs/index.html +++ b/ch3-coop/os/syscall/fs/index.html @@ -1,8 +1,10 @@ -os::syscall::fs - Rust +os::syscall::fs - Rust
-

Module os::syscall::fs

source · []

Constants

+

Module os::syscall::fs

source · []
Expand description

File and filesystem-related syscalls

+

Constants

Functions

-
+

write buf of length len to a file with fd

+
\ No newline at end of file diff --git a/ch3-coop/os/syscall/fs/sidebar-items.js b/ch3-coop/os/syscall/fs/sidebar-items.js index 002a1085..99a1dcdc 100644 --- a/ch3-coop/os/syscall/fs/sidebar-items.js +++ b/ch3-coop/os/syscall/fs/sidebar-items.js @@ -1 +1 @@ -initSidebarItems({"constant":[["FD_STDOUT",""]],"fn":[["sys_write",""]]}); \ No newline at end of file +initSidebarItems({"constant":[["FD_STDOUT",""]],"fn":[["sys_write","write buf of length `len` to a file with `fd`"]]}); \ No newline at end of file diff --git a/ch3-coop/os/syscall/index.html b/ch3-coop/os/syscall/index.html index f6087d06..faadf910 100644 --- a/ch3-coop/os/syscall/index.html +++ b/ch3-coop/os/syscall/index.html @@ -1,9 +1,20 @@ -os::syscall - Rust +os::syscall - Rust
Expand description

Implementation of syscalls

+

The single entry point to all system calls, syscall(), is called +whenever userspace wishes to perform a system call using the ecall +instruction. In this case, the processor raises an ‘Environment call from +U-mode’ exception, which is handled as one of the cases in +crate::trap::trap_handler.

+

For clarity, each single syscall is implemented as its own function, named +sys_ then the name of the syscall. You can find functions like this in +submodules, and you should also implement syscalls this way.

+

Modules

+

File and filesystem-related syscalls

+

Process management syscalls

+

Constants

Functions

handle syscall exception with syscall_id and other arguments

diff --git a/ch3-coop/os/syscall/process/fn.sys_exit.html b/ch3-coop/os/syscall/process/fn.sys_exit.html index 2b0c7c4d..157a4863 100644 --- a/ch3-coop/os/syscall/process/fn.sys_exit.html +++ b/ch3-coop/os/syscall/process/fn.sys_exit.html @@ -2,6 +2,6 @@
pub fn sys_exit(exit_code: i32) -> !
Expand description

task exits and submit an exit code

+

Function os::syscall::process::sys_exit

source · []
pub fn sys_exit(exit_code: i32) -> !
Expand description

task exits and submit an exit code

\ No newline at end of file diff --git a/ch3-coop/os/syscall/process/fn.sys_yield.html b/ch3-coop/os/syscall/process/fn.sys_yield.html index 77fb8508..58f2ab5b 100644 --- a/ch3-coop/os/syscall/process/fn.sys_yield.html +++ b/ch3-coop/os/syscall/process/fn.sys_yield.html @@ -2,6 +2,6 @@
pub fn sys_yield() -> isize
Expand description

current task gives up resources for other tasks

+

Function os::syscall::process::sys_yield

source · []
pub fn sys_yield() -> isize
Expand description

current task gives up resources for other tasks

\ No newline at end of file diff --git a/ch3-coop/os/syscall/process/index.html b/ch3-coop/os/syscall/process/index.html index 85e18e39..4b103e79 100644 --- a/ch3-coop/os/syscall/process/index.html +++ b/ch3-coop/os/syscall/process/index.html @@ -1,8 +1,9 @@ -os::syscall::process - Rust +os::syscall::process - Rust
Expand description

Process management syscalls

+

Functions

task exits and submit an exit code

current task gives up resources for other tasks

diff --git a/ch3-coop/os/syscall/sidebar-items.js b/ch3-coop/os/syscall/sidebar-items.js index 9ed280ec..e8e24a71 100644 --- a/ch3-coop/os/syscall/sidebar-items.js +++ b/ch3-coop/os/syscall/sidebar-items.js @@ -1 +1 @@ -initSidebarItems({"constant":[["SYSCALL_EXIT",""],["SYSCALL_WRITE",""],["SYSCALL_YIELD",""]],"fn":[["syscall","handle syscall exception with `syscall_id` and other arguments"]],"mod":[["fs",""],["process",""]]}); \ No newline at end of file +initSidebarItems({"constant":[["SYSCALL_EXIT",""],["SYSCALL_WRITE",""],["SYSCALL_YIELD",""]],"fn":[["syscall","handle syscall exception with `syscall_id` and other arguments"]],"mod":[["fs","File and filesystem-related syscalls"],["process","Process management syscalls"]]}); \ No newline at end of file diff --git a/ch3-coop/os/task/context/index.html b/ch3-coop/os/task/context/index.html index 17629096..18356785 100644 --- a/ch3-coop/os/task/context/index.html +++ b/ch3-coop/os/task/context/index.html @@ -1,7 +1,9 @@ -os::task::context - Rust +os::task::context - Rust
+

Module os::task::context

source · []
Expand description

Implementation of TaskContext

+

Structs

+

Task Context

+
\ No newline at end of file diff --git a/ch3-coop/os/task/context/sidebar-items.js b/ch3-coop/os/task/context/sidebar-items.js index 86a68385..a79aab67 100644 --- a/ch3-coop/os/task/context/sidebar-items.js +++ b/ch3-coop/os/task/context/sidebar-items.js @@ -1 +1 @@ -initSidebarItems({"struct":[["TaskContext",""]]}); \ No newline at end of file +initSidebarItems({"struct":[["TaskContext","Task Context"]]}); \ No newline at end of file diff --git a/ch3-coop/os/task/context/struct.TaskContext.html b/ch3-coop/os/task/context/struct.TaskContext.html index c036e41a..3a36669b 100644 --- a/ch3-coop/os/task/context/struct.TaskContext.html +++ b/ch3-coop/os/task/context/struct.TaskContext.html @@ -1,14 +1,20 @@ -TaskContext in os::task::context - Rust +TaskContext in os::task::context - Rust
#[repr(C)]
pub struct TaskContext { +

Struct os::task::context::TaskContext

source · []
#[repr(C)]
pub struct TaskContext { ra: usize, sp: usize, s: [usize; 12], -}

Fields

ra: usizesp: usizes: [usize; 12]

Implementations

Trait Implementations

Returns a copy of the value. Read more

+}
Expand description

Task Context

+

Fields

ra: usize

return address ( e.g. __restore ) of __switch ASM function

+
sp: usize

kernel stack pointer of app

+
s: [usize; 12]

callee saved registers: s 0..11

+

Implementations

init task context

+

set task context {__restore ASM funciton, kernel stack, s_0..12 }

+

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

-

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

diff --git a/ch3-coop/os/task/fn.exit_current_and_run_next.html b/ch3-coop/os/task/fn.exit_current_and_run_next.html index 5f84fcde..b008dec6 100644 --- a/ch3-coop/os/task/fn.exit_current_and_run_next.html +++ b/ch3-coop/os/task/fn.exit_current_and_run_next.html @@ -1,6 +1,7 @@ -exit_current_and_run_next in os::task - Rust +exit_current_and_run_next in os::task - Rust
pub fn exit_current_and_run_next()
+

Function os::task::exit_current_and_run_next

source · []
pub fn exit_current_and_run_next()
Expand description

exit current task, then run next task

+
\ No newline at end of file diff --git a/ch3-coop/os/task/fn.mark_current_exited.html b/ch3-coop/os/task/fn.mark_current_exited.html index 02abd5ff..35b3b300 100644 --- a/ch3-coop/os/task/fn.mark_current_exited.html +++ b/ch3-coop/os/task/fn.mark_current_exited.html @@ -1,6 +1,7 @@ -mark_current_exited in os::task - Rust +mark_current_exited in os::task - Rust
fn mark_current_exited()
+

Function os::task::mark_current_exited

source · []
fn mark_current_exited()
Expand description

exit current task

+
\ No newline at end of file diff --git a/ch3-coop/os/task/fn.mark_current_suspended.html b/ch3-coop/os/task/fn.mark_current_suspended.html index 221ecdfd..6c86eb82 100644 --- a/ch3-coop/os/task/fn.mark_current_suspended.html +++ b/ch3-coop/os/task/fn.mark_current_suspended.html @@ -1,6 +1,7 @@ -mark_current_suspended in os::task - Rust +mark_current_suspended in os::task - Rust
fn mark_current_suspended()
+

Function os::task::mark_current_suspended

source · []
fn mark_current_suspended()
Expand description

suspend current task

+
\ No newline at end of file diff --git a/ch3-coop/os/task/fn.run_first_task.html b/ch3-coop/os/task/fn.run_first_task.html index 55d4f690..c9cd8f12 100644 --- a/ch3-coop/os/task/fn.run_first_task.html +++ b/ch3-coop/os/task/fn.run_first_task.html @@ -1,6 +1,7 @@ -run_first_task in os::task - Rust +run_first_task in os::task - Rust
pub fn run_first_task()
+

Function os::task::run_first_task

source · []
pub fn run_first_task()
Expand description

run first task

+
\ No newline at end of file diff --git a/ch3-coop/os/task/fn.run_next_task.html b/ch3-coop/os/task/fn.run_next_task.html index cfdf927a..48c2e9cf 100644 --- a/ch3-coop/os/task/fn.run_next_task.html +++ b/ch3-coop/os/task/fn.run_next_task.html @@ -1,6 +1,7 @@ -run_next_task in os::task - Rust +run_next_task in os::task - Rust
-

Function os::task::run_next_task

source · []
fn run_next_task()
+

Function os::task::run_next_task

source · []
fn run_next_task()
Expand description

rust next task

+
\ No newline at end of file diff --git a/ch3-coop/os/task/fn.suspend_current_and_run_next.html b/ch3-coop/os/task/fn.suspend_current_and_run_next.html index 09385bd8..7beab2a7 100644 --- a/ch3-coop/os/task/fn.suspend_current_and_run_next.html +++ b/ch3-coop/os/task/fn.suspend_current_and_run_next.html @@ -1,6 +1,7 @@ -suspend_current_and_run_next in os::task - Rust +suspend_current_and_run_next in os::task - Rust
pub fn suspend_current_and_run_next()
+

Function os::task::suspend_current_and_run_next

source · []
pub fn suspend_current_and_run_next()
Expand description

suspend current task, then run next task

+
\ No newline at end of file diff --git a/ch3-coop/os/task/index.html b/ch3-coop/os/task/index.html index b7f39d68..ad60454f 100644 --- a/ch3-coop/os/task/index.html +++ b/ch3-coop/os/task/index.html @@ -1,10 +1,29 @@ -os::task - Rust +os::task - Rust
+

Module os::task

source · []
Expand description

Task management implementation

+

Everything about task management, like starting and switching tasks is +implemented here.

+

A single global instance of TaskManager called TASK_MANAGER controls +all the tasks in the operating system.

+

Be careful when you see __switch ASM function in switch.S. Control flow around this function +might not be what you expect.

+

Modules

+

Implementation of TaskContext

+

Rust wrapper around __switch.

+

Types related to task management

+

Structs

+

Global variable: TASK_MANAGER

+

Task Context

+

The task manager, where all the tasks are managed.

+

Inner of Task Manager

+

Functions

+

exit current task, then run next task

+

exit current task

+

suspend current task

+

run first task

+

rust next task

+

suspend current task, then run next task

+
\ No newline at end of file diff --git a/ch3-coop/os/task/sidebar-items.js b/ch3-coop/os/task/sidebar-items.js index 43227bc9..025c860d 100644 --- a/ch3-coop/os/task/sidebar-items.js +++ b/ch3-coop/os/task/sidebar-items.js @@ -1 +1 @@ -initSidebarItems({"fn":[["exit_current_and_run_next",""],["mark_current_exited",""],["mark_current_suspended",""],["run_first_task",""],["run_next_task",""],["suspend_current_and_run_next",""]],"mod":[["context",""],["switch",""],["task",""]],"struct":[["TASK_MANAGER",""],["TaskManager",""],["TaskManagerInner",""]]}); \ No newline at end of file +initSidebarItems({"fn":[["exit_current_and_run_next","exit current task, then run next task"],["mark_current_exited","exit current task"],["mark_current_suspended","suspend current task"],["run_first_task","run first task"],["run_next_task","rust next task"],["suspend_current_and_run_next","suspend current task, then run next task"]],"mod":[["context","Implementation of [`TaskContext`]"],["switch","Rust wrapper around `__switch`."],["task","Types related to task management"]],"struct":[["TASK_MANAGER","Global variable: TASK_MANAGER"],["TaskContext","Task Context"],["TaskManager","The task manager, where all the tasks are managed."],["TaskManagerInner","Inner of Task Manager"]]}); \ No newline at end of file diff --git a/ch3-coop/os/task/struct.TASK_MANAGER.html b/ch3-coop/os/task/struct.TASK_MANAGER.html index d54e3aec..490367ac 100644 --- a/ch3-coop/os/task/struct.TASK_MANAGER.html +++ b/ch3-coop/os/task/struct.TASK_MANAGER.html @@ -1,21 +1,22 @@ -TASK_MANAGER in os::task - Rust +TASK_MANAGER in os::task - Rust
pub struct TASK_MANAGER {
+    

Struct os::task::TASK_MANAGER

source · []
pub struct TASK_MANAGER {
     __private_field: (),
-}

Fields

__private_field: ()

Methods from Deref<Target = TaskManager>

Run the first task in task list.

+}
Expand description

Global variable: TASK_MANAGER

+

Fields

__private_field: ()

Methods from Deref<Target = TaskManager>

Run the first task in task list.

Generally, the first task in task list is an idle task (we call it zero process later). But in ch3, we load apps statically, so the first task is a real app.

-

Change the status of current Running task into Ready.

-

Change the status of current Running task into Exited.

-

Find next task to run and return app id.

+

Change the status of current Running task into Ready.

+

Change the status of current Running task into Exited.

+

Find next task to run and return app id.

In this case, we only return the first Ready task in task list.

-

Switch current Running task to the task we have found, +

Switch current Running task to the task we have found, or there is no Ready task and we can exit with all applications completed

-

Trait Implementations

The resulting type after dereferencing.

-

Dereferences the value.

-

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+

Trait Implementations

The resulting type after dereferencing.

+

Dereferences the value.

+

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

diff --git a/ch3-coop/os/task/struct.TaskContext.html b/ch3-coop/os/task/struct.TaskContext.html new file mode 100644 index 00000000..8ef89ec6 --- /dev/null +++ b/ch3-coop/os/task/struct.TaskContext.html @@ -0,0 +1,27 @@ +TaskContext in os::task - Rust +
#[repr(C)]
pub struct TaskContext { + ra: usize, + sp: usize, + s: [usize; 12], +}
Expand description

Task Context

+

Fields

ra: usize

return address ( e.g. __restore ) of __switch ASM function

+
sp: usize

kernel stack pointer of app

+
s: [usize; 12]

callee saved registers: s 0..11

+

Implementations

init task context

+

set task context {__restore ASM funciton, kernel stack, s_0..12 }

+

Trait Implementations

Returns a copy of the value. Read more

+

Performs copy-assignment from source. Read more

+

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+

Immutably borrows from an owned value. Read more

+

Mutably borrows from an owned value. Read more

+

Performs the conversion.

+

Performs the conversion.

+

The type returned in the event of a conversion error.

+

Performs the conversion.

+

The type returned in the event of a conversion error.

+

Performs the conversion.

+
+ \ No newline at end of file diff --git a/ch3-coop/os/task/struct.TaskManager.html b/ch3-coop/os/task/struct.TaskManager.html index 34867269..3cd8ed54 100644 --- a/ch3-coop/os/task/struct.TaskManager.html +++ b/ch3-coop/os/task/struct.TaskManager.html @@ -1,20 +1,27 @@ -TaskManager in os::task - Rust +TaskManager in os::task - Rust
pub struct TaskManager {
+    

Struct os::task::TaskManager

source · []
pub struct TaskManager {
     num_app: usize,
     inner: UPSafeCell<TaskManagerInner>,
-}

Fields

num_app: usize

total number of tasks

+}
Expand description

The task manager, where all the tasks are managed.

+

Functions implemented on TaskManager deals with all task state transitions +and task context switching. For convenience, you can find wrappers around it +in the module level.

+

Most of TaskManager are hidden behind the field inner, to defer +borrowing checks to runtime. You can see examples on how to use inner in +existing functions on TaskManager.

+

Fields

num_app: usize

total number of tasks

inner: UPSafeCell<TaskManagerInner>

use inner value to get mutable access

-

Implementations

Run the first task in task list.

+

Implementations

Run the first task in task list.

Generally, the first task in task list is an idle task (we call it zero process later). But in ch3, we load apps statically, so the first task is a real app.

-

Change the status of current Running task into Ready.

-

Change the status of current Running task into Exited.

-

Find next task to run and return app id.

+

Change the status of current Running task into Ready.

+

Change the status of current Running task into Exited.

+

Find next task to run and return app id.

In this case, we only return the first Ready task in task list.

-

Switch current Running task to the task we have found, +

Switch current Running task to the task we have found, or there is no Ready task and we can exit with all applications completed

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

diff --git a/ch3-coop/os/task/struct.TaskManagerInner.html b/ch3-coop/os/task/struct.TaskManagerInner.html index 640b199b..4ed1238c 100644 --- a/ch3-coop/os/task/struct.TaskManagerInner.html +++ b/ch3-coop/os/task/struct.TaskManagerInner.html @@ -1,11 +1,12 @@ -TaskManagerInner in os::task - Rust +TaskManagerInner in os::task - Rust
struct TaskManagerInner {
+    

Struct os::task::TaskManagerInner

source · []
pub struct TaskManagerInner {
     tasks: [TaskControlBlock; 4],
     current_task: usize,
-}

Fields

tasks: [TaskControlBlock; 4]

task list

+}
Expand description

Inner of Task Manager

+

Fields

tasks: [TaskControlBlock; 4]

task list

current_task: usize

id of current Running task

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

diff --git a/ch3-coop/os/task/switch/fn.__switch.html b/ch3-coop/os/task/switch/fn.__switch.html index 7d5e620d..155d91c2 100644 --- a/ch3-coop/os/task/switch/fn.__switch.html +++ b/ch3-coop/os/task/switch/fn.__switch.html @@ -1,6 +1,8 @@ -__switch in os::task::switch - Rust +__switch in os::task::switch - Rust
-

Function os::task::switch::__switch

source · []
pub unsafe extern "C" fn __switch(
    current_task_cx_ptr: *mut TaskContext,
    next_task_cx_ptr: *const TaskContext
)
+

Function os::task::switch::__switch

source · []
pub unsafe extern "C" fn __switch(
    current_task_cx_ptr: *mut TaskContext,
    next_task_cx_ptr: *const TaskContext
)
Expand description

Switch to the context of next_task_cx_ptr, saving the current context +in current_task_cx_ptr.

+
\ No newline at end of file diff --git a/ch3-coop/os/task/switch/index.html b/ch3-coop/os/task/switch/index.html index c7c3e27b..76fd9087 100644 --- a/ch3-coop/os/task/switch/index.html +++ b/ch3-coop/os/task/switch/index.html @@ -1,7 +1,14 @@ -os::task::switch - Rust +os::task::switch - Rust
+

Module os::task::switch

source · []
Expand description

Rust wrapper around __switch.

+

Switching to a different task’s context happens here. The actual +implementation must not be in Rust and (essentially) has to be in assembly +language (Do you know why?), so this module really is just a wrapper around +switch.S.

+

Functions

+

Switch to the context of next_task_cx_ptr, saving the current context +in current_task_cx_ptr.

+
\ No newline at end of file diff --git a/ch3-coop/os/task/switch/sidebar-items.js b/ch3-coop/os/task/switch/sidebar-items.js index 59e64029..e12d73ff 100644 --- a/ch3-coop/os/task/switch/sidebar-items.js +++ b/ch3-coop/os/task/switch/sidebar-items.js @@ -1 +1 @@ -initSidebarItems({"fn":[["__switch",""]]}); \ No newline at end of file +initSidebarItems({"fn":[["__switch","Switch to the context of `next_task_cx_ptr`, saving the current context in `current_task_cx_ptr`."]]}); \ No newline at end of file diff --git a/ch3-coop/os/task/task/enum.TaskStatus.html b/ch3-coop/os/task/task/enum.TaskStatus.html index a60a6041..d5ce4780 100644 --- a/ch3-coop/os/task/task/enum.TaskStatus.html +++ b/ch3-coop/os/task/task/enum.TaskStatus.html @@ -2,17 +2,17 @@
pub enum TaskStatus {
+    

Enum os::task::task::TaskStatus

source · []
pub enum TaskStatus {
     UnInit,
     Ready,
     Running,
     Exited,
-}

Variants

UnInit

Ready

Running

Exited

Trait Implementations

Returns a copy of the value. Read more

+}

Variants

UnInit

Ready

Running

Exited

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

-

This method tests for self and other values to be equal, and is used +

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

-

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

diff --git a/ch3-coop/os/task/task/index.html b/ch3-coop/os/task/task/index.html index d95126a0..9b4504c9 100644 --- a/ch3-coop/os/task/task/index.html +++ b/ch3-coop/os/task/task/index.html @@ -1,8 +1,9 @@ -os::task::task - Rust +os::task::task - Rust
-

Module os::task::task

source · []

Structs

+

Module os::task::task

source · []
Expand description

Types related to task management

+

Structs

Enums

\ No newline at end of file diff --git a/ch3-coop/os/task/task/struct.TaskControlBlock.html b/ch3-coop/os/task/task/struct.TaskControlBlock.html index 85d69a0e..df7ed5be 100644 --- a/ch3-coop/os/task/task/struct.TaskControlBlock.html +++ b/ch3-coop/os/task/task/struct.TaskControlBlock.html @@ -2,12 +2,12 @@
pub struct TaskControlBlock {
+    

Struct os::task::task::TaskControlBlock

source · []
pub struct TaskControlBlock {
     pub task_status: TaskStatus,
     pub task_cx: TaskContext,
-}

Fields

task_status: TaskStatustask_cx: TaskContext

Trait Implementations

Returns a copy of the value. Read more

+}

Fields

task_status: TaskStatustask_cx: TaskContext

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

-

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

diff --git a/ch3-coop/os/trap/context/index.html b/ch3-coop/os/trap/context/index.html index f681954f..4531c273 100644 --- a/ch3-coop/os/trap/context/index.html +++ b/ch3-coop/os/trap/context/index.html @@ -2,6 +2,7 @@
+

Module os::trap::context

source · []

Structs

+

Trap Context

+
\ No newline at end of file diff --git a/ch3-coop/os/trap/context/sidebar-items.js b/ch3-coop/os/trap/context/sidebar-items.js index d7c5bfe2..c68e0844 100644 --- a/ch3-coop/os/trap/context/sidebar-items.js +++ b/ch3-coop/os/trap/context/sidebar-items.js @@ -1 +1 @@ -initSidebarItems({"struct":[["TrapContext",""]]}); \ No newline at end of file +initSidebarItems({"struct":[["TrapContext","Trap Context"]]}); \ No newline at end of file diff --git a/ch3-coop/os/trap/context/struct.TrapContext.html b/ch3-coop/os/trap/context/struct.TrapContext.html index ea75c16f..11ee8ae2 100644 --- a/ch3-coop/os/trap/context/struct.TrapContext.html +++ b/ch3-coop/os/trap/context/struct.TrapContext.html @@ -1,12 +1,18 @@ -TrapContext in os::trap::context - Rust +TrapContext in os::trap::context - Rust
#[repr(C)]
pub struct TrapContext { +

Struct os::trap::context::TrapContext

source · []
#[repr(C)]
pub struct TrapContext { pub x: [usize; 32], pub sstatus: Sstatus, pub sepc: usize, -}

Fields

x: [usize; 32]sstatus: Sstatussepc: usize

Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+}
Expand description

Trap Context

+

Fields

x: [usize; 32]

general regs[0..31]

+
sstatus: Sstatus

CSR sstatus

+
sepc: usize

CSR sepc

+

Implementations

set stack pointer to x_2 reg (sp)

+

init app context

+

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

diff --git a/ch3-coop/os/trap/fn.init.html b/ch3-coop/os/trap/fn.init.html index f2bbade7..6faad899 100644 --- a/ch3-coop/os/trap/fn.init.html +++ b/ch3-coop/os/trap/fn.init.html @@ -2,6 +2,6 @@
-

Function os::trap::init

source · []
pub fn init()
Expand description

initialize CSR stvec as the entry of __alltraps

+

Function os::trap::init

source · []
pub fn init()
Expand description

initialize CSR stvec as the entry of __alltraps

\ No newline at end of file diff --git a/ch3-coop/os/trap/fn.trap_handler.html b/ch3-coop/os/trap/fn.trap_handler.html index b85716c1..4b39eb33 100644 --- a/ch3-coop/os/trap/fn.trap_handler.html +++ b/ch3-coop/os/trap/fn.trap_handler.html @@ -2,7 +2,7 @@
-

Function os::trap::trap_handler

source · []
#[no_mangle]
+    

Function os::trap::trap_handler

source · []
#[no_mangle]
 pub fn trap_handler(cx: &mut TrapContext) -> &mut TrapContext
Expand description

handle an interrupt, exception, or system call from user space

\ No newline at end of file diff --git a/ch3-coop/os/trap/index.html b/ch3-coop/os/trap/index.html index 7d8e2f23..62e630d9 100644 --- a/ch3-coop/os/trap/index.html +++ b/ch3-coop/os/trap/index.html @@ -1,10 +1,21 @@ -os::trap - Rust +os::trap - Rust
-

Module os::trap

source · []

Re-exports

-
pub use context::TrapContext;

Modules

-

Functions

+

Module os::trap

source · []
Expand description

Trap handling functionality

+

For rCore, we have a single trap entry point, namely __alltraps. At +initialization in init(), we set the stvec CSR to point to it.

+

All traps go through __alltraps, which is defined in trap.S. The +assembly language code does just enough work restore the kernel space +context, ensuring that Rust code safely runs, and transfers control to +trap_handler().

+

It then calls different functionality based on what exactly the exception +was. For example, timer interrupts trigger task preemption, and syscalls go +to syscall().

+

Modules

+

Structs

+

Trap Context

+

Functions

initialize CSR stvec as the entry of __alltraps

handle an interrupt, exception, or system call from user space

diff --git a/ch3-coop/os/trap/sidebar-items.js b/ch3-coop/os/trap/sidebar-items.js index 445b06f2..79df6d2b 100644 --- a/ch3-coop/os/trap/sidebar-items.js +++ b/ch3-coop/os/trap/sidebar-items.js @@ -1 +1 @@ -initSidebarItems({"fn":[["init","initialize CSR `stvec` as the entry of `__alltraps`"],["trap_handler","handle an interrupt, exception, or system call from user space"]],"mod":[["context",""]]}); \ No newline at end of file +initSidebarItems({"fn":[["init","initialize CSR `stvec` as the entry of `__alltraps`"],["trap_handler","handle an interrupt, exception, or system call from user space"]],"mod":[["context",""]],"struct":[["TrapContext","Trap Context"]]}); \ No newline at end of file diff --git a/ch3-coop/os/trap/struct.TrapContext.html b/ch3-coop/os/trap/struct.TrapContext.html new file mode 100644 index 00000000..42ae2bba --- /dev/null +++ b/ch3-coop/os/trap/struct.TrapContext.html @@ -0,0 +1,25 @@ +TrapContext in os::trap - Rust +
#[repr(C)]
pub struct TrapContext { + pub x: [usize; 32], + pub sstatus: Sstatus, + pub sepc: usize, +}
Expand description

Trap Context

+

Fields

x: [usize; 32]

general regs[0..31]

+
sstatus: Sstatus

CSR sstatus

+
sepc: usize

CSR sepc

+

Implementations

set stack pointer to x_2 reg (sp)

+

init app context

+

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+

Immutably borrows from an owned value. Read more

+

Mutably borrows from an owned value. Read more

+

Performs the conversion.

+

Performs the conversion.

+

The type returned in the event of a conversion error.

+

Performs the conversion.

+

The type returned in the event of a conversion error.

+

Performs the conversion.

+
+ \ No newline at end of file diff --git a/ch3-coop/search-index.js b/ch3-coop/search-index.js index 0ad973fa..0434bfd2 100644 --- a/ch3-coop/search-index.js +++ b/ch3-coop/search-index.js @@ -1,4 +1,4 @@ var searchIndex = JSON.parse('{\ -"os":{"doc":"","t":[5,0,0,0,0,14,14,5,0,0,0,0,0,17,17,17,17,17,3,11,11,11,11,5,11,11,11,11,5,7,3,7,3,11,11,11,11,11,11,12,12,11,11,5,5,11,11,5,11,11,5,11,11,11,11,11,11,11,17,17,17,17,17,17,17,17,17,5,5,5,5,0,3,11,11,11,11,12,11,11,11,11,11,17,17,17,0,0,5,17,5,5,5,3,3,3,12,11,11,11,11,11,11,0,12,11,5,11,11,11,11,12,11,11,11,5,11,5,11,12,5,11,5,11,5,0,0,12,11,11,11,11,11,11,11,11,11,3,11,11,11,11,11,11,12,12,12,11,11,11,11,5,13,13,13,3,4,13,11,11,11,11,11,11,11,11,11,11,11,12,12,11,11,11,11,11,11,0,5,5,3,11,11,11,11,11,12,11,12,11,11,11,12],"n":["clear_bss","config","console","lang_items","loader","print","println","rust_main","sbi","sync","syscall","task","trap","APP_BASE_ADDRESS","APP_SIZE_LIMIT","KERNEL_STACK_SIZE","MAX_APP_NUM","USER_STACK_SIZE","Stdout","borrow","borrow_mut","from","into","print","try_from","try_into","type_id","write_str","panic","KERNEL_STACK","KernelStack","USER_STACK","UserStack","borrow","borrow","borrow_mut","borrow_mut","clone","clone","data","data","from","from","get_base_i","get_num_app","get_sp","get_sp","init_app_cx","into","into","load_apps","push_context","try_from","try_from","try_into","try_into","type_id","type_id","SBI_CLEAR_IPI","SBI_CONSOLE_GETCHAR","SBI_CONSOLE_PUTCHAR","SBI_REMOTE_FENCE_I","SBI_REMOTE_SFENCE_VMA","SBI_REMOTE_SFENCE_VMA_ASID","SBI_SEND_IPI","SBI_SET_TIMER","SBI_SHUTDOWN","console_getchar","console_putchar","sbi_call","shutdown","up","UPSafeCell","borrow","borrow_mut","exclusive_access","from","inner","into","new","try_from","try_into","type_id","SYSCALL_EXIT","SYSCALL_WRITE","SYSCALL_YIELD","fs","process","syscall","FD_STDOUT","sys_write","sys_exit","sys_yield","TASK_MANAGER","TaskManager","TaskManagerInner","__private_field","borrow","borrow","borrow","borrow_mut","borrow_mut","borrow_mut","context","current_task","deref","exit_current_and_run_next","find_next_task","from","from","from","inner","into","into","into","mark_current_exited","mark_current_exited","mark_current_suspended","mark_current_suspended","num_app","run_first_task","run_first_task","run_next_task","run_next_task","suspend_current_and_run_next","switch","task","tasks","try_from","try_from","try_from","try_into","try_into","try_into","type_id","type_id","type_id","TaskContext","borrow","borrow_mut","clone","from","goto_restore","into","ra","s","sp","try_from","try_into","type_id","zero_init","__switch","Exited","Ready","Running","TaskControlBlock","TaskStatus","UnInit","borrow","borrow","borrow_mut","borrow_mut","clone","clone","eq","from","from","into","into","task_cx","task_status","try_from","try_from","try_into","try_into","type_id","type_id","context","init","trap_handler","TrapContext","app_init_context","borrow","borrow_mut","from","into","sepc","set_sp","sstatus","try_from","try_into","type_id","x"],"q":["os","","","","","","","","","","","","","os::config","","","","","os::console","","","","","","","","","","os::lang_items","os::loader","","","","","","","","","","","","","","","","","","","","","","","","","","","","","os::sbi","","","","","","","","","","","","","os::sync","os::sync::up","","","","","","","","","","","os::syscall","","","","","","os::syscall::fs","","os::syscall::process","","os::task","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","os::task::context","","","","","","","","","","","","","","os::task::switch","os::task::task","","","","","","","","","","","","","","","","","","","","","","","","","os::trap","","","os::trap::context","","","","","","","","","","","",""],"d":["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","Get base address of app i.","Get the total number of applications.","","","get app info with entry and sp and save TrapContext in …","","","Load nth user app at [APP_BASE_ADDRESS + n * …","","","","","","","","","","","","","","","","","use sbi call to getchar from console (qemu uart handler)","use sbi call to putchar in console (qemu uart handler)","","use sbi call to shutdown the kernel","","Wrap a static data structure inside it so that we are able …","","","Panic if the data has been borrowed.","","inner data","","User is responsible to guarantee that inner struct is only …","","","","","","","","","handle syscall exception with syscall_id and other …","","","task exits and submit an exit code","current task gives up resources for other tasks","","","","","","","","","","","","id of current Running task","","","Find next task to run and return app id.","","","","use inner value to get mutable access","","","","","Change the status of current Running task into Exited.","","Change the status of current Running task into Ready.","total number of tasks","","Run the first task in task list.","","Switch current Running task to the task we have found, or …","","","","task list","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","initialize CSR stvec as the entry of __alltraps","handle an interrupt, exception, or system call from user …","","","","","","","","","","","","",""],"i":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,1,1,0,0,0,0,0,2,3,2,3,2,3,2,3,2,3,0,0,2,3,0,2,3,0,2,2,3,2,3,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,5,6,7,5,6,7,5,0,7,5,0,6,6,7,5,6,6,7,5,0,6,0,6,6,0,6,0,6,0,0,0,7,6,7,5,6,7,5,6,7,5,0,8,8,8,8,8,8,8,8,8,8,8,8,8,0,9,9,9,0,0,9,10,9,10,9,10,9,9,10,9,10,9,10,10,10,9,10,9,10,9,0,0,0,0,11,11,11,11,11,11,11,11,11,11,11,11],"f":[[[]],null,null,null,null,null,null,[[],["never",15]],null,null,null,null,null,null,null,null,null,null,null,[[]],[[]],[[]],[[]],[[["arguments",3]]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],[[["str",15]],["result",6]],[[["panicinfo",3]],["never",15]],null,null,null,null,[[]],[[]],[[]],[[]],[[],["kernelstack",3]],[[],["userstack",3]],null,null,[[]],[[]],[[["usize",15]],["usize",15]],[[],["usize",15]],[[],["usize",15]],[[],["usize",15]],[[["usize",15]],["usize",15]],[[]],[[]],[[]],[[["trapcontext",3]],["usize",15]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],[[],["typeid",3]],null,null,null,null,null,null,null,null,null,[[],["usize",15]],[[["usize",15]]],[[["usize",15],["usize",15],["usize",15],["usize",15]],["usize",15]],[[],["never",15]],null,null,[[]],[[]],[[],["refmut",3]],[[]],null,[[]],[[]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],null,null,null,null,null,[[["usize",15]],["isize",15]],null,[[["usize",15],["usize",15]],["isize",15]],[[["i32",15]],["never",15]],[[],["isize",15]],null,null,null,null,[[]],[[]],[[]],[[]],[[]],[[]],null,null,[[],["taskmanager",3]],[[]],[[],["option",4,[["usize",15]]]],[[]],[[]],[[]],null,[[]],[[]],[[]],[[]],[[]],[[]],[[]],null,[[]],[[],["never",15]],[[]],[[]],[[]],null,null,null,[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],[[],["typeid",3]],[[],["typeid",3]],null,[[]],[[]],[[],["taskcontext",3]],[[]],[[["usize",15]]],[[]],null,null,null,[[],["result",4]],[[],["result",4]],[[],["typeid",3]],[[]],null,null,null,null,null,null,null,[[]],[[]],[[]],[[]],[[],["taskcontrolblock",3]],[[],["taskstatus",4]],[[["taskstatus",4]],["bool",15]],[[]],[[]],[[]],[[]],null,null,[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],[[],["typeid",3]],null,[[]],[[["trapcontext",3]],["trapcontext",3]],null,[[["usize",15],["usize",15]]],[[]],[[]],[[]],[[]],null,[[["usize",15]]],null,[[],["result",4]],[[],["result",4]],[[],["typeid",3]],null],"p":[[3,"Stdout"],[3,"KernelStack"],[3,"UserStack"],[3,"UPSafeCell"],[3,"TASK_MANAGER"],[3,"TaskManager"],[3,"TaskManagerInner"],[3,"TaskContext"],[4,"TaskStatus"],[3,"TaskControlBlock"],[3,"TrapContext"]]}\ +"os":{"doc":"The main module and entrypoint","t":[5,0,0,0,0,14,14,5,0,0,0,0,0,17,17,17,17,17,3,11,11,11,11,5,11,11,11,11,5,7,3,7,3,11,11,11,11,11,11,12,12,11,11,5,5,11,11,5,11,11,5,11,11,11,11,11,11,11,17,17,5,5,5,0,3,11,11,11,11,12,11,11,11,11,11,17,17,17,0,0,5,17,5,5,5,3,3,3,3,12,11,11,11,11,11,11,0,12,11,5,11,11,11,11,12,11,11,11,5,11,5,11,12,12,5,11,5,11,12,12,5,0,0,12,11,11,11,11,11,11,11,11,11,3,11,11,11,11,11,11,12,12,12,11,11,11,11,5,13,13,13,3,4,13,11,11,11,11,11,11,11,11,11,11,11,12,12,11,11,11,11,11,11,3,0,5,12,12,5,12,3,11,11,11,11,11,12,11,12,11,11,11,12],"n":["clear_bss","config","console","lang_items","loader","print","println","rust_main","sbi","sync","syscall","task","trap","APP_BASE_ADDRESS","APP_SIZE_LIMIT","KERNEL_STACK_SIZE","MAX_APP_NUM","USER_STACK_SIZE","Stdout","borrow","borrow_mut","from","into","print","try_from","try_into","type_id","write_str","panic","KERNEL_STACK","KernelStack","USER_STACK","UserStack","borrow","borrow","borrow_mut","borrow_mut","clone","clone","data","data","from","from","get_base_i","get_num_app","get_sp","get_sp","init_app_cx","into","into","load_apps","push_context","try_from","try_from","try_into","try_into","type_id","type_id","SBI_CONSOLE_PUTCHAR","SBI_SHUTDOWN","console_putchar","sbi_call","shutdown","up","UPSafeCell","borrow","borrow_mut","exclusive_access","from","inner","into","new","try_from","try_into","type_id","SYSCALL_EXIT","SYSCALL_WRITE","SYSCALL_YIELD","fs","process","syscall","FD_STDOUT","sys_write","sys_exit","sys_yield","TASK_MANAGER","TaskContext","TaskManager","TaskManagerInner","__private_field","borrow","borrow","borrow","borrow_mut","borrow_mut","borrow_mut","context","current_task","deref","exit_current_and_run_next","find_next_task","from","from","from","inner","into","into","into","mark_current_exited","mark_current_exited","mark_current_suspended","mark_current_suspended","num_app","ra","run_first_task","run_first_task","run_next_task","run_next_task","s","sp","suspend_current_and_run_next","switch","task","tasks","try_from","try_from","try_from","try_into","try_into","try_into","type_id","type_id","type_id","TaskContext","borrow","borrow_mut","clone","from","goto_restore","into","ra","s","sp","try_from","try_into","type_id","zero_init","__switch","Exited","Ready","Running","TaskControlBlock","TaskStatus","UnInit","borrow","borrow","borrow_mut","borrow_mut","clone","clone","eq","from","from","into","into","task_cx","task_status","try_from","try_from","try_into","try_into","type_id","type_id","TrapContext","context","init","sepc","sstatus","trap_handler","x","TrapContext","app_init_context","borrow","borrow_mut","from","into","sepc","set_sp","sstatus","try_from","try_into","type_id","x"],"q":["os","","","","","","","","","","","","","os::config","","","","","os::console","","","","","","","","","","os::lang_items","os::loader","","","","","","","","","","","","","","","","","","","","","","","","","","","","","os::sbi","","","","","os::sync","os::sync::up","","","","","","","","","","","os::syscall","","","","","","os::syscall::fs","","os::syscall::process","","os::task","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","os::task::context","","","","","","","","","","","","","","os::task::switch","os::task::task","","","","","","","","","","","","","","","","","","","","","","","","","os::trap","","","","","","","os::trap::context","","","","","","","","","","","",""],"d":["clear BSS segment","Constants used in rCore","SBI console driver, for text output","The panic handler","Loading user applications into memory","print string macro","println string macro","the rust entry-point of os","SBI call wrappers","Synchronization and interior mutability primitives","Implementation of syscalls","Task management implementation","Trap handling functionality","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","Get base address of app i.","Get the total number of applications.","","","get app info with entry and sp and save TrapContext in …","","","Load nth user app at [APP_BASE_ADDRESS + n * …","","","","","","","","","","use sbi call to putchar in console (qemu uart handler)","handle SBI call with which SBI_id and other arguments","use sbi call to getchar from console (qemu uart handler) …","Uniprocessor interior mutability primitives","Wrap a static data structure inside it so that we are able …","","","Exclusive access inner data in UPSafeCell. Panic if the …","","inner data","","User is responsible to guarantee that inner struct is only …","","","","","","","File and filesystem-related syscalls","Process management syscalls","handle syscall exception with syscall_id and other …","","write buf of length len to a file with fd","task exits and submit an exit code","current task gives up resources for other tasks","Global variable: TASK_MANAGER","Task Context","The task manager, where all the tasks are managed.","Inner of Task Manager","","","","","","","","Implementation of TaskContext","id of current Running task","","exit current task, then run next task","Find next task to run and return app id.","","","","use inner value to get mutable access","","","","exit current task","Change the status of current Running task into Exited.","suspend current task","Change the status of current Running task into Ready.","total number of tasks","return address ( e.g. __restore ) of __switch ASM function","run first task","Run the first task in task list.","rust next task","Switch current Running task to the task we have found, or …","callee saved registers: s 0..11","kernel stack pointer of app","suspend current task, then run next task","Rust wrapper around __switch.","Types related to task management","task list","","","","","","","","","","Task Context","","","","","set task context {__restore ASM funciton, kernel stack, …","","return address ( e.g. __restore ) of __switch ASM function","callee saved registers: s 0..11","kernel stack pointer of app","","","","init task context","Switch to the context of next_task_cx_ptr, saving the …","","","","","","","","","","","","","","","","","","","","","","","","","","Trap Context","","initialize CSR stvec as the entry of __alltraps","CSR sepc","CSR sstatus ","handle an interrupt, exception, or system call from user …","general regs[0..31]","Trap Context","init app context","","","","","CSR sepc","set stack pointer to x_2 reg (sp)","CSR sstatus ","","","","general regs[0..31]"],"i":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,1,1,0,0,0,0,0,2,3,2,3,2,3,2,3,2,3,0,0,2,3,0,2,3,0,2,2,3,2,3,2,3,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,6,7,5,6,7,5,0,7,5,0,6,6,7,5,6,6,7,5,0,6,0,6,6,8,0,6,0,6,8,8,0,0,0,7,6,7,5,6,7,5,6,7,5,0,8,8,8,8,8,8,8,8,8,8,8,8,8,0,9,9,9,0,0,9,10,9,10,9,10,9,9,10,9,10,9,10,10,10,9,10,9,10,9,0,0,0,11,11,0,11,0,11,11,11,11,11,11,11,11,11,11,11,11],"f":[[[]],null,null,null,null,null,null,[[],["never",15]],null,null,null,null,null,null,null,null,null,null,null,[[]],[[]],[[]],[[]],[[["arguments",3]]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],[[["str",15]],["result",6]],[[["panicinfo",3]],["never",15]],null,null,null,null,[[]],[[]],[[]],[[]],[[],["kernelstack",3]],[[],["userstack",3]],null,null,[[]],[[]],[[["usize",15]],["usize",15]],[[],["usize",15]],[[],["usize",15]],[[],["usize",15]],[[["usize",15]],["usize",15]],[[]],[[]],[[]],[[["trapcontext",3]],["usize",15]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],[[],["typeid",3]],null,null,[[["usize",15]]],[[["usize",15],["usize",15],["usize",15],["usize",15]],["usize",15]],[[],["never",15]],null,null,[[]],[[]],[[],["refmut",3]],[[]],null,[[]],[[]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],null,null,null,null,null,[[["usize",15]],["isize",15]],null,[[["usize",15],["usize",15]],["isize",15]],[[["i32",15]],["never",15]],[[],["isize",15]],null,null,null,null,null,[[]],[[]],[[]],[[]],[[]],[[]],null,null,[[],["taskmanager",3]],[[]],[[],["option",4,[["usize",15]]]],[[]],[[]],[[]],null,[[]],[[]],[[]],[[]],[[]],[[]],[[]],null,null,[[]],[[],["never",15]],[[]],[[]],null,null,[[]],null,null,null,[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],[[],["typeid",3]],[[],["typeid",3]],null,[[]],[[]],[[],["taskcontext",3]],[[]],[[["usize",15]]],[[]],null,null,null,[[],["result",4]],[[],["result",4]],[[],["typeid",3]],[[]],null,null,null,null,null,null,null,[[]],[[]],[[]],[[]],[[],["taskcontrolblock",3]],[[],["taskstatus",4]],[[["taskstatus",4]],["bool",15]],[[]],[[]],[[]],[[]],null,null,[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],[[],["typeid",3]],null,null,[[]],null,null,[[["trapcontext",3]],["trapcontext",3]],null,null,[[["usize",15],["usize",15]]],[[]],[[]],[[]],[[]],null,[[["usize",15]]],null,[[],["result",4]],[[],["result",4]],[[],["typeid",3]],null],"p":[[3,"Stdout"],[3,"KernelStack"],[3,"UserStack"],[3,"UPSafeCell"],[3,"TASK_MANAGER"],[3,"TaskManager"],[3,"TaskManagerInner"],[3,"TaskContext"],[4,"TaskStatus"],[3,"TaskControlBlock"],[3,"TrapContext"]]}\ }'); if (window.initSearch) {window.initSearch(searchIndex)}; \ No newline at end of file diff --git a/ch3-coop/src/os/config.rs.html b/ch3-coop/src/os/config.rs.html index 1f95030d..a9036685 100644 --- a/ch3-coop/src/os/config.rs.html +++ b/ch3-coop/src/os/config.rs.html @@ -6,7 +6,11 @@ 3 4 5 -
pub const USER_STACK_SIZE: usize = 4096 * 2;
+6
+7
+
//! Constants used in rCore
+
+pub const USER_STACK_SIZE: usize = 4096 * 2;
 pub const KERNEL_STACK_SIZE: usize = 4096 * 2;
 pub const MAX_APP_NUM: usize = 4;
 pub const APP_BASE_ADDRESS: usize = 0x80400000;
diff --git a/ch3-coop/src/os/console.rs.html b/ch3-coop/src/os/console.rs.html
index 18c55e28..c3774d09 100644
--- a/ch3-coop/src/os/console.rs.html
+++ b/ch3-coop/src/os/console.rs.html
@@ -32,7 +32,13 @@
 29
 30
 31
-
use crate::sbi::console_putchar;
+32
+33
+34
+35
+
//! SBI console driver, for text output
+
+use crate::sbi::console_putchar;
 use core::fmt::{self, Write};
 
 struct Stdout;
@@ -50,6 +56,7 @@
     Stdout.write_fmt(args).unwrap();
 }
 
+/// print string macro
 #[macro_export]
 macro_rules! print {
     ($fmt: literal $(, $($arg: tt)+)?) => {
@@ -57,6 +64,7 @@
     }
 }
 
+/// println string macro
 #[macro_export]
 macro_rules! println {
     ($fmt: literal $(, $($arg: tt)+)?) => {
diff --git a/ch3-coop/src/os/lang_items.rs.html b/ch3-coop/src/os/lang_items.rs.html
index 696d616e..7685d650 100644
--- a/ch3-coop/src/os/lang_items.rs.html
+++ b/ch3-coop/src/os/lang_items.rs.html
@@ -18,7 +18,11 @@
 15
 16
 17
-
use crate::sbi::shutdown;
+18
+19
+
//! The panic handler
+
+use crate::sbi::shutdown;
 use core::panic::PanicInfo;
 
 #[panic_handler]
diff --git a/ch3-coop/src/os/loader.rs.html b/ch3-coop/src/os/loader.rs.html
index dc5db8be..5ac34254 100644
--- a/ch3-coop/src/os/loader.rs.html
+++ b/ch3-coop/src/os/loader.rs.html
@@ -92,7 +92,21 @@
 89
 90
 91
-
use crate::config::*;
+92
+93
+94
+95
+96
+97
+98
+
//! 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
+//! [`KernelStack`] and [`UserStack`].
+
+use crate::config::*;
 use crate::trap::TrapContext;
 use core::arch::asm;
 
diff --git a/ch3-coop/src/os/main.rs.html b/ch3-coop/src/os/main.rs.html
index c288cb0d..3c23a9e5 100644
--- a/ch3-coop/src/os/main.rs.html
+++ b/ch3-coop/src/os/main.rs.html
@@ -41,7 +41,47 @@
 38
 39
 40
-
#![no_std]
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+
//! The main module and entrypoint
+//!
+//! Various facilities of the kernels are implemented as submodules. The most
+//! important ones are:
+//!
+//! - [`trap`]: Handles all cases of switching from userspace to the kernel
+//! - [`task`]: Task management
+//! - [`syscall`]: System call handling and implementation
+//!
+//! The operating system also starts in this module. Kernel code starts
+//! executing from `entry.asm`, after which [`rust_main()`] is called to
+//! initialize various pieces of functionality. (See its source code for
+//! details.)
+//!
+//! We then call [`task::run_first_task()`] and for the first time go to
+//! userspace.
+
+#![deny(missing_docs)]
+#![deny(warnings)]
+#![no_std]
 #![no_main]
 #![feature(panic_info_message)]
 
@@ -54,13 +94,14 @@
 mod loader;
 mod sbi;
 mod sync;
-mod syscall;
-mod task;
-mod trap;
+pub mod syscall;
+pub mod task;
+pub mod trap;
 
 global_asm!(include_str!("entry.asm"));
 global_asm!(include_str!("link_app.S"));
 
+/// clear BSS segment
 fn clear_bss() {
     extern "C" {
         fn sbss();
@@ -72,6 +113,7 @@
     }
 }
 
+/// the rust entry-point of os
 #[no_mangle]
 pub fn rust_main() -> ! {
     clear_bss();
diff --git a/ch3-coop/src/os/sbi.rs.html b/ch3-coop/src/os/sbi.rs.html
index d29b5e20..45144cd4 100644
--- a/ch3-coop/src/os/sbi.rs.html
+++ b/ch3-coop/src/os/sbi.rs.html
@@ -45,20 +45,22 @@
 42
 43
 44
-
#![allow(unused)]
+45
+
//! SBI call wrappers
 
 use core::arch::asm;
 
-const SBI_SET_TIMER: usize = 0;
 const SBI_CONSOLE_PUTCHAR: usize = 1;
-const SBI_CONSOLE_GETCHAR: usize = 2;
-const SBI_CLEAR_IPI: usize = 3;
-const SBI_SEND_IPI: usize = 4;
-const SBI_REMOTE_FENCE_I: usize = 5;
-const SBI_REMOTE_SFENCE_VMA: usize = 6;
-const SBI_REMOTE_SFENCE_VMA_ASID: usize = 7;
 const SBI_SHUTDOWN: usize = 8;
+// const SBI_SET_TIMER: usize = 0;
+// const SBI_CONSOLE_GETCHAR: usize = 2;
+// const SBI_CLEAR_IPI: usize = 3;
+// const SBI_SEND_IPI: usize = 4;
+// const SBI_REMOTE_FENCE_I: usize = 5;
+// const SBI_REMOTE_SFENCE_VMA: usize = 6;
+// const SBI_REMOTE_SFENCE_VMA_ASID: usize = 7;
 
+///  handle SBI call with `which` SBI_id and other arguments
 #[inline(always)]
 fn sbi_call(which: usize, arg0: usize, arg1: usize, arg2: usize) -> usize {
     let mut ret;
@@ -80,9 +82,9 @@
 }
 
 /// use sbi call to getchar from console (qemu uart handler)
-pub fn console_getchar() -> usize {
-    sbi_call(SBI_CONSOLE_GETCHAR, 0, 0, 0)
-}
+// pub fn console_getchar() -> usize {
+//     sbi_call(SBI_CONSOLE_GETCHAR, 0, 0, 0)
+// }
 
 /// use sbi call to shutdown the kernel
 pub fn shutdown() -> ! {
diff --git a/ch3-coop/src/os/sync/mod.rs.html b/ch3-coop/src/os/sync/mod.rs.html
index 625d8d9d..4bd5e3b3 100644
--- a/ch3-coop/src/os/sync/mod.rs.html
+++ b/ch3-coop/src/os/sync/mod.rs.html
@@ -4,7 +4,11 @@
                                 
Change settings
1
 2
 3
-
mod up;
+4
+5
+
//! Synchronization and interior mutability primitives
+
+mod up;
 
 pub use up::UPSafeCell;
 
diff --git a/ch3-coop/src/os/sync/up.rs.html b/ch3-coop/src/os/sync/up.rs.html index 8e982968..45704751 100644 --- a/ch3-coop/src/os/sync/up.rs.html +++ b/ch3-coop/src/os/sync/up.rs.html @@ -30,7 +30,11 @@ 27 28 29 -
use core::cell::{RefCell, RefMut};
+30
+31
+
//! Uniprocessor interior mutability primitives
+
+use core::cell::{RefCell, RefMut};
 
 /// Wrap a static data structure inside it so that we are
 /// able to access it without any `unsafe`.
@@ -54,7 +58,7 @@
             inner: RefCell::new(value),
         }
     }
-    /// Panic if the data has been borrowed.
+    /// Exclusive access inner data in UPSafeCell. Panic if the data has been borrowed.
     pub fn exclusive_access(&self) -> RefMut<'_, T> {
         self.inner.borrow_mut()
     }
diff --git a/ch3-coop/src/os/syscall/fs.rs.html b/ch3-coop/src/os/syscall/fs.rs.html
index f883c38f..4cce3b3c 100644
--- a/ch3-coop/src/os/syscall/fs.rs.html
+++ b/ch3-coop/src/os/syscall/fs.rs.html
@@ -16,8 +16,14 @@
 13
 14
 15
-
const FD_STDOUT: usize = 1;
+16
+17
+18
+
//! File and filesystem-related syscalls
 
+const FD_STDOUT: usize = 1;
+
+/// write buf of length `len`  to a file with `fd`
 pub fn sys_write(fd: usize, buf: *const u8, len: usize) -> isize {
     match fd {
         FD_STDOUT => {
diff --git a/ch3-coop/src/os/syscall/mod.rs.html b/ch3-coop/src/os/syscall/mod.rs.html
index 32f70989..c970e1b3 100644
--- a/ch3-coop/src/os/syscall/mod.rs.html
+++ b/ch3-coop/src/os/syscall/mod.rs.html
@@ -21,7 +21,31 @@
 18
 19
 20
-
const SYSCALL_WRITE: usize = 64;
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+
//! Implementation of syscalls
+//!
+//! The single entry point to all system calls, [`syscall()`], is called
+//! whenever userspace wishes to perform a system call using the `ecall`
+//! instruction. In this case, the processor raises an 'Environment call from
+//! U-mode' exception, which is handled as one of the cases in
+//! [`crate::trap::trap_handler`].
+//!
+//! For clarity, each single syscall is implemented as its own function, named
+//! `sys_` then the name of the syscall. You can find functions like this in
+//! submodules, and you should also implement syscalls this way.
+
+const SYSCALL_WRITE: usize = 64;
 const SYSCALL_EXIT: usize = 93;
 const SYSCALL_YIELD: usize = 124;
 //const SYSCALL_GET_TIME: usize = 169;
diff --git a/ch3-coop/src/os/syscall/process.rs.html b/ch3-coop/src/os/syscall/process.rs.html
index a948d2d0..44de95c0 100644
--- a/ch3-coop/src/os/syscall/process.rs.html
+++ b/ch3-coop/src/os/syscall/process.rs.html
@@ -15,7 +15,9 @@
 12
 13
 14
-
use crate::task::{exit_current_and_run_next, suspend_current_and_run_next};
+15
+
//! Process management syscalls
+use crate::task::{exit_current_and_run_next, suspend_current_and_run_next};
 
 /// task exits and submit an exit code
 pub fn sys_exit(exit_code: i32) -> ! {
diff --git a/ch3-coop/src/os/task/context.rs.html b/ch3-coop/src/os/task/context.rs.html
index bad35a5f..0b6ba972 100644
--- a/ch3-coop/src/os/task/context.rs.html
+++ b/ch3-coop/src/os/task/context.rs.html
@@ -28,15 +28,31 @@
 25
 26
 27
-
#[derive(Copy, Clone)]
+28
+29
+30
+31
+32
+33
+34
+35
+36
+
//! Implementation of [`TaskContext`]
+
+/// Task Context
+#[derive(Copy, Clone)]
 #[repr(C)]
 pub struct TaskContext {
+    /// return address ( e.g. __restore ) of __switch ASM function
     ra: usize,
+    /// kernel stack pointer of app
     sp: usize,
+    /// callee saved registers:  s 0..11
     s: [usize; 12],
 }
 
 impl TaskContext {
+    /// init task context
     pub fn zero_init() -> Self {
         Self {
             ra: 0,
@@ -44,6 +60,8 @@
             s: [0; 12],
         }
     }
+
+    /// set task context {__restore ASM funciton, kernel stack, s_0..12 }
     pub fn goto_restore(kstack_ptr: usize) -> Self {
         extern "C" {
             fn __restore();
diff --git a/ch3-coop/src/os/task/mod.rs.html b/ch3-coop/src/os/task/mod.rs.html
index 11f4d2c6..515e9fe0 100644
--- a/ch3-coop/src/os/task/mod.rs.html
+++ b/ch3-coop/src/os/task/mod.rs.html
@@ -144,7 +144,46 @@
 141
 142
 143
-
mod context;
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+
//! Task management implementation
+//!
+//! Everything about task management, like starting and switching tasks is
+//! implemented here.
+//!
+//! A single global instance of [`TaskManager`] called `TASK_MANAGER` controls
+//! all the tasks in the operating system.
+//!
+//! Be careful when you see `__switch` ASM function in `switch.S`. Control flow around this function
+//! might not be what you expect.
+
+mod context;
 mod switch;
 
 #[allow(clippy::module_inception)]
@@ -159,6 +198,15 @@
 
 pub use context::TaskContext;
 
+/// The task manager, where all the tasks are managed.
+///
+/// Functions implemented on `TaskManager` deals with all task state transitions
+/// and task context switching. For convenience, you can find wrappers around it
+/// in the module level.
+///
+/// Most of `TaskManager` are hidden behind the field `inner`, to defer
+/// borrowing checks to runtime. You can see examples on how to use `inner` in
+/// existing functions on `TaskManager`.
 pub struct TaskManager {
     /// total number of tasks
     num_app: usize,
@@ -166,7 +214,8 @@
     inner: UPSafeCell<TaskManagerInner>,
 }
 
-struct TaskManagerInner {
+/// Inner of Task Manager
+pub struct TaskManagerInner {
     /// task list
     tasks: [TaskControlBlock; MAX_APP_NUM],
     /// id of current `Running` task
@@ -174,6 +223,7 @@
 }
 
 lazy_static! {
+    /// Global variable: TASK_MANAGER
     pub static ref TASK_MANAGER: TaskManager = {
         let num_app = get_num_app();
         let mut tasks = [TaskControlBlock {
@@ -262,27 +312,33 @@
     }
 }
 
+/// run first task
 pub fn run_first_task() {
     TASK_MANAGER.run_first_task();
 }
 
+/// rust next task
 fn run_next_task() {
     TASK_MANAGER.run_next_task();
 }
 
+/// suspend current task
 fn mark_current_suspended() {
     TASK_MANAGER.mark_current_suspended();
 }
 
+/// exit current task
 fn mark_current_exited() {
     TASK_MANAGER.mark_current_exited();
 }
 
+/// suspend current task, then run next task
 pub fn suspend_current_and_run_next() {
     mark_current_suspended();
     run_next_task();
 }
 
+/// exit current task,  then run next task
 pub fn exit_current_and_run_next() {
     mark_current_exited();
     run_next_task();
diff --git a/ch3-coop/src/os/task/switch.rs.html b/ch3-coop/src/os/task/switch.rs.html
index 416474a8..50b491fd 100644
--- a/ch3-coop/src/os/task/switch.rs.html
+++ b/ch3-coop/src/os/task/switch.rs.html
@@ -1,20 +1,38 @@
 switch.rs - source
     
1
-2
-3
-4
-5
-6
-7
-8
-
use super::TaskContext;
+                                
Change settings
 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16
+17
+
//! Rust wrapper around `__switch`.
+//!
+//! Switching to a different task's context happens here. The actual
+//! implementation must not be in Rust and (essentially) has to be in assembly
+//! language (Do you know why?), so this module really is just a wrapper around
+//! `switch.S`.
+
+use super::TaskContext;
 use core::arch::global_asm;
 
 global_asm!(include_str!("switch.S"));
 
 extern "C" {
+    /// Switch to the context of `next_task_cx_ptr`, saving the current context
+    /// in `current_task_cx_ptr`.
     pub fn __switch(current_task_cx_ptr: *mut TaskContext, next_task_cx_ptr: *const TaskContext);
 }
 
diff --git a/ch3-coop/src/os/task/task.rs.html b/ch3-coop/src/os/task/task.rs.html index a1c5eb3c..97195b29 100644 --- a/ch3-coop/src/os/task/task.rs.html +++ b/ch3-coop/src/os/task/task.rs.html @@ -16,7 +16,11 @@ 13 14 15 -
use super::TaskContext;
+16
+17
+
//! Types related to task management
+
+use super::TaskContext;
 
 #[derive(Copy, Clone)]
 pub struct TaskControlBlock {
diff --git a/ch3-coop/src/os/trap/context.rs.html b/ch3-coop/src/os/trap/context.rs.html
index 5b89852e..7d10e2f5 100644
--- a/ch3-coop/src/os/trap/context.rs.html
+++ b/ch3-coop/src/os/trap/context.rs.html
@@ -26,29 +26,39 @@
 23
 24
 25
+26
+27
+28
+29
+30
 
use riscv::register::sstatus::{self, Sstatus, SPP};
-
+/// Trap Context
 #[repr(C)]
 pub struct TrapContext {
+    /// general regs[0..31]
     pub x: [usize; 32],
+    /// CSR sstatus      
     pub sstatus: Sstatus,
+    /// CSR sepc
     pub sepc: usize,
 }
 
 impl TrapContext {
+    /// set stack pointer to x_2 reg (sp)
     pub fn set_sp(&mut self, sp: usize) {
         self.x[2] = sp;
     }
+    /// init app context
     pub fn app_init_context(entry: usize, sp: usize) -> Self {
-        let mut sstatus = sstatus::read();
-        sstatus.set_spp(SPP::User);
+        let mut sstatus = sstatus::read(); // CSR sstatus
+        sstatus.set_spp(SPP::User); //previous privilege mode: user mode
         let mut cx = Self {
             x: [0; 32],
             sstatus,
-            sepc: entry,
+            sepc: entry, // entry point of app
         };
-        cx.set_sp(sp);
-        cx
+        cx.set_sp(sp); // app's user stack pointer
+        cx // return initial Trap Context of app
     }
 }
 
diff --git a/ch3-coop/src/os/trap/mod.rs.html b/ch3-coop/src/os/trap/mod.rs.html index 1cf02b48..b4c39f6b 100644 --- a/ch3-coop/src/os/trap/mod.rs.html +++ b/ch3-coop/src/os/trap/mod.rs.html @@ -55,7 +55,35 @@ 52 53 54 -
mod context;
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+
//! Trap handling functionality
+//!
+//! For rCore, we have a single trap entry point, namely `__alltraps`. At
+//! initialization in [`init()`], we set the `stvec` CSR to point to it.
+//!
+//! All traps go through `__alltraps`, which is defined in `trap.S`. The
+//! assembly language code does just enough work restore the kernel space
+//! context, ensuring that Rust code safely runs, and transfers control to
+//! [`trap_handler()`].
+//!
+//! It then calls different functionality based on what exactly the exception
+//! was. For example, timer interrupts trigger task preemption, and syscalls go
+//! to [`syscall()`].
+
+mod context;
 
 use crate::syscall::syscall;
 use core::arch::global_asm;