Skip to content

Commit

Permalink
Support tcsattr flush. Add poweroff utility
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalmiel committed Oct 19, 2023
1 parent fc9c6e4 commit 983b41c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 18 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ cross_nyancat := sysroot/build/nyancat
cross_ttytest := sysroot/build/ttytest
cross_fork := sysroot/build/fork
cross_forktest := sysroot/build/forktest
cross_poweroff := sysroot/build/poweroff

usb_dev := /dev/sdb1

Expand Down Expand Up @@ -119,6 +120,7 @@ hello: $(cross_cpp) sysroot/test.c sysroot/test.cpp sysroot/hello.cpp sysroot/st
$(cross_c) sysroot/ttytest.c -o $(cross_ttytest)
$(cross_c) sysroot/fork.c -o $(cross_fork)
$(cross_c) sysroot/forktest.c -o $(cross_forktest)
$(cross_c) sysroot/poweroff.c -o $(cross_poweroff)
$(cross_c) sysroot/stat.c -o sysroot/build/stat
sysroot/build.sh cykusz_nyancat
$(cross_strip) $(cross_hello)
Expand Down
6 changes: 6 additions & 0 deletions cykusz-rs/src/drivers/tty/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ impl InputBuffer {
n - remaining
}

pub(crate) fn flush(&mut self) {
self.r = self.w;

self.clear_eof();
}

pub(crate) fn commit_write(&mut self) {
self.w = self.e;
}
Expand Down
12 changes: 8 additions & 4 deletions cykusz-rs/src/drivers/tty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ impl INode for Tty {
}

if current_task_ref().terminal().connect(tty().clone()) {
println!("TERMINAL ATTACHED TO TASK {}", current.tid());
logln!("TERMINAL ATTACHED TO TASK {}", current.tid());
Ok(0)
} else {
Err(FsError::EntryExists)
Expand Down Expand Up @@ -567,15 +567,19 @@ impl INode for Tty {

Ok(0)
}
tty::TCSETS => {
ioctl @ (tty::TCSETS | tty::TCSETSW | tty::TCSETSF) => {
let termios =
unsafe { VirtAddr(arg).read_ref::<syscall_defs::ioctl::tty::Termios>() };

logln!("termios TCSETS 0x{:x}", termios.c_lflag);
logln!("{:?}", termios);
logln3!("termios TCSETS 0x{:x}", termios.c_lflag);
logln3!("{:?}", termios);

*self.termios.lock_irq() = *termios;

if ioctl == tty::TCSETSF {
self.buffer.lock_irq().flush();
}

Ok(0)
}
tty::TCGETS => {
Expand Down
12 changes: 2 additions & 10 deletions cykusz-rs/src/kernel/sched/round_robin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,31 +410,23 @@ impl Queues {
self.deadline_awaiting.push_back(task);
}

fn push_runnable(&mut self, task: Arc<Task>, continued: bool) {
fn push_runnable(&mut self, task: Arc<Task>, _continued: bool) {
assert_eq!(task.sched.is_linked(), false);
assert_ne!(task.tid(), self.idle_task.tid());

task.set_state(TaskState::Runnable);
//task.set_sleep_until(0);
self.runnable.push_back(task.clone());

if continued {
task.set_has_pending_io(true);
}
}

fn push_runnable_front(&mut self, task: Arc<Task>, continued: bool) {
fn push_runnable_front(&mut self, task: Arc<Task>, _continued: bool) {
assert_eq!(task.sched.is_linked(), false);
assert_ne!(task.tid(), self.idle_task.tid());

task.set_state(TaskState::Runnable);
//task.set_sleep_until(0);

self.runnable.push_front(task.clone());

if continued {
task.set_has_pending_io(true);
}
}
}

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 @@ -13,7 +13,7 @@ sed -i "s/{ROOT_UUID}/$(blkid -s UUID -o value /dev/loop0p2)/g" mnt/grub/grub.cf

umount mnt

PROGS="test testcpp hello stack nyancat ttytest fork forktest stat fbdoom DOOM1.WAD"
PROGS="test testcpp hello stack nyancat ttytest fork forktest poweroff stat fbdoom DOOM1.WAD"

mount /dev/loop0p2 mnt
mkdir -p mnt/bin
Expand Down
2 changes: 2 additions & 0 deletions syscall-defs/src/ioctl/tty.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub const TCGETS: usize = 0x5401;
pub const TCSETS: usize = 0x5402;
pub const TCSETSW: usize = 0x5403;
pub const TCSETSF: usize = 0x5404;

pub const TIOCSCTTY: usize = 0x540E;
pub const TIOCNOTTY: usize = 0x5422;
Expand Down
10 changes: 7 additions & 3 deletions userspace/src/bin/init/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ fn spawn_shell() -> usize {
if let Err(e) = syscall::setsid() {
println!("[ init ] setsid failed {:?}", e);
}
//syscall::ioctl(0, syscall_defs::ioctl::tty::TIOCSCTTY, 0)
// .expect("Failed to attach tty");
if let Err(e) = syscall::exec("/bin/shell", None, None) {
syscall::ioctl(0, syscall_defs::ioctl::tty::TIOCSCTTY, 0)
.expect("Failed to attach tty");
if let Err(e) = syscall::exec(
"/usr/bin/bash",
None,
Some(&["PATH=/bin:/usr/bin", "TERM=cykusz"]),
) {
panic!("Failed to spawn shell {:?}", e);
}

Expand Down

0 comments on commit 983b41c

Please sign in to comment.