You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/rust-os/1-hello-riscv/index.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -129,7 +129,9 @@ SBI (Supervisor Binary Interface) is a standard interface for interacting with t
129
129
130
130
The version shipping with QEMU uses a Jump Address ([_FW_JUMP_](https://github.com/riscv-software-src/opensbi/blob/master/docs/firmware/fw_jump.md)), in this case, `0x80200000`, which is where we'll be putting our kernel. QEMU will load our kernel into memory and jump to `0x80000000`, from where OpenSBI will then jump to `0x80200000`, where our kernel is located.
This architecture has a lot of benefits: SBI puts an abstraction layer between the kernel and the hardware, which allows us to write a single kernel that can run on any RISC-V CPU, regardless of the extensions it supports, as long as it has an SBI implementation. SBI also provides many functions like printing to and reading from the console, and it loads a flattened device tree (FDT) into memory, which we'll also be using later on to get information about the hardware.
Copy file name to clipboardExpand all lines: content/rust-os/2-shell/index.md
+22-8Lines changed: 22 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,13 +3,18 @@ transparent = true
3
3
title = "Creating a Kernel in Rust #2: Shell"
4
4
description = "Creating a simple shell for our kernel to run commands and help us debug"
5
5
date = 2023-05-14
6
-
draft = true
7
6
8
7
[taxonomies]
9
8
tags = ["rust", "riscv", "kernel"]
10
9
series = ["rust-os"]
11
10
+++
12
11
12
+
{% quote (class="info")%}
13
+
14
+
This is a series of posts about my journey creating a kernel in rust. You can find the code for this project [here](https://github.com/explodingcamera/pogos/tree/part-1) and all of the posts in this series [here](/series/os-dev/).
15
+
16
+
{% end %}
17
+
13
18
Now that we have a basic kernel that can print to the screen, we can start building out some more functionality.
14
19
The first thing I want to do is create a simple shell that will allow us to run some commands and more easily interact with our system.
15
20
@@ -33,20 +38,29 @@ First, we'll create a new file `src/linear-allocator.rs` and will create the bas
33
38
34
39
usecore::sync::atomic::{AtomicUsize};
35
40
36
-
pubstructLinearAllocator<constT:usize> {
41
+
pubstructLinearAllocator {
37
42
head:AtomicUsize, // the current index of the buffer
38
43
// AtomicUsize is a special type that allows us to safely share data
39
44
// between threads without using locks
40
45
41
-
memory: [u8; T], // our in-memory "arena"
46
+
start:*mutu8, // raw pointer to the start of the heap
47
+
end:*mutu8, // raw pointer to the end of the heap
42
48
}
43
-
44
49
// allow our allocator to be shared between threads
45
50
unsafeimplSyncforLinearAllocator {}
46
51
47
52
implLinearAllocator {
48
-
pubfninit(buffer:&'staticmut [u8]) ->Self {
49
-
Self { head:AtomicUsize::new(0), memory }
53
+
pubconstfnempty() ->Self {
54
+
Self {
55
+
head:AtomicUsize::new(0),
56
+
start:core::ptr::null_mut(),
57
+
end:core::ptr::null_mut(),
58
+
}
59
+
}
60
+
61
+
pubfninit(&mutself, start:usize, size:usize) {
62
+
self.start =startas*mutu8;
63
+
self.end =unsafe { self.start.add(size) };
50
64
}
51
65
}
52
66
```
@@ -60,8 +74,8 @@ use core::alloc::{GlobalAlloc, Layout};
0 commit comments