diff --git a/ch2/os/all.html b/ch2/os/all.html index 928a1bec..8c07d38a 100644 --- a/ch2/os/all.html +++ b/ch2/os/all.html @@ -1,5 +1,5 @@ List of all items in this crate

List of all items

Structs

Macros

Functions

Statics

Constants

+ Change settings

List of all items

Structs

Macros

Functions

Statics

Constants

\ No newline at end of file diff --git a/ch2/os/batch/constant.APP_BASE_ADDRESS.html b/ch2/os/batch/constant.APP_BASE_ADDRESS.html index 86b30e48..7ce68650 100644 --- a/ch2/os/batch/constant.APP_BASE_ADDRESS.html +++ b/ch2/os/batch/constant.APP_BASE_ADDRESS.html @@ -2,5 +2,5 @@
const APP_BASE_ADDRESS: usize = 0x80400000;
+

Constant os::batch::APP_BASE_ADDRESS

source · []
const APP_BASE_ADDRESS: usize = 0x80400000;
\ No newline at end of file diff --git a/ch2/os/batch/constant.APP_SIZE_LIMIT.html b/ch2/os/batch/constant.APP_SIZE_LIMIT.html index 5b6892ee..2b0b413c 100644 --- a/ch2/os/batch/constant.APP_SIZE_LIMIT.html +++ b/ch2/os/batch/constant.APP_SIZE_LIMIT.html @@ -2,5 +2,5 @@
const APP_SIZE_LIMIT: usize = 0x20000;
+

Constant os::batch::APP_SIZE_LIMIT

source · []
const APP_SIZE_LIMIT: usize = 0x20000;
\ No newline at end of file diff --git a/ch2/os/batch/constant.KERNEL_STACK_SIZE.html b/ch2/os/batch/constant.KERNEL_STACK_SIZE.html index 51b6e54c..a2953385 100644 --- a/ch2/os/batch/constant.KERNEL_STACK_SIZE.html +++ b/ch2/os/batch/constant.KERNEL_STACK_SIZE.html @@ -2,5 +2,5 @@
const KERNEL_STACK_SIZE: usize = 4096 * 2; // 0x0000_0000_0000_2000usize
+

Constant os::batch::KERNEL_STACK_SIZE

source · []
const KERNEL_STACK_SIZE: usize = 4096 * 2; // 0x0000_0000_0000_2000usize
\ No newline at end of file diff --git a/ch2/os/batch/constant.MAX_APP_NUM.html b/ch2/os/batch/constant.MAX_APP_NUM.html index 1ab86b96..9f2c9ced 100644 --- a/ch2/os/batch/constant.MAX_APP_NUM.html +++ b/ch2/os/batch/constant.MAX_APP_NUM.html @@ -2,5 +2,5 @@
-

Constant os::batch::MAX_APP_NUM

source · []
const MAX_APP_NUM: usize = 16;
+

Constant os::batch::MAX_APP_NUM

source · []
const MAX_APP_NUM: usize = 16;
\ No newline at end of file diff --git a/ch2/os/batch/constant.USER_STACK_SIZE.html b/ch2/os/batch/constant.USER_STACK_SIZE.html index c1a1a9a7..7cce1ec5 100644 --- a/ch2/os/batch/constant.USER_STACK_SIZE.html +++ b/ch2/os/batch/constant.USER_STACK_SIZE.html @@ -2,5 +2,5 @@
const USER_STACK_SIZE: usize = 4096 * 2; // 0x0000_0000_0000_2000usize
+

Constant os::batch::USER_STACK_SIZE

source · []
const USER_STACK_SIZE: usize = 4096 * 2; // 0x0000_0000_0000_2000usize
\ No newline at end of file diff --git a/ch2/os/batch/fn.init.html b/ch2/os/batch/fn.init.html index cf06e0bb..f772b414 100644 --- a/ch2/os/batch/fn.init.html +++ b/ch2/os/batch/fn.init.html @@ -1,6 +1,7 @@ -init in os::batch - Rust +init in os::batch - Rust
-

Function os::batch::init

source · []
pub fn init()
+

Function os::batch::init

source · []
pub fn init()
Expand description

init batch subsystem

+
\ No newline at end of file diff --git a/ch2/os/batch/fn.print_app_info.html b/ch2/os/batch/fn.print_app_info.html index 97f857bf..2823035f 100644 --- a/ch2/os/batch/fn.print_app_info.html +++ b/ch2/os/batch/fn.print_app_info.html @@ -1,6 +1,7 @@ -print_app_info in os::batch - Rust +print_app_info in os::batch - Rust
pub fn print_app_info()
+

