Skip to content

Commit 9e184f4

Browse files
author
Bingus
committed
Fix formatting and update Dockerfile comments, README build instructions
1 parent 378be2d commit 9e184f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2107
-1872
lines changed

Dockerfile

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#
2-
# Runs the build of CrystalOS in a Docker container. It should work now anyway. Just run docker build . -o <output_folder>.
3-
# There was probably a good reason to include this file in the repo but it is somewhat unclear to myself.
4-
# I have just updated a couple things to cache dependencies and create a small container to copy the relevant build artifacts tos.
5-
#
1+
# Runs the build of CrystalOS in a Docker container. It should work now anyway. Just run "DOCKER_BUILDKIT=1 docker build . -o <output_folder>."
2+
# There was probably a good reason to include this file in the repo but it is somewhat unclear to myself.
3+
# I have just updated a couple things to cache dependencies and create a small container to copy the relevant build artifacts to.
64

75
FROM rustlang/rust:nightly AS build
86

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,17 @@ while I'm waiting for the third edition to release, I guess I'm gonna just have
4949

5050
- a shell that can enter apps and run commands like 'echo' and 'clear'
5151
- well actually just those commands lol. Might try making a shell language or something if i get some spare time over christmas
52+
53+
## Building with Docker
54+
55+
To build using Docker, just run this:
56+
57+
```sh
58+
DOCKER_BUILDKIT=1 docker build . -o ./path/to/output/folder
59+
```
60+
61+
### TODOs with Docker/CI etc:
62+
63+
* Setup everything including qemu inside of Docker.
64+
* Running tests inside of Docker.
65+
* Possible automatic releases when you git tag? (Not too hard using the docker image and uploading to GitHub)

src/lib.rs

+39-42
Original file line numberDiff line numberDiff line change
@@ -16,98 +16,95 @@ use bootloader::BootInfo;
1616
use core::panic::PanicInfo;
1717
extern crate alloc;
1818

19-
2019
pub mod system;
2120
pub mod user;
22-
pub use system::std as std;
21+
pub use system::std;
2322
pub use user::bin::*;
2423

25-
2624
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2725
#[repr(u32)]
2826
pub enum QemuExitCode {
29-
Ok = 0x10,
30-
Err = 0x11,
27+
Ok = 0x10,
28+
Err = 0x11,
3129
}
3230

3331
pub fn poweroff() {
34-
exit(QemuExitCode::Ok);
32+
exit(QemuExitCode::Ok);
3533
}
3634

3735
pub fn exit(code: QemuExitCode) {
38-
use x86_64::instructions::port::Port;
36+
use x86_64::instructions::port::Port;
3937

40-
unsafe {
41-
let mut port = Port::new(0xf4);
42-
port.write(code as u32);
43-
}
44-
println!("e");
38+
unsafe {
39+
let mut port = Port::new(0xf4);
40+
port.write(code as u32);
41+
}
42+
println!("e");
4543
}
4644

4745
#[alloc_error_handler]
4846
fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! {
49-
panic!("error while allocating: {:?}", layout)
47+
panic!("error while allocating: {:?}", layout)
5048
}
5149

5250
pub fn start(boot_info: &'static BootInfo) {
53-
system::init(boot_info);
51+
system::init(boot_info);
5452
}
5553

5654
pub fn hlt() -> ! {
57-
loop {
58-
x86_64::instructions::hlt();
59-
}
55+
loop {
56+
x86_64::instructions::hlt();
57+
}
6058
}
6159

62-
6360
#[cfg(test)]
6461
entry_point!(test_kernel_main);
6562

6663
#[cfg(test)]
6764
fn test_kernel_main(boot_info: &'static BootInfo) -> ! {
68-
system::init(boot_info);
69-
test_main();
70-
hlt();
65+
system::init(boot_info);
66+
test_main();
67+
hlt();
7168
}
7269

7370
pub trait Testable {
74-
fn run(&self) -> ();
71+
fn run(&self) -> ();
7572
}
7673

