diff --git a/Cargo.lock b/Cargo.lock index 1dfb25c..c1ad3c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -122,6 +122,62 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" +[[package]] +name = "crossbeam" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1137cd7e7fc0fb5d3c5a8678be38ec56e819125d8d7907411fe24ccb943faca8" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-queue" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + [[package]] name = "goblin" version = "0.10.4" @@ -281,6 +337,7 @@ version = "0.0.0" dependencies = [ "anyhow", "clap", + "crossbeam", "goblin", "int-enum", "memmap2", diff --git a/Cargo.toml b/Cargo.toml index 35ad73b..42f4eea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2024" [dependencies] anyhow = "1.0.100" clap = { version = "4.5.53", features = ["derive"] } +crossbeam = { version = "0.8.4", features = ["crossbeam-channel"] } goblin = "0.10.4" int-enum = "1.2.0" memmap2 = "0.9.8" diff --git a/src/core.rs b/src/core.rs index 30d879a..4a05aa8 100644 --- a/src/core.rs +++ b/src/core.rs @@ -1,10 +1,10 @@ -// Copyright (c) 2025 taitep +// Copyright (c) 2025-2026 taitep // SPDX-License-Identifier: BSD-2-Clause // // This file is part of TRVE (https://gitea.taitep.se/taitep/trve) // See LICENSE file in the project root for full license text. -use std::{collections::HashSet, sync::mpsc}; +use std::collections::HashSet; use crate::{ core::commands::CoreCmd, @@ -19,13 +19,13 @@ pub struct Core { pub(crate) x_regs: [u64; 32], pub(crate) pc: u64, pub(crate) mem: MemConfig, - command_stream: mpsc::Receiver, + command_stream: crossbeam::channel::Receiver, } pub mod commands; impl Core { - pub fn new(mem: MemConfig, command_stream: mpsc::Receiver) -> Self { + pub fn new(mem: MemConfig, command_stream: crossbeam::channel::Receiver) -> Self { Self { x_regs: [0; 32], pc: 0, @@ -103,7 +103,10 @@ impl Core { }; } - fn debug_loop(&mut self, dbg_stream: mpsc::Receiver) -> anyhow::Result<()> { + fn debug_loop( + &mut self, + dbg_stream: crossbeam::channel::Receiver, + ) -> anyhow::Result<()> { let mut breakpoints = HashSet::new(); loop { diff --git a/src/gdb.rs b/src/gdb.rs index d781a6a..7c1fcd8 100644 --- a/src/gdb.rs +++ b/src/gdb.rs @@ -1,4 +1,4 @@ -// Copyright (c) 2025 taitep +// Copyright (c) 2025-2026 taitep // SPDX-License-Identifier: BSD-2-Clause // // This file is part of TRVE (https://gitea.taitep.se/taitep/trve) @@ -7,7 +7,6 @@ use std::{ io::{self, BufRead, ErrorKind, Write}, net::{TcpListener, TcpStream}, - sync::mpsc, }; use crate::{ @@ -29,7 +28,7 @@ pub(crate) enum DebugCommand { ExitDebugMode, } -pub struct DebugStream(pub(crate) mpsc::Receiver); +pub struct DebugStream(pub(crate) crossbeam::channel::Receiver); #[derive(Clone, Copy, Debug)] pub(crate) enum StopReason { @@ -68,13 +67,13 @@ pub(crate) struct RegsResponse { pub pc: u64, } -pub fn run_stub(cmd_sender: mpsc::Sender) { +pub fn run_stub(cmd_sender: crossbeam::channel::Sender) { std::thread::spawn(move || { let listener = TcpListener::bind("127.0.0.1:1234").expect("couldnt start tcp listener"); for stream_res in listener.incoming() { if let Ok(stream) = stream_res { - let (dbg_tx, dbg_rx) = mpsc::channel(); + let (dbg_tx, dbg_rx) = crossbeam::channel::bounded(16); stream .set_nonblocking(true) @@ -92,7 +91,7 @@ pub fn run_stub(cmd_sender: mpsc::Sender) { fn handle_gdb_connection( gdb_stream: TcpStream, - dbg_tx: mpsc::Sender, + dbg_tx: crossbeam::channel::Sender, ) -> io::Result<()> { eprintln!("gdb connected"); let mut reader = io::BufReader::new(gdb_stream.try_clone()?); @@ -152,7 +151,7 @@ fn read_rsp_packet(reader: &mut R) -> io::Result { fn handle_packet( packet: &str, writer: &mut W, - dbg_tx: &mpsc::Sender, + dbg_tx: &crossbeam::channel::Sender, reader: &mut R, ) -> io::Result<()> { writer.write_all(b"+")?; diff --git a/src/main.rs b/src/main.rs index 4e02745..a9b8672 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -// Copyright (c) 2025 taitep +// Copyright (c) 2025-2026 taitep // SPDX-License-Identifier: BSD-2-Clause // // This file is part of TRVE (https://gitea.taitep.se/taitep/trve) @@ -48,7 +48,7 @@ fn main() -> Result<()> { mmio_root, }; - let (cmd_sender, cmd_reciever) = std::sync::mpsc::channel(); + let (cmd_sender, cmd_reciever) = crossbeam::channel::bounded(16); gdb::run_stub(cmd_sender.clone());