Function os::batch::print_app_info

source · []
pub fn print_app_info()
Expand description

print apps info

+
\ No newline at end of file diff --git a/ch2/os/batch/fn.run_next_app.html b/ch2/os/batch/fn.run_next_app.html index c8fa8d3c..c83629da 100644 --- a/ch2/os/batch/fn.run_next_app.html +++ b/ch2/os/batch/fn.run_next_app.html @@ -1,6 +1,7 @@ -run_next_app in os::batch - Rust +run_next_app in os::batch - Rust
-

Function os::batch::run_next_app

source · []
pub fn run_next_app() -> !
+

Function os::batch::run_next_app

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

run next app

+
\ No newline at end of file diff --git a/ch2/os/batch/index.html b/ch2/os/batch/index.html index ef8e8611..dc3d4c37 100644 --- a/ch2/os/batch/index.html +++ b/ch2/os/batch/index.html @@ -1,10 +1,14 @@ -os::batch - Rust +os::batch - Rust
-

Module os::batch

source · []

Structs

+

Module os::batch

source · []
Expand description

batch subsystem

+

Structs

Constants

Statics

Functions

-
+

init batch subsystem

+

print apps info

+

run next app

+
\ No newline at end of file diff --git a/ch2/os/batch/sidebar-items.js b/ch2/os/batch/sidebar-items.js index c3c891ba..c17f8d71 100644 --- a/ch2/os/batch/sidebar-items.js +++ b/ch2/os/batch/sidebar-items.js @@ -1 +1 @@ -initSidebarItems({"constant":[["APP_BASE_ADDRESS",""],["APP_SIZE_LIMIT",""],["KERNEL_STACK_SIZE",""],["MAX_APP_NUM",""],["USER_STACK_SIZE",""]],"fn":[["init",""],["print_app_info",""],["run_next_app",""]],"static":[["KERNEL_STACK",""],["USER_STACK",""]],"struct":[["APP_MANAGER",""],["AppManager",""],["KernelStack",""],["UserStack",""]]}); \ No newline at end of file +initSidebarItems({"constant":[["APP_BASE_ADDRESS",""],["APP_SIZE_LIMIT",""],["KERNEL_STACK_SIZE",""],["MAX_APP_NUM",""],["USER_STACK_SIZE",""]],"fn":[["init","init batch subsystem"],["print_app_info","print apps info"],["run_next_app","run next app"]],"static":[["KERNEL_STACK",""],["USER_STACK",""]],"struct":[["APP_MANAGER",""],["AppManager",""],["KernelStack",""],["UserStack",""]]}); \ No newline at end of file diff --git a/ch2/os/batch/static.KERNEL_STACK.html b/ch2/os/batch/static.KERNEL_STACK.html index eaad9f21..9138a0c9 100644 --- a/ch2/os/batch/static.KERNEL_STACK.html +++ b/ch2/os/batch/static.KERNEL_STACK.html @@ -2,5 +2,5 @@
static KERNEL_STACK: KernelStack
+

Static os::batch::KERNEL_STACK

source · []
static KERNEL_STACK: KernelStack
\ No newline at end of file diff --git a/ch2/os/batch/static.USER_STACK.html b/ch2/os/batch/static.USER_STACK.html index 41f8750b..9892c9f3 100644 --- a/ch2/os/batch/static.USER_STACK.html +++ b/ch2/os/batch/static.USER_STACK.html @@ -2,5 +2,5 @@
static USER_STACK: UserStack
+

Static os::batch::USER_STACK

source · []
static USER_STACK: UserStack
\ No newline at end of file diff --git a/ch2/os/batch/struct.APP_MANAGER.html b/ch2/os/batch/struct.APP_MANAGER.html index 2f07f53c..e95918fd 100644 --- a/ch2/os/batch/struct.APP_MANAGER.html +++ b/ch2/os/batch/struct.APP_MANAGER.html @@ -2,12 +2,12 @@
struct APP_MANAGER {
+    

Struct os::batch::APP_MANAGER

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

Fields

__private_field: ()

Methods from Deref<Target = UPSafeCell<AppManager>>

Panic if the data has been borrowed.

-

Trait Implementations

The resulting type after dereferencing.

-

Dereferences the value.

-

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+}

Fields

__private_field: ()

Methods from Deref<Target = UPSafeCell<AppManager>>

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

