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

[WIP] Arch independence #183

Open
wants to merge 15 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 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ before_install:

script:
- cargo make iso
- cargo make iso-release
- cargo make iso --profile production
- cargo make test
- cargo make doc-full
- cargo make clippy-ci
Expand Down
25 changes: 25 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

123 changes: 30 additions & 93 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ skip_core_tasks = true
RUST_TARGET_PATH = "${PWD}"
GDB_PORT = { script = ["echo ${GDB_PORT:-9090}"] }
VNC_PORT = { script = ["echo ${VNC_PORT:-:0}"] }
TARGET = { script = ["echo ${TARGET:-i386-unknown-none}"] }
TARGET_PATH = "${TARGET}/debug"
# TODO: Find better work around cargo build not accepting empty arguments
RELEASE_FLAG = "--message-format=human"

[env.production]
TARGET_PATH = "${TARGET}/release"
RELEASE_FLAG = "--release"

[tasks.bootstrap-linker]
workspace = false
Expand All @@ -26,150 +34,79 @@ install_crate = { crate_name = "mkisofs-rs", binary = "mkisofs-rs", test_arg = "

[tasks.bootstrap]
workspace = false
description = "Compiles the i386 bootstrap for debug"
dependencies = ["bootstrap-linker", "install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none", "--package=kfs-bootstrap" ]

[tasks.bootstrap-release]
workspace = false
description = "Compiles the i386 bootstrap for release"
description = "Compiles the i386 bootstrap"
dependencies = ["bootstrap-linker", "install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none", "--package=kfs-bootstrap", "--release" ]
args = ["xbuild", "--target=${TARGET}", "--package=kfs-bootstrap", "${RELEASE_FLAG}"]

[tasks.kernel]
workspace = false
description = "Compiles the kernel for debug"
dependencies = ["kernel-linker", "install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none", "--package=kfs-kernel", "-Z", "package-features", "--features=panic-on-exception"]

[tasks.kernel-release]
workspace = false
description = "Compiles the kernel for release"
description = "Compiles the kernel"
dependencies = ["kernel-linker", "install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none", "--package=kfs-kernel", "--release" ]
args = ["xbuild", "--target=${TARGET}", "--package=kfs-kernel", "-Z", "package-features", "--features=panic-on-exception", "${RELEASE_FLAG}"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

panic-on-exception is a debug feature, it shouldn't be enabled when building for release ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I guess I'll add a KERNEL_FLAGS env variable.


[tasks.vi]
workspace = false
description = "Compiles kfs-vi"
dependencies = ["userspace-linker", "install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none", "--package=kfs-vi"]

[tasks.vi-release]
workspace = false
description = "Compiles kfs-vi"
dependencies = ["userspace-linker", "install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none", "--package=kfs-vi", "--release"]
args = ["xbuild", "--target=${TARGET}", "--package=kfs-vi", "${RELEASE_FLAG}"]

[tasks.sm]
workspace = false
description = "Compiles kfs-sm"
dependencies = ["userspace-linker", "install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none", "--package=kfs-sm"]

[tasks.sm-release]
workspace = false
description = "Compiles kfs-sm"
dependencies = ["userspace-linker", "install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none", "--package=kfs-sm", "--release"]
args = ["xbuild", "--target=${TARGET}", "--package=kfs-sm", "${RELEASE_FLAG}"]

[tasks.shell]
workspace = false
description = "Compiles kfs-shell"
dependencies = ["userspace-linker", "install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none", "--package=kfs-shell"]

[tasks.shell-release]
workspace = false
description = "Compiles kfs-shell"
dependencies = ["userspace-linker", "install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none", "--package=kfs-shell", "--release"]
args = ["xbuild", "--target=${TARGET}", "--package=kfs-shell", "${RELEASE_FLAG}"]

[tasks.clock]
workspace = false
description = "Compiles kfs-clock"
dependencies = ["userspace-linker", "install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none", "--package=kfs-clock"]

[tasks.clock-release]
workspace = false
description = "Compiles kfs-clock"
dependencies = ["userspace-linker", "install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none", "--package=kfs-clock", "--release"]
args = ["xbuild", "--target=${TARGET}", "--package=kfs-clock", "${RELEASE_FLAG}"]

[tasks.ahci]
workspace = false
description = "Compiles kfs-ahci"
dependencies = ["userspace-linker", "install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none", "--package=kfs-ahci"]

[tasks.ahci-release]
workspace = false
description = "Compiles kfs-ahci"
dependencies = ["userspace-linker", "install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none", "--package=kfs-ahci", "--release"]
args = ["xbuild", "--target=${TARGET}", "--package=kfs-ahci", "${RELEASE_FLAG}"]

[tasks.userspace]
workspace = false
description = "Compiles userspace apps"
dependencies = ["shell", "clock", "sm", "vi", "ahci"]

[tasks.userspace-release]
workspace = false
description = "Compiles userspace apps"
dependencies = ["shell-release", "clock-release", "sm-release", "vi-release", "ahci-release"]

[tasks.iso]
workspace = false
description = "Creates a bootable ISO containing the kernel and grub."
dependencies = ["bootstrap", "kernel", "userspace", "install-mkisofs-rs"]
script = [
'''
cp target/i386-unknown-none/debug/kfs-bootstrap isofiles/boot/
cp target/i386-unknown-none/debug/kfs-kernel isofiles/boot/
cp target/i386-unknown-none/debug/kfs-shell isofiles/boot/
cp target/i386-unknown-none/debug/kfs-clock isofiles/boot/
cp target/i386-unknown-none/debug/kfs-sm isofiles/boot/
cp target/i386-unknown-none/debug/kfs-vi isofiles/boot/
cp target/i386-unknown-none/debug/kfs-ahci isofiles/boot/
mkisofs-rs external/grub/isofiles isofiles -o os.iso -b boot/grub/i386-pc/eltorito.img --no-emul-boot --boot-info-table --embedded-boot external/grub/embedded.img
'''
]

[tasks.iso-release]
workspace = false
description = "Creates a bootable ISO containing the kernel and grub."
dependencies = ["bootstrap-release", "kernel-release", "userspace-release", "install-mkisofs-rs"]
script = [
'''
cp target/i386-unknown-none/release/kfs-bootstrap isofiles/boot/
cp target/i386-unknown-none/release/kfs-kernel isofiles/boot/
cp target/i386-unknown-none/release/kfs-shell isofiles/boot/
cp target/i386-unknown-none/release/kfs-clock isofiles/boot/
cp target/i386-unknown-none/release/kfs-sm isofiles/boot/
cp target/i386-unknown-none/release/kfs-vi isofiles/boot/
cp target/i386-unknown-none/release/kfs-ahci isofiles/boot/
cp target/${TARGET_PATH}/kfs-bootstrap isofiles/boot/
cp target/${TARGET_PATH}/kfs-kernel isofiles/boot/
cp target/${TARGET_PATH}/kfs-shell isofiles/boot/
cp target/${TARGET_PATH}/kfs-clock isofiles/boot/
cp target/${TARGET_PATH}/kfs-sm isofiles/boot/
cp target/${TARGET_PATH}/kfs-vi isofiles/boot/
cp target/${TARGET_PATH}/kfs-ahci isofiles/boot/
mkisofs-rs external/grub/isofiles isofiles -o os.iso -b boot/grub/i386-pc/eltorito.img --no-emul-boot --boot-info-table --embedded-boot external/grub/embedded.img
'''
]

[tasks.qemu]
workspace = false
description = "Runs the bootable ISO in qemu."
dependencies = ["iso-release"]
dependencies = ["iso"]
command = "qemu-system-i386"
args = ["-cdrom", "os.iso", "-serial", "stdio", "-vnc", "${VNC_PORT}", "-no-reboot", "-enable-kvm"]

Expand All @@ -185,22 +122,22 @@ workspace = false
description = "Generate the project's documentation"
env = { "RUSTFLAGS" = "--sysroot=${PWD}/target/sysroot", "RUSTDOCFLAGS" = "--sysroot=${PWD}/target/sysroot"}
command = "cargo"
args = ["doc", "--target=i386-unknown-none", "--no-deps" ]
args = ["doc", "--target=${TARGET}", "--no-deps" ]

[tasks.doc-full]
workspace = false
description = "Generate the project's documentation, including private items"
env = { "RUSTFLAGS" = "--sysroot=${PWD}/target/sysroot", "RUSTDOCFLAGS" = "--sysroot=${PWD}/target/sysroot -Z unstable-options --enable-index-page"}
command = "cargo"
args = ["doc", "--target=i386-unknown-none", "--no-deps", "--document-private-items"]
args = ["doc", "--target=${TARGET}", "--no-deps", "--document-private-items"]

[tasks.deploy-doc]
workspace = false
install_crate = { crate_name = "cargo-travis", binary = "cargo", test_arg = "doc-upload --help" }
install_crate_args = ["--git", "https://github.com/roblabla/cargo-travis", "--rev", "doc-upload-target"]
description = "Upload this project's documentation on github pages. Should only run on CI."
command = "cargo"
args = ["doc-upload", "--target=i386-unknown-none", "--clobber-index"]
args = ["doc-upload", "--target=${TARGET}", "--clobber-index"]

[tasks.test]
workspace = false
Expand All @@ -214,7 +151,7 @@ dependencies = ["install-rust-src"]
install_crate = { rustup_component_name = "clippy" }
description = "Run clippy"
command = "cargo"
args = ["xclippy", "--target=i386-unknown-none", "--",
args = ["xclippy", "--target=${TARGET}", "--",
"-A", "clippy::redundant_field_names",
"-A", "clippy::unreadable_literal",
"-A", "clippy::identity_op",
Expand All @@ -238,7 +175,7 @@ dependencies = ["install-rust-src"]
install_crate = { rustup_component_name = "clippy" }
description = "Run clippy"
command = "cargo"
args = ["xclippy", "--target=i386-unknown-none", "--",
args = ["xclippy", "--target=${TARGET}", "--",
"-A", "clippy::redundant_field_names",
"-A", "clippy::unreadable_literal",
"-A", "clippy::identity_op",
Expand Down
2 changes: 1 addition & 1 deletion isofiles/boot/grub/grub.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set timeout=10
set timeout=0
set timeout_style=countdown
set default=0

Expand Down
10 changes: 10 additions & 0 deletions kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ rustc-demangle = "0.1"
failure = { version = "0.1", default-features = false, features = ["derive"] }
bitfield = "0.13"
mashup = "0.1.9"
cfg-if = "0.1"
generic-array = "0.12"

[dependencies.intrusive-collections]
default-features = false
version = "0.7"

[dependencies.arrayvec]
default-features = false
version = "0.4.10"

[dependencies.smallvec]
default-features = false
Expand Down
12 changes: 6 additions & 6 deletions kernel/src/i386/gdt.rs → kernel/src/arch/i386/gdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ use core::ops::{Deref, DerefMut};
use core::slice;
use core::fmt;

use crate::i386::{PrivilegeLevel, TssStruct};
use crate::i386::structures::gdt::SegmentSelector;
use crate::i386::instructions::tables::{lgdt, sgdt, DescriptorTablePointer};
use crate::i386::instructions::segmentation::*;
use crate::arch::i386::{PrivilegeLevel, TssStruct};
use crate::arch::i386::structures::gdt::SegmentSelector;
use crate::arch::i386::instructions::tables::{lgdt, sgdt, DescriptorTablePointer};
use crate::arch::i386::instructions::segmentation::*;

use crate::paging::PAGE_SIZE;
use crate::paging::{MappingAccessRights, kernel_memory::get_kernel_memory};
use crate::frame_allocator::{FrameAllocator, FrameAllocatorTrait};
use crate::frame_allocator::FrameAllocator;
use crate::mem::VirtualAddress;
use alloc::vec::Vec;
use crate::utils::align_up;
Expand All @@ -39,7 +39,7 @@ static GLOBAL_LDT: Once<DescriptorTable> = Once::new();
/// This function should only be called once. Further calls will be silently
/// ignored.
pub fn init_gdt() {
use crate::i386::instructions::tables::{lldt, ltr};
use crate::arch::i386::instructions::tables::{lldt, ltr};

let ldt = GLOBAL_LDT.call_once(DescriptorTable::new);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@
//! defined in the event module. It is expected that these pointer will then be
//! inserted in an architecture-specific interrupt table (such as i386's IDT).

use crate::i386::structures::idt::ExceptionStackFrame;
use crate::arch::i386::structures::idt::ExceptionStackFrame;
use crate::devices::pic;

#[allow(clippy::missing_docs_in_private_items)]
extern "x86-interrupt" fn timer_handler(_stack_frame: &mut ExceptionStackFrame) {
// TODO: Feed the timer handler into a kernel preemption handler.
pic::get().acknowledge(0);
}

macro_rules! irq_handler {
($irq:expr, $name:ident) => {{
#[allow(clippy::missing_docs_in_private_items)]
Expand Down
Loading