77-
impl<T> Testable for T where T: Fn(), {
78-
fn run(&self) {
79-
serial_print!("{}...\t", core::any::type_name::<T>());
80-
self();
81-
serial_println!("OK");
82-
}
74+
impl<T> Testable for T
75+
where
76+
T: Fn(),
77+
{
78+
fn run(&self) {
79+
serial_print!("{}...\t", core::any::type_name::<T>());
80+
self();
81+
serial_println!("OK");
82+
}
8383
}
8484

8585
pub fn test_runner(tests: &[&dyn Testable]) {
86-
serial_println!("Running {} tests", tests.len());
87-
for test in tests {
88-
test.run();
89-
}
90-
exit(QemuExitCode::Ok);
86+
serial_println!("Running {} tests", tests.len());
87+
for test in tests {
88+
test.run();
89+
}
90+
exit(QemuExitCode::Ok);
9191
}
9292

9393
pub fn test_panic_handler(info: &PanicInfo) -> ! {
94-
serial_println!("ERR");
95-
serial_println!("Error: {}\n", info);
96-
exit(QemuExitCode::Err);
97-
hlt();
94+
serial_println!("ERR");
95+
serial_println!("Error: {}\n", info);
96+
exit(QemuExitCode::Err);
97+
hlt();
9898
}
9999

100-
101100
#[cfg(test)]
102101
#[panic_handler]
103102
fn panic(info: &PanicInfo) -> ! {
104-
test_panic_handler(info)
103+
test_panic_handler(info)
105104
}
106105

107-
108-
109106
#[cfg(test)]
110107
#[test_case]
111108
fn trivial_assertion() {
112-
assert_eq!(1, 1);
109+
assert_eq!(1, 1);
113110
}

src/main.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
use bootloader::{entry_point, BootInfo};
88
use core::panic::PanicInfo;
99
use CrystalOS::std::tasks::{Executor, Task};
10-
use CrystalOS::{printerr, std::syscall};
10+
use CrystalOS::{print_log, serial_println};
11+
use CrystalOS::{printerr, std::syscall};
1112
extern crate alloc;
1213
use CrystalOS::user::bin::shell;
1314

@@ -25,12 +26,13 @@ fn panic(info: &PanicInfo) -> ! {
2526
CrystalOS::test_panic_handler(info)
2627
}
2728

28-
2929
entry_point!(main);
3030

3131
fn main(boot_info: &'static BootInfo) -> ! {
3232
CrystalOS::start(boot_info);
3333

34+
print_log!("test");
35+
3436
#[cfg(test)]
3537
test_main();
3638

@@ -41,4 +43,3 @@ fn main(boot_info: &'static BootInfo) -> ! {
4143
executor.try_run();
4244
}
4345
}
44-

src/system/kernel/allocator.rs

+32-41
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,50 @@
1-
21
use alloc::alloc::{GlobalAlloc, Layout};
32
use core::ptr::null_mut;
43
use linked_list_allocator::LockedHeap;
54

6-
75
use x86_64::{
8-
structures::paging::{
9-
mapper::MapToError, FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB,
10-
},
11-
VirtAddr,
6+
structures::paging::{
7+
mapper::MapToError, FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB,
8+
},
9+
VirtAddr,
1210
};
1311

1412
pub fn init_heap(
15-
mapper: &mut impl Mapper<Size4KiB>,
16-
frame_allocator: &mut impl FrameAllocator<Size4KiB>
13+
mapper: &mut impl Mapper<Size4KiB>,
14+
frame_allocator: &mut impl FrameAllocator<Size4KiB>,
1715
) -> Result<(), MapToError<Size4KiB>> {
18-
let page_range = {
19-
let heap_start = VirtAddr::new(HEAP_START as u64);
20-
let heap_end = heap_start + HEAP_SIZE - 1u64;
21-
let heap_start_page = Page::containing_address(heap_start);
22-
let heap_end_page = Page::containing_address(heap_end);
23-
Page::range_inclusive(heap_start_page, heap_end_page)
24-
};
25-
26-
for page in page_range {
27-
let frame = frame_allocator.allocate_frame()
28-
.ok_or(MapToError::FrameAllocationFailed)?;
29-
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
30-
unsafe {
31-
mapper.map_to(page, frame, flags, frame_allocator)?.flush()
32-
};
33-
34-
unsafe { ALLOCATOR.lock().init(HEAP_START as *mut u8, HEAP_SIZE); }
35-
}
36-
Ok(())
16+
let page_range = {
17+
let heap_start = VirtAddr::new(HEAP_START as u64);
18+
let heap_end = heap_start + HEAP_SIZE - 1u64;
19+
let heap_start_page = Page::containing_address(heap_start);
20+
let heap_end_page = Page::containing_address(heap_end);
21+
Page::range_inclusive(heap_start_page, heap_end_page)
22+
};
23+
24+
for page in page_range {
25+
let frame = frame_allocator
26+
.allocate_frame()
27+
.ok_or(MapToError::FrameAllocationFailed)?;
28+
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
29+
unsafe { mapper.map_to(page, frame, flags, frame_allocator)?.flush() };
30+
31+
unsafe {
32+
ALLOCATOR.lock().init(HEAP_START as *mut u8, HEAP_SIZE);
33+
}
34+
}
35+
Ok(())
3736
}
3837

39-
40-
41-
42-
43-
44-
45-
46-
4738
pub struct Dummy;
4839

4940
unsafe impl GlobalAlloc for Dummy {
50-
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
51-
null_mut()
52-
}
41+
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
42+
null_mut()
43+
}
5344

54-
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {
55-
panic!("this method should not be used")
56-
}
45+
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {
46+
panic!("this method should not be used")
47+
}
5748
}
5849

5950
#[global_allocator]

src/system/kernel/authenticator.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
use lazy_static::lazy_static;
21
use alloc::sync::Arc;
2+
use alloc::{string::String, vec, vec::Vec};
3+
use lazy_static::lazy_static;
34
use spin::Mutex;
4-
use alloc::{vec, vec::Vec, string::String};
55

6-
lazy_static!(
6+
lazy_static! {
77
static ref AUTHENTICATOR: Arc<Mutex<Vec<User>>> = Arc::new(Mutex::new(vec![User::new(
88
String::from("fantasypvp"),
99
String::from("password")
1010
)]));
11-
);
11+
};
1212

1313
pub struct User {
1414
username: String,
@@ -18,7 +18,10 @@ pub struct User {
1818
impl User {
1919
fn new(username: String, password: String) -> User {
2020
let pass_hash = User::get_pass_hash(&password);
21-
User { username, pass_hash }
21+
User {
22+
username,
23+
pass_hash,
24+
}
2225
}
2326

2427
fn get_pass_hash(pass: &String) -> u64 {
@@ -33,4 +36,4 @@ impl User {
3336
Some(false)
3437
}
3538
}
36-
}
39+
}

0 commit comments

Comments
 (0)