+

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/ch2/os/batch/struct.AppManager.html b/ch2/os/batch/struct.AppManager.html index f4647541..2021881b 100644 --- a/ch2/os/batch/struct.AppManager.html +++ b/ch2/os/batch/struct.AppManager.html @@ -2,11 +2,11 @@
struct AppManager {
+    

Struct os::batch::AppManager

source · []
struct AppManager {
     num_app: usize,
     current_app: usize,
     app_start: [usize; 17],
-}

Fields

num_app: usizecurrent_app: usizeapp_start: [usize; 17]

Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+}

Fields

num_app: usizecurrent_app: usizeapp_start: [usize; 17]

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/ch2/os/batch/struct.KernelStack.html b/ch2/os/batch/struct.KernelStack.html index 3a77e4d4..1d2a0fd5 100644 --- a/ch2/os/batch/struct.KernelStack.html +++ b/ch2/os/batch/struct.KernelStack.html @@ -2,9 +2,9 @@
#[repr(align(4096))]
struct KernelStack { +

Struct os::batch::KernelStack

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

Fields

data: [u8; 8192]

Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+}

Fields

data: [u8; 8192]

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/ch2/os/batch/struct.UserStack.html b/ch2/os/batch/struct.UserStack.html index f7db5e81..49d5b3ac 100644 --- a/ch2/os/batch/struct.UserStack.html +++ b/ch2/os/batch/struct.UserStack.html @@ -2,9 +2,9 @@
-

Struct os::batch::UserStack

source · []
#[repr(align(4096))]
struct UserStack { +

Struct os::batch::UserStack

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

Fields

data: [u8; 8192]

Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+}

Fields

data: [u8; 8192]

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/ch2/os/console/fn.print.html b/ch2/os/console/fn.print.html index 11eb46a6..cfcc29ed 100644 --- a/ch2/os/console/fn.print.html +++ b/ch2/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/ch2/os/console/index.html b/ch2/os/console/index.html index 20aa4929..d3626af6 100644 --- a/ch2/os/console/index.html +++ b/ch2/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/ch2/os/console/struct.Stdout.html b/ch2/os/console/struct.Stdout.html index aacab1d0..38dd2dcd 100644 --- a/ch2/os/console/struct.Stdout.html +++ b/ch2/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/ch2/os/fn.clear_bss.html b/ch2/os/fn.clear_bss.html index 67c8e8d4..4516fda5 100644 --- a/ch2/os/fn.clear_bss.html +++ b/ch2/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/ch2/os/fn.rust_main.html b/ch2/os/fn.rust_main.html index 8778f994..7993bac9 100644 --- a/ch2/os/fn.rust_main.html +++ b/ch2/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/ch2/os/index.html b/ch2/os/index.html index 99848c4d..a7b9ab09 100644 --- a/ch2/os/index.html +++ b/ch2/os/index.html @@ -1,9 +1,33 @@ -os - Rust +os - Rust
+

Crate os

source · []
Expand description

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
  • +
  • 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 batch::run_next_app() and for the first time go to +userspace.

+

Modules

+

batch subsystem

+

SBI console driver, for text output

+

The panic handler

+

SBI call wrappers

+

Synchronization and interior mutability primitives

+

Implementation of syscalls

