Skip to content

Commit

Permalink
Add rust doom port
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalmiel committed Oct 12, 2024
1 parent 40829c7 commit ccc8127
Show file tree
Hide file tree
Showing 20 changed files with 643 additions and 52 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[submodule "acpica/acpica"]
path = acpica/acpica
url = https://github.com/acpica/acpica
[submodule "userspace/doom/doomgeneric"]
path = userspace/doom/doomgeneric
url = https://github.com/rafalmiel/doomgeneric.git
branch = cykusz
52 changes: 6 additions & 46 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion cykusz-rs/src/arch/x86_64/asm/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ SECTIONS {
KEEP(*(.multiboot_header))
build/arch/x86_64/asm/boot.o(.text* .rodata* .data* .bss*)
build/arch/x86_64/asm/paging.o(.text* .rodata* .data* .bss*)
build/arch/x86_64/asm/sse.o(.text* .rodata* .data* .bss*)
build/arch/x86_64/asm/test.o(.text* .rodata* .data* .bss*)
build/arch/x86_64/asm/long_mode_init.o(.text* .rodata* .data* .bss*)
}
Expand Down
1 change: 1 addition & 0 deletions cykusz-rs/src/drivers/ps2/mouse/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ impl INode for MouseState {
flags: OpenFlags,
) -> crate::kernel::fs::vfs::Result<usize> {
if buf.len() % core::mem::size_of::<Event>() != 0 {
dbgln!(mouse, "Failed mouse read of {} bytes", buf.len());
Err(FsError::InvalidParam)
} else {
Ok(self.buf.read_data_flags(
Expand Down
2 changes: 1 addition & 1 deletion disk-scripts/install_os.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fi
sudo umount mnt

PROGS="test testcpp hello stack nyancat ttytest fork poweroff stat fbdoom doom1.wad open_sleep"
RUST_PROGS="init shell mount umount unixsocket-server unixsocket-client forktest mprotecttest playwav playmidi threads sound-daemon"
RUST_PROGS="init shell mount umount unixsocket-server unixsocket-client forktest mprotecttest playwav playmidi threads sound-daemon doom"

sudo mount /dev/loop0p2 mnt
sudo chown -R $USER:$USER mnt
Expand Down
2 changes: 2 additions & 0 deletions syscall-defs/src/events/buttons.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[allow(non_camel_case_types, dead_code)]
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
#[repr(u16)]
pub enum ButtonCode {
BTN_MOUSE = 0x100,
BTN_LEFT = 0x110,
Expand All @@ -11,6 +12,7 @@ pub enum ButtonCode {

#[allow(non_camel_case_types, dead_code)]
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
#[repr(u16)]
pub enum RelCode {
REL_X = 0x00,
REL_Y = 0x01,
Expand Down
1 change: 1 addition & 0 deletions syscall-defs/src/events/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub const NR_KEYS: usize = 256;

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
#[allow(non_camel_case_types, dead_code)]
#[repr(u16)]
pub enum KeyCode {
KEY_RESERVED = 0,
KEY_ESC = 1,
Expand Down
1 change: 1 addition & 0 deletions syscall-defs/src/ioctl/fb.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub const GFBINFO: usize = 0x3415;

#[derive(Default)]
pub struct FbInfo {
pub width: u64,
pub height: u64,
Expand Down
4 changes: 4 additions & 0 deletions userspace/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ rustc = "../sysroot/cross/usr/local/bin/rustc"
target = "x86_64-unknown-cykusz"
rustflags = ["-C", "link-args=-no-pie", "-C", "link-args=-lgcc_s", "-Z", "threads=8"]

[env]
CC = { value = "../sysroot/cross/usr/bin/x86_64-cykusz-gcc", relative = true }
AR = { value = "../sysroot/cross/usr/bin/x86_64-cykusz-ar", relative = true }

[target.x86_64-unknown-cykusz]
linker = "../sysroot/cross/usr/bin/x86_64-cykusz-gcc"

Expand Down
29 changes: 27 additions & 2 deletions userspace/Cargo.lock

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

2 changes: 1 addition & 1 deletion userspace/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
resolver = "2"
members = ["init", "shell", "mount", "umount", "syscall-user", "unixsockets", "testprogs", "playaudio", "sound-daemon"]
members = ["doom", "init", "shell", "mount", "umount", "syscall-user", "unixsockets", "testprogs", "playaudio", "sound-daemon"]
16 changes: 16 additions & 0 deletions userspace/doom/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "doom"
version = "0.1.0"
edition = "2021"

[dependencies]
libc = "*"

[dependencies.syscall-defs]
path = "../../syscall-defs"

[dependencies.syscall-user]
path = "../syscall-user"

[build-dependencies]
cc = "1.0"
37 changes: 37 additions & 0 deletions userspace/doom/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
let ref dg_src_dir = std::path::PathBuf::from("doomgeneric/doomgeneric");
let mut dg_c_paths = vec![];
let mut dg_h_paths = vec![];

// Find most c and h files
for entry in std::fs::read_dir(dg_src_dir)? {
let entry = entry?;
if let Some(filename) = entry.file_name().to_str() {
if filename.starts_with("doomgeneric_")
|| filename == "i_main.c"
|| filename.contains("sdl")
|| filename.contains("allegro")
{
continue;
}

if filename.ends_with(".h") {
dg_h_paths.push(dg_src_dir.join(filename));
} else if filename.ends_with(".c") {
dg_c_paths.push(dg_src_dir.join(filename));
}
}
}
dg_c_paths
.iter()
.chain(dg_h_paths.iter())
.for_each(|path| println!("cargo:rerun-if-changed={}", path.to_str().unwrap()));

cc::Build::new()
.flag("-w") // Disable warnings
.files(dg_c_paths)
.compile("doomgeneric");

println!("cargo:rustc-link-lib=static=doomgeneric");
Ok(())
}
1 change: 1 addition & 0 deletions userspace/doom/doomgeneric
Submodule doomgeneric added at 6ba55e
44 changes: 44 additions & 0 deletions userspace/doom/src/cykusz.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
mod fb;
mod input;

use crate::DoomScreen;
use std::process::ExitCode;

pub struct CykuszDoom {
fb: fb::Fb,
input: input::Input,
}

impl CykuszDoom {
pub fn new(doom_screen: DoomScreen) -> Result<CykuszDoom, ExitCode> {
Ok(CykuszDoom {
fb: fb::Fb::new(doom_screen)?,
input: input::Input::new(),
})
}

pub fn get_ticks_ms(&self) -> u32 {
((unsafe { syscall_user::syscall0(syscall_defs::SYS_TICKSNS).unwrap() }) / 1_000_000) as u32
}

pub fn sleep_ms(&self, ms: u32) {
syscall_user::sleep(ms as usize).unwrap();
}

pub fn draw_frame(&mut self) {
self.input.poll();
self.fb.flip();
}

pub fn get_key(&mut self) -> Option<(bool, u8)> {
self.input.get_key()
}

pub fn get_mouse(&mut self) -> Option<((bool, bool, bool), i32, i32)> {
self.input.get_mouse()
}

pub fn quit(&self) {
self.input.quit();
}
}
Loading

0 comments on commit ccc8127

Please sign in to comment.