Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rust #651

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,135 changes: 1,075 additions & 1,060 deletions Cargo.lock

Large diffs are not rendered by default.

41 changes: 21 additions & 20 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ default_to_workspace = false
[env]
CARGO_MAKE_CRATE_INSTALLATION_LOCKED = "true"
RUST_TARGET_PATH = "${CARGO_MAKE_WORKING_DIRECTORY}"
XARGO_RUST_SRC = "${CARGO_MAKE_WORKING_DIRECTORY}/rust/src"
XARGO_RUST_SRC = "${CARGO_MAKE_WORKING_DIRECTORY}/rust/library"
GDB_PORT = { script = ["echo ${GDB_PORT:-9090}"] }
VNC_PORT = { script = ["echo ${VNC_PORT:-:0}"] }
CLIPPY_RULES = """
Expand All @@ -32,7 +32,7 @@ QEMU_COMMON_FLAGS = """\
-vnc ${VNC_PORT} \
-no-reboot \
-drive id=diskA,file=DISK.img,format=raw,if=none -device ahci,id=ahci \
-device ide-drive,drive=diskA,bus=ahci.0 \
-device ide-hd,drive=diskA,bus=ahci.0 \
-machine q35 \
-m 512M"""

Expand Down Expand Up @@ -75,7 +75,7 @@ install_crate = { crate_name = "mkisofs-rs", binary = "mkisofs-rs", test_arg = "

[tasks.install-xargo]
dependencies = ["install-rust-src"]
install_crate = { crate_name = "xargo", binary = "xargo", test_arg = "--version", min_version = "0.3.18" }
install_crate = { crate_name = "xargo", binary = "xargo", test_arg = "--version", min_version = "0.3.26" }

[tasks.bootstrap]
description = "Compiles the i386 bootstrap"
Expand Down Expand Up @@ -168,7 +168,6 @@ command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=uutils", "-Z", "package-features", "--features=sunrise", "--no-default-features", "@@split(COMPILER_FLAGS, )"]

[tasks.userspace-nostd]
internal = true
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "@@split(COMPILER_FLAGS, )",
"-p", "sunrise-shell", "-p", "sunrise-wall-clock", "-p", "sunrise-sm",
Expand Down Expand Up @@ -376,17 +375,19 @@ script_runner = "@duckscript"
script = [
'''
version = readfile rust-toolchain
version = trim ${version}
date = split ${version} "-"
array_remove ${date} 0
date = array_join ${date} "-"
date = trim ${date}
datetime = concat ${date} " 12:00:00 +0000"

function apply_patches
patches = glob_array ${CARGO_MAKE_WORKING_DIRECTORY}/rust-patches/*.patch
patches = array_join ${patches} " "
set_env GIT_COMMITTER_NAME patchsystem
set_env GIT_COMMITTER_EMAIL patchsystem
exec git am --committer-date-is-author-date %{patches}
exec --fail-on-error git am --committer-date-is-author-date %{patches}
end

# If rust folder doesn't exist, create it, and import the rust source.
Expand All @@ -396,16 +397,16 @@ if not is_path_exists ${CARGO_MAKE_WORKING_DIRECTORY}/rust
sysroot = concat ${output.stdout} /lib/rustlib/src/rust/
cp ${sysroot} ${CARGO_MAKE_WORKING_DIRECTORY}
cd ${CARGO_MAKE_WORKING_DIRECTORY}/rust/
exec git init
exec git add .
exec --fail-on-error git init
exec --fail-on-error git add .
set_env GIT_COMMITTER_NAME patchsystem
set_env GIT_COMMITTER_EMAIL patchsystem
set_env GIT_COMMITTER_DATE ${datetime}
set_env GIT_AUTHOR_NAME patchsystem
set_env GIT_AUTHOR_EMAIL patchsystem
set_env GIT_AUTHOR_DATE ${datetime}
echo "Importing rust-src"
exec git commit -m ${version} -q
exec --fail-on-error git commit -m ${version} -q
unset_env GIT_AUTHOR_DATE
unset_env GIT_AUTHOR_EMAIL
unset_env GIT_AUTHOR_NAME
Expand All @@ -421,32 +422,32 @@ cd ${CARGO_MAKE_WORKING_DIRECTORY}/rust/

# Check the original commit matches the current rust version. If it doesn't,
# bail out, tell user they need to update their patches.
head_rev = exec git rev-list --max-parents=0 HEAD
head_rev = exec --fail-on-error git rev-list --max-parents=0 HEAD
head_rev = trim ${head_rev.stdout}
message = exec git log --format=%B -n 1 ${head_rev}
message = exec --fail-on-error git log --format=%B -n 1 ${head_rev}
message = trim ${message.stdout}
assert_eq ${message} ${version} "\nRust version doesn't match rust-toolchain. The patches will need to be updated. See docs/UPDATE_RUST.md for more information."
assert_eq ${message} ${version} "\nRust version ${message} doesn't match rust-toolchain ${version}. The patches will need to be updated. See docs/UPDATE_RUST.md for more information."

# Check if there's any uncommitted changes. If there are, bail out, tell
# user.
exec git update-index --refresh
status = exec git status --porcelain -z
exec --fail-on-error git update-index --refresh
status = exec --fail-on-error git status --porcelain -z
status = trim ${status.stdout}
status_empty = is_empty ${status}
assert ${status_empty} "\nUncommited changes were found in the rust folder.\nEither commit them and create a patch, or set the USE_DIRTY_RUST_REPO environment variable."

# Check if there's any commits that got changed. If there are, tell the user
# to create patches.
output = exec git log --committer=^(?!patchsystem).*$ --perl-regexp --format=oneline
output = exec --fail-on-error git log --committer=^(?!patchsystem).*$ --perl-regexp --format=oneline
output = trim ${output.stdout}
output_empty = is_empty ${output}
assert ${output_empty} "\nRust repo has commits that weren't properly added to the patch system.\nEither run create-patches, or set the USE_DIRTY_RUST_REPO environment variable."

# Every commit belongs to the patchsystem, re-applying the patches is safe.
# Reset to initial commit (which imports the rust tree)
head = exec git rev-list --max-parents=0 HEAD
head = exec --fail-on-error git rev-list --max-parents=0 HEAD
head = trim ${head.stdout}
exec git reset --hard ${head}
exec --fail-on-error git reset --hard ${head}
# Apply all patches.
apply_patches
''']
Expand All @@ -457,17 +458,17 @@ script = [
'''
cd rust
# Get initial commit (which imports the rust tree)
head = exec git rev-list --max-parents=0 HEAD
head = exec --fail-on-error git rev-list --max-parents=0 HEAD
head = trim ${head.stdout}

# Change committer for the previous patches so they show up as being committed
# by patchsystem.
set_env FILTER_BRANCH_SQUELCH_WARNING 1
exec git update-ref -d refs/original/refs/heads/master
exec git filter-branch --env-filter "export GIT_COMMITTER_NAME=patchsystem; export GIT_COMMITTER_EMAIL=patchsystem" -- ${head}..
exec --fail-on-error git update-ref -d refs/original/refs/heads/master
exec --fail-on-error git filter-branch --env-filter "export GIT_COMMITTER_NAME=patchsystem; export GIT_COMMITTER_EMAIL=patchsystem" -- ${head}..

# Create patch for every commit after initial commit.
exec git format-patch -o ../rust-patches ${head}..
exec --fail-on-error git format-patch -o ../rust-patches ${head}..
''']

[tasks.clippy]
Expand Down
4 changes: 1 addition & 3 deletions Xargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ stage = 1
[patch.crates-io.libc]
git = "https://github.com/sunriseos/libc.git"
branch = "sunrise-2020-05-27"
features = ['align']

[patch.crates-io.compiler_builtins]
git = "https://github.com/sunriseos/compiler-builtins.git"
branch = "sunrise-2020-05-27"
features = ['soft-float']
branch = "sunrise-2022-08-19"

[patch."https://github.com/sunriseos/sunriseos.git".sunrise-libuser]
path = "libuser"
5 changes: 1 addition & 4 deletions ahci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ sunrise-libutils = { path = "../libutils" }
spin = "0.5"
log = "0.4.6"
bitfield = "0.13"
static_assertions = "1.1.0"

[dependencies.lazy_static]
features = ["spin_no_std"]
version = "1.3.0"

[dependencies.static_assertions]
version = "0.3.3"
features = ["nightly"]
6 changes: 4 additions & 2 deletions ahci/src/hba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//!
//! [Serial ATA AHCI: Specification, Rev. 1.3.1]: http://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/serial-ata-ahci-spec-rev1-3-1.pdf

use core::mem::ManuallyDrop;

use sunrise_libuser::io::{Io, Mmio};
use sunrise_libuser::syscalls::{sleep_thread, query_physical_address};
use sunrise_libuser::mem::{map_mmio, virt_to_phys};
Expand Down Expand Up @@ -1079,8 +1081,8 @@ unsafe impl ZeroInitialized for CmdTable {}
#[allow(clippy::missing_docs_in_private_items)]
#[repr(C)]
union Cfis {
raw_bytes: [Mmio<u8>; 64],
h2d: FisRegH2D,
raw_bytes: ManuallyDrop<[Mmio<u8>; 64]>,
h2d: ManuallyDrop<FisRegH2D>,
// ...
}

Expand Down
4 changes: 2 additions & 2 deletions ahci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
//! simultaneously. Unfortunately we can't take advantage of that until we manage to
//! make command-completion interrupts work.

#![feature(box_syntax, untagged_unions)]
#![feature(box_syntax)]
#![no_std]

// rustc warnings
Expand All @@ -53,7 +53,7 @@
// rustdoc warnings
#![deny(missing_docs)]
#![deny(clippy::missing_docs_in_private_items)]
#![deny(intra_doc_link_resolution_failure)]
#![deny(rustdoc::broken_intra_doc_links)]

#[macro_use]
extern crate alloc;
Expand Down
8 changes: 5 additions & 3 deletions bootstrap/src/bootstrap_logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//!
//! This driver is meant to be as simple as possible

use core::arch::asm;

const COM1: u16 = 0x3F8;

/// Init the rs232 COM1. Must be called before logging anything.
Expand Down Expand Up @@ -46,12 +48,12 @@ pub fn bootstrap_log(string: &str) {

unsafe fn bootstrap_inb(port: u16) -> u8 {
let value: u8;
llvm_asm!("in $0, $1" : "={al}"(value) : "{dx}"(port) : "memory" : "intel", "volatile");
asm!("in al, dx", in("dx") port, out("al") value, options(nostack, nomem, preserves_flags));
value
}

unsafe fn bootstrap_outb(port: u16, value: u8) {
llvm_asm!("out $1, $0" : : "{al}"(value), "{dx}"(port) : "memory" : "intel", "volatile");
asm!("out dx, al", in("dx") port, in("al") value, options(nostack, nomem, preserves_flags));
}

/// A logger that sends its output to COM1.
Expand All @@ -69,5 +71,5 @@ impl ::core::fmt::Write for Serial {
fn write_str(&mut self, s: &str) -> Result<(), ::core::fmt::Error> {
bootstrap_log(s);
Ok(())
}
}
}
2 changes: 1 addition & 1 deletion bootstrap/src/bootstrap_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use sunrise_libutils::log2_ceil;

/// The size of a kernel stack in pages, not accounting for the page guard
// Make sure this value is the same as the one in kernel, or bad things happen.
pub const STACK_SIZE: usize = 8;
pub const STACK_SIZE: usize = 4095;
/// The size of a kernel stack in pages, with the page guard.
pub const STACK_SIZE_WITH_GUARD: usize = STACK_SIZE + 1;

Expand Down
83 changes: 47 additions & 36 deletions bootstrap/src/frame_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use sunrise_libutils::{bit_array_first_one, bit_array_first_count_one};
use crate::paging::PAGE_SIZE;
use crate::address::PhysicalAddress;
use crate::bootstrap_logging::Serial;
use core::fmt::Write;
use core::fmt::{self, Write};

/// A memory frame is the same size as a page
pub const MEMORY_FRAME_SIZE: usize = PAGE_SIZE;
Expand Down Expand Up @@ -192,41 +192,9 @@ impl FrameAllocator {
0x00000000,
0x00000001);

/* if log_enabled!(::log::Level::Info) {
let mut cur = None;
for (i, bitmap) in frames_bitmap.memory_bitmap.iter().enumerate() {
for j in 0..8 {
let curaddr = (i * 8 + j) * ::paging::PAGE_SIZE;
if bitmap & (1 << j) != 0 {
// Area is available
match cur {
None => cur = Some((FRAME_FREE, curaddr)),
Some((FRAME_OCCUPIED, last)) => {
info!("{:#010x} - {:#010x} OCCUPIED", last, curaddr);
cur = Some((FRAME_FREE, curaddr));
},
_ => ()
}
} else {
// Area is occupied
match cur {
None => cur = Some((FRAME_OCCUPIED, curaddr)),
Some((FRAME_FREE, last)) => {
info!("{:#010x} - {:#010x} AVAILABLE", last, curaddr);
cur = Some((FRAME_OCCUPIED, curaddr));
},
_ => ()
}
}
}
}
match cur {
Some((FRAME_FREE, last)) => info!("{:#010x} - {:#010x} AVAILABLE", last, 0xFFFFFFFFu32),
Some((FRAME_OCCUPIED, last)) => info!("{:#010x} - {:#010x} OCCUPIED", last, 0xFFFFFFFFu32),
_ => ()
}
} */
frames_bitmap.initialized = true
frames_bitmap.initialized = true;

writeln!(Serial, "{:?}", frames_bitmap);
}

/// Panics if the frames bitmap was not initialized
Expand Down Expand Up @@ -322,3 +290,46 @@ impl FrameAllocator {
frames_bitmap.memory_bitmap.set_bit(frame, FRAME_FREE);
}
}

impl fmt::Debug for AllocatorBitmap {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if !self.initialized {
return write!(f, "FrameAllocator {{ uninitialized }}");
}

let mut cur = None;
for (i, bitmap) in self.memory_bitmap.iter().enumerate() {
for j in 0..8 {
let curaddr = (i * 8 + j) * crate::paging::PAGE_SIZE;
if bitmap & (1 << j) != 0 {
// Area is available
match cur {
None => cur = Some((FRAME_FREE, curaddr)),
Some((FRAME_OCCUPIED, last)) => {
writeln!(f, " {:#010x} - {:#010x} OCCUPIED", last, curaddr)?;
cur = Some((FRAME_FREE, curaddr));
},
_ => ()
}
} else {
// Area is occupied
match cur {
None => cur = Some((FRAME_OCCUPIED, curaddr)),
Some((FRAME_FREE, last)) => {
writeln!(f, " {:#010x} - {:#010x} AVAILABLE", last, curaddr)?;
cur = Some((FRAME_OCCUPIED, curaddr));
},
_ => ()
}
}
}
}
match cur {
Some((FRAME_FREE, last)) => writeln!(f, " {:#010x} - {:#010x} AVAILABLE", last, 0xFFFFFFFFu32)?,
Some((FRAME_OCCUPIED, last)) => writeln!(f, " {:#010x} - {:#010x} OCCUPIED", last, 0xFFFFFFFFu32)?,
_ => ()
}

Ok(())
}
}
Loading