+

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/ch2/os/lang_items/fn.panic.html b/ch2/os/lang_items/fn.panic.html index 4109a3bb..6665430c 100644 --- a/ch2/os/lang_items/fn.panic.html +++ b/ch2/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/ch2/os/lang_items/index.html b/ch2/os/lang_items/index.html index c333ed12..752216ad 100644 --- a/ch2/os/lang_items/index.html +++ b/ch2/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/ch2/os/macro.print.html b/ch2/os/macro.print.html index 17d519f7..bb6aceda 100644 --- a/ch2/os/macro.print.html +++ b/ch2/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/ch2/os/macro.println.html b/ch2/os/macro.println.html index 6f58012d..229b7103 100644 --- a/ch2/os/macro.println.html +++ b/ch2/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/ch2/os/sbi/constant.SBI_CLEAR_IPI.html b/ch2/os/sbi/constant.SBI_CLEAR_IPI.html deleted file mode 100644 index c191974c..00000000 --- a/ch2/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/ch2/os/sbi/constant.SBI_CONSOLE_GETCHAR.html b/ch2/os/sbi/constant.SBI_CONSOLE_GETCHAR.html deleted file mode 100644 index 12640c16..00000000 --- a/ch2/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/ch2/os/sbi/constant.SBI_CONSOLE_PUTCHAR.html b/ch2/os/sbi/constant.SBI_CONSOLE_PUTCHAR.html index 11240f3f..9ec312e1 100644 --- a/ch2/os/sbi/constant.SBI_CONSOLE_PUTCHAR.html +++ b/ch2/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/ch2/os/sbi/constant.SBI_REMOTE_FENCE_I.html b/ch2/os/sbi/constant.SBI_REMOTE_FENCE_I.html deleted file mode 100644 index 35e0c19e..00000000 --- a/ch2/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/ch2/os/sbi/constant.SBI_REMOTE_SFENCE_VMA.html b/ch2/os/sbi/constant.SBI_REMOTE_SFENCE_VMA.html deleted file mode 100644 index 4bedd2b5..00000000 --- a/ch2/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/ch2/os/sbi/constant.SBI_REMOTE_SFENCE_VMA_ASID.html b/ch2/os/sbi/constant.SBI_REMOTE_SFENCE_VMA_ASID.html deleted file mode 100644 index 06c69ce2..00000000 --- a/ch2/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/ch2/os/sbi/constant.SBI_SEND_IPI.html b/ch2/os/sbi/constant.SBI_SEND_IPI.html deleted file mode 100644 index a3da3df2..00000000 --- a/ch2/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/ch2/os/sbi/constant.SBI_SET_TIMER.html b/ch2/os/sbi/constant.SBI_SET_TIMER.html deleted file mode 100644 index b8c22ab8..00000000 --- a/ch2/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/ch2/os/sbi/constant.SBI_SHUTDOWN.html b/ch2/os/sbi/constant.SBI_SHUTDOWN.html index 1019984f..4326bff5 100644 --- a/ch2/os/sbi/constant.SBI_SHUTDOWN.html +++ b/ch2/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/ch2/os/sbi/fn.console_getchar.html b/ch2/os/sbi/fn.console_getchar.html deleted file mode 100644 index 77867c6e..00000000 --- a/ch2/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/ch2/os/sbi/fn.console_putchar.html b/ch2/os/sbi/fn.console_putchar.html index 0cf1da13..42daa833 100644 --- a/ch2/os/sbi/fn.console_putchar.html +++ b/ch2/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/ch2/os/sbi/fn.sbi_call.html b/ch2/os/sbi/fn.sbi_call.html index 00731305..6235e7f1 100644 --- a/ch2/os/sbi/fn.sbi_call.html +++ b/ch2/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/ch2/os/sbi/fn.shutdown.html b/ch2/os/sbi/fn.shutdown.html index 61b32df2..821fbf25 100644 --- a/ch2/os/sbi/fn.shutdown.html +++ b/ch2/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/ch2/os/sbi/index.html b/ch2/os/sbi/index.html index e9e82a59..20c93b16 100644 --- a/ch2/os/sbi/index.html +++ b/ch2/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/ch2/os/sbi/sidebar-items.js b/ch2/os/sbi/sidebar-items.js index 57e03764..d7d2fdc2 100644 --- a/ch2/os/sbi/sidebar-items.js +++ b/ch2/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/ch2/os/sidebar-items.js b/ch2/os/sidebar-items.js index 0179a50d..b60f0f38 100644 --- a/ch2/os/sidebar-items.js +++ b/ch2/os/sidebar-items.js @@ -1 +1 @@ -initSidebarItems({"fn":[["clear_bss",""],["rust_main",""]],"macro":[["print",""],["println",""]],"mod":[["batch",""],["console",""],["lang_items",""],["sbi",""],["sync",""],["syscall",""],["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":[["batch","batch subsystem"],["console","SBI console driver, for text output"],["lang_items","The panic handler"],["sbi","SBI call wrappers"],["sync","Synchronization and interior mutability primitives"],["syscall","Implementation of syscalls"],["trap","Trap handling functionality"]]}); \ No newline at end of file diff --git a/ch2/os/sync/index.html b/ch2/os/sync/index.html index 26fd3968..effcc859 100644 --- a/ch2/os/sync/index.html +++ b/ch2/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/ch2/os/sync/sidebar-items.js b/ch2/os/sync/sidebar-items.js index 440fc425..09d6027e 100644 --- a/ch2/os/sync/sidebar-items.js +++ b/ch2/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/ch2/os/sync/up/index.html b/ch2/os/sync/up/index.html index 26f07349..4faef20d 100644 --- a/ch2/os/sync/up/index.html +++ b/ch2/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/ch2/os/sync/up/struct.UPSafeCell.html b/ch2/os/sync/up/struct.UPSafeCell.html index d29e93de..006b5c1b 100644 --- a/ch2/os/sync/up/struct.UPSafeCell.html +++ b/ch2/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/ch2/os/syscall/constant.SYSCALL_EXIT.html b/ch2/os/syscall/constant.SYSCALL_EXIT.html index 53cf68dc..a7ac151b 100644 --- a/ch2/os/syscall/constant.SYSCALL_EXIT.html +++ b/ch2/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/ch2/os/syscall/constant.SYSCALL_WRITE.html b/ch2/os/syscall/constant.SYSCALL_WRITE.html index a37aec89..608006c0 100644 --- a/ch2/os/syscall/constant.SYSCALL_WRITE.html +++ b/ch2/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/ch2/os/syscall/fn.syscall.html b/ch2/os/syscall/fn.syscall.html index d46b1bd3..7d7c10ac 100644 --- a/ch2/os/syscall/fn.syscall.html +++ b/ch2/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/ch2/os/syscall/fs/constant.FD_STDOUT.html b/ch2/os/syscall/fs/constant.FD_STDOUT.html index a2a9bff0..e70dc6aa 100644 --- a/ch2/os/syscall/fs/constant.FD_STDOUT.html +++ b/ch2/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/ch2/os/syscall/fs/fn.sys_write.html b/ch2/os/syscall/fs/fn.sys_write.html index b1b2e869..f99ebf0e 100644 --- a/ch2/os/syscall/fs/fn.sys_write.html +++ b/ch2/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/ch2/os/syscall/fs/index.html b/ch2/os/syscall/fs/index.html index 31b9eef4..fcb8e96f 100644 --- a/ch2/os/syscall/fs/index.html +++ b/ch2/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/ch2/os/syscall/fs/sidebar-items.js b/ch2/os/syscall/fs/sidebar-items.js index 002a1085..99a1dcdc 100644 --- a/ch2/os/syscall/fs/sidebar-items.js +++ b/ch2/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/ch2/os/syscall/index.html b/ch2/os/syscall/index.html index b591c9ff..14e9954a 100644 --- a/ch2/os/syscall/index.html +++ b/ch2/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

+

App management syscalls

+

Constants

Functions

handle syscall exception with syscall_id and other arguments

diff --git a/ch2/os/syscall/process/fn.sys_exit.html b/ch2/os/syscall/process/fn.sys_exit.html index f82bd3d1..f78aad79 100644 --- a/ch2/os/syscall/process/fn.sys_exit.html +++ b/ch2/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/ch2/os/syscall/process/index.html b/ch2/os/syscall/process/index.html index 3377c3f2..ee37f2fd 100644 --- a/ch2/os/syscall/process/index.html +++ b/ch2/os/syscall/process/index.html @@ -1,8 +1,9 @@ -os::syscall::process - Rust +os::syscall::process - Rust
Expand description

App management syscalls

+

Functions

task exits and submit an exit code

\ No newline at end of file diff --git a/ch2/os/syscall/sidebar-items.js b/ch2/os/syscall/sidebar-items.js index c18cac38..c3b7bc26 100644 --- a/ch2/os/syscall/sidebar-items.js +++ b/ch2/os/syscall/sidebar-items.js @@ -1 +1 @@ -initSidebarItems({"constant":[["SYSCALL_EXIT",""],["SYSCALL_WRITE",""]],"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",""]],"fn":[["syscall","handle syscall exception with `syscall_id` and other arguments"]],"mod":[["fs","File and filesystem-related syscalls"],["process","App management syscalls"]]}); \ No newline at end of file diff --git a/ch2/os/trap/context/index.html b/ch2/os/trap/context/index.html index f681954f..4531c273 100644 --- a/ch2/os/trap/context/index.html +++ b/ch2/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/ch2/os/trap/context/sidebar-items.js b/ch2/os/trap/context/sidebar-items.js index d7c5bfe2..c68e0844 100644 --- a/ch2/os/trap/context/sidebar-items.js +++ b/ch2/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/ch2/os/trap/context/struct.TrapContext.html b/ch2/os/trap/context/struct.TrapContext.html index ea75c16f..11ee8ae2 100644 --- a/ch2/os/trap/context/struct.TrapContext.html +++ b/ch2/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/ch2/os/trap/fn.init.html b/ch2/os/trap/fn.init.html index 0d3a3272..ae36c3e6 100644 --- a/ch2/os/trap/fn.init.html +++ b/ch2/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/ch2/os/trap/fn.trap_handler.html b/ch2/os/trap/fn.trap_handler.html index fec4c685..1c0ed1be 100644 --- a/ch2/os/trap/fn.trap_handler.html +++ b/ch2/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/ch2/os/trap/index.html b/ch2/os/trap/index.html index 3093d332..d48d9239 100644 --- a/ch2/os/trap/index.html +++ b/ch2/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/ch2/os/trap/sidebar-items.js b/ch2/os/trap/sidebar-items.js index 445b06f2..79df6d2b 100644 --- a/ch2/os/trap/sidebar-items.js +++ b/ch2/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/ch2/os/trap/struct.TrapContext.html b/ch2/os/trap/struct.TrapContext.html new file mode 100644 index 00000000..42ae2bba --- /dev/null +++ b/ch2/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/ch2/search-index.js b/ch2/search-index.js index 3c68f5d1..257d8c5c 100644 --- a/ch2/search-index.js +++ b/ch2/search-index.js @@ -1,4 +1,4 @@ var searchIndex = JSON.parse('{\ -"os":{"doc":"","t":[0,5,0,0,14,14,5,0,0,0,0,17,3,17,3,7,17,3,17,7,17,3,12,12,11,11,11,11,11,11,11,11,12,12,12,11,11,11,11,11,11,11,11,5,11,11,11,11,11,11,12,5,11,11,5,11,11,11,11,11,11,11,11,11,11,11,11,3,11,11,11,11,5,11,11,11,11,5,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,0,0,5,17,5,5,0,5,5,3,11,11,11,11,11,12,11,12,11,11,11,12],"n":["batch","clear_bss","console","lang_items","print","println","rust_main","sbi","sync","syscall","trap","APP_BASE_ADDRESS","APP_MANAGER","APP_SIZE_LIMIT","AppManager","KERNEL_STACK","KERNEL_STACK_SIZE","KernelStack","MAX_APP_NUM","USER_STACK","USER_STACK_SIZE","UserStack","__private_field","app_start","borrow","borrow","borrow","borrow","borrow_mut","borrow_mut","borrow_mut","borrow_mut","current_app","data","data","deref","from","from","from","from","get_current_app","get_sp","get_sp","init","into","into","into","into","load_app","move_to_next_app","num_app","print_app_info","print_app_info","push_context","run_next_app","try_from","try_from","try_from","try_from","try_into","try_into","try_into","try_into","type_id","type_id","type_id","type_id","Stdout","borrow","borrow_mut","from","into","print","try_from","try_into","type_id","write_str","panic","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","fs","process","syscall","FD_STDOUT","sys_write","sys_exit","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::batch","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","os::console","","","","","","","","","","os::lang_items","os::sbi","","","","","","","","","","","","","os::sync","os::sync::up","","","","","","","","","","","os::syscall","","","","","os::syscall::fs","","os::syscall::process","os::trap","","","os::trap::context","","","","","","","","","","","",""],"d":["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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","","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,0,0,0,1,2,3,4,2,1,3,4,2,1,2,3,4,1,3,4,2,1,2,3,4,0,3,4,2,1,2,2,2,0,2,3,0,3,4,2,1,3,4,2,1,3,4,2,1,0,5,5,5,5,0,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,6,6,6,6,6,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,7,7,7,7,7,7,7,7,7,7,7,7],"f":[null,[[]],null,null,null,null,[[],["never",15]],null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],null,null,null,[[],["upsafecell",3]],[[]],[[]],[[]],[[]],[[],["usize",15]],[[],["usize",15]],[[],["usize",15]],[[]],[[]],[[]],[[]],[[]],[[["usize",15]]],[[]],null,[[]],[[]],[[["trapcontext",3]],["trapcontext",3]],[[],["never",15]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],[[],["typeid",3]],[[],["typeid",3]],[[],["typeid",3]],null,[[]],[[]],[[]],[[]],[[["arguments",3]]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],[[["str",15]],["result",6]],[[["panicinfo",3]],["never",15]],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,[[["usize",15]],["isize",15]],null,[[["usize",15],["usize",15]],["isize",15]],[[["i32",15]],["never",15]],null,[[]],[[["trapcontext",3]],["trapcontext",3]],null,[[["usize",15],["usize",15]]],[[]],[[]],[[]],[[]],null,[[["usize",15]]],null,[[],["result",4]],[[],["result",4]],[[],["typeid",3]],null],"p":[[3,"APP_MANAGER"],[3,"AppManager"],[3,"KernelStack"],[3,"UserStack"],[3,"Stdout"],[3,"UPSafeCell"],[3,"TrapContext"]]}\ +"os":{"doc":"The main module and entrypoint","t":[0,5,0,0,14,14,5,0,0,0,0,17,3,17,3,7,17,3,17,7,17,3,12,12,11,11,11,11,11,11,11,11,12,12,12,11,11,11,11,11,11,11,11,5,11,11,11,11,11,11,12,5,11,11,5,11,11,11,11,11,11,11,11,11,11,11,11,3,11,11,11,11,5,11,11,11,11,5,17,17,5,5,5,0,3,11,11,11,11,12,11,11,11,11,11,17,17,0,0,5,17,5,5,3,0,5,12,12,5,12,3,11,11,11,11,11,12,11,12,11,11,11,12],"n":["batch","clear_bss","console","lang_items","print","println","rust_main","sbi","sync","syscall","trap","APP_BASE_ADDRESS","APP_MANAGER","APP_SIZE_LIMIT","AppManager","KERNEL_STACK","KERNEL_STACK_SIZE","KernelStack","MAX_APP_NUM","USER_STACK","USER_STACK_SIZE","UserStack","__private_field","app_start","borrow","borrow","borrow","borrow","borrow_mut","borrow_mut","borrow_mut","borrow_mut","current_app","data","data","deref","from","from","from","from","get_current_app","get_sp","get_sp","init","into","into","into","into","load_app","move_to_next_app","num_app","print_app_info","print_app_info","push_context","run_next_app","try_from","try_from","try_from","try_from","try_into","try_into","try_into","try_into","type_id","type_id","type_id","type_id","Stdout","borrow","borrow_mut","from","into","print","try_from","try_into","type_id","write_str","panic","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","fs","process","syscall","FD_STDOUT","sys_write","sys_exit","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::batch","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","os::console","","","","","","","","","","os::lang_items","os::sbi","","","","","os::sync","os::sync::up","","","","","","","","","","","os::syscall","","","","","os::syscall::fs","","os::syscall::process","os::trap","","","","","","","os::trap::context","","","","","","","","","","","",""],"d":["batch subsystem","clear BSS segment","SBI console driver, for text output","The panic handler","print string macro","println string macro","the rust entry-point of os","SBI call wrappers","Synchronization and interior mutability primitives","Implementation of syscalls","Trap handling functionality","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","init batch subsystem","","","","","","","","print apps info","","","run next app","","","","","","","","","","","","","","","","","","","","","","","","","","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","App 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","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,0,0,0,1,2,3,4,2,1,3,4,2,1,2,3,4,1,3,4,2,1,2,3,4,0,3,4,2,1,2,2,2,0,2,3,0,3,4,2,1,3,4,2,1,3,4,2,1,0,5,5,5,5,0,5,5,5,5,0,0,0,0,0,0,0,0,6,6,6,6,6,6,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,7,7,0,7,0,7,7,7,7,7,7,7,7,7,7,7,7],"f":[null,[[]],null,null,null,null,[[],["never",15]],null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],null,null,null,[[],["upsafecell",3]],[[]],[[]],[[]],[[]],[[],["usize",15]],[[],["usize",15]],[[],["usize",15]],[[]],[[]],[[]],[[]],[[]],[[["usize",15]]],[[]],null,[[]],[[]],[[["trapcontext",3]],["trapcontext",3]],[[],["never",15]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],[[],["typeid",3]],[[],["typeid",3]],[[],["typeid",3]],null,[[]],[[]],[[]],[[]],[[["arguments",3]]],[[],["result",4]],[[],["result",4]],[[],["typeid",3]],[[["str",15]],["result",6]],[[["panicinfo",3]],["never",15]],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,[[["usize",15]],["isize",15]],null,[[["usize",15],["usize",15]],["isize",15]],[[["i32",15]],["never",15]],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,"APP_MANAGER"],[3,"AppManager"],[3,"KernelStack"],[3,"UserStack"],[3,"Stdout"],[3,"UPSafeCell"],[3,"TrapContext"]]}\ }'); if (window.initSearch) {window.initSearch(searchIndex)}; \ No newline at end of file diff --git a/ch2/src/os/batch.rs.html b/ch2/src/os/batch.rs.html index ebcac515..b600edaa 100644 --- a/ch2/src/os/batch.rs.html +++ b/ch2/src/os/batch.rs.html @@ -143,7 +143,14 @@ 140 141 142 -
use crate::sync::UPSafeCell;
+143
+144
+145
+146
+147
+
//! batch subsystem
+
+use crate::sync::UPSafeCell;
 use crate::trap::TrapContext;
 use core::arch::asm;
 use lazy_static::*;
@@ -256,14 +263,17 @@
     };
 }
 
+/// init batch subsystem
 pub fn init() {
     print_app_info();
 }
 
+/// print apps info
 pub fn print_app_info() {
     APP_MANAGER.exclusive_access().print_app_info();
 }
 
+/// run next app
 pub fn run_next_app() -> ! {
     let mut app_manager = APP_MANAGER.exclusive_access();
     let current_app = app_manager.get_current_app();
diff --git a/ch2/src/os/console.rs.html b/ch2/src/os/console.rs.html
index 18c55e28..c3774d09 100644
--- a/ch2/src/os/console.rs.html
+++ b/ch2/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/ch2/src/os/lang_items.rs.html b/ch2/src/os/lang_items.rs.html
index 696d616e..7685d650 100644
--- a/ch2/src/os/lang_items.rs.html
+++ b/ch2/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/ch2/src/os/main.rs.html b/ch2/src/os/main.rs.html
index c1c7f54c..7c92f08f 100644
--- a/ch2/src/os/main.rs.html
+++ b/ch2/src/os/main.rs.html
@@ -38,7 +38,45 @@
 35
 36
 37
-
#![no_std]
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+
//! 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
+//! - [`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 [`batch::run_next_app()`] and for the first time go to
+//! userspace.
+
+#![deny(missing_docs)]
+#![deny(warnings)]
+#![no_std]
 #![no_main]
 #![feature(panic_info_message)]
 
@@ -46,16 +84,17 @@
 
 #[macro_use]
 mod console;
-mod batch;
+pub mod batch;
 mod lang_items;
 mod sbi;
 mod sync;
-mod syscall;
-mod trap;
+pub mod syscall;
+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();
@@ -67,6 +106,7 @@
     }
 }
 
+/// the rust entry-point of os
 #[no_mangle]
 pub fn rust_main() -> ! {
     clear_bss();
diff --git a/ch2/src/os/sbi.rs.html b/ch2/src/os/sbi.rs.html
index d29b5e20..45144cd4 100644
--- a/ch2/src/os/sbi.rs.html
+++ b/ch2/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/ch2/src/os/sync/mod.rs.html b/ch2/src/os/sync/mod.rs.html
index 625d8d9d..4bd5e3b3 100644
--- a/ch2/src/os/sync/mod.rs.html
+++ b/ch2/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/ch2/src/os/sync/up.rs.html b/ch2/src/os/sync/up.rs.html index 8e982968..45704751 100644 --- a/ch2/src/os/sync/up.rs.html +++ b/ch2/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/ch2/src/os/syscall/fs.rs.html b/ch2/src/os/syscall/fs.rs.html
index f883c38f..4cce3b3c 100644
--- a/ch2/src/os/syscall/fs.rs.html
+++ b/ch2/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/ch2/src/os/syscall/mod.rs.html b/ch2/src/os/syscall/mod.rs.html
index a37c83d0..2aaec3bb 100644
--- a/ch2/src/os/syscall/mod.rs.html
+++ b/ch2/src/os/syscall/mod.rs.html
@@ -18,7 +18,31 @@
 15
 16
 17
-
const SYSCALL_WRITE: usize = 64;
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+
//! 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;
 
 mod fs;
diff --git a/ch2/src/os/syscall/process.rs.html b/ch2/src/os/syscall/process.rs.html
index db1cb28b..cb3b8c59 100644
--- a/ch2/src/os/syscall/process.rs.html
+++ b/ch2/src/os/syscall/process.rs.html
@@ -8,7 +8,9 @@
 5
 6
 7
-
use crate::batch::run_next_app;
+8
+
//! App management syscalls
+use crate::batch::run_next_app;
 
 /// task exits and submit an exit code
 pub fn sys_exit(exit_code: i32) -> ! {
diff --git a/ch2/src/os/trap/context.rs.html b/ch2/src/os/trap/context.rs.html
index 5b89852e..7d10e2f5 100644
--- a/ch2/src/os/trap/context.rs.html
+++ b/ch2/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/ch2/src/os/trap/mod.rs.html b/ch2/src/os/trap/mod.rs.html index 1cf52939..91454947 100644 --- a/ch2/src/os/trap/mod.rs.html +++ b/ch2/src/os/trap/mod.rs.html @@ -54,7 +54,35 @@ 51 52 53 -
mod context;
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+
//! 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::batch::run_next_app;
 use crate::syscall::syscall;