Skip to content

Commit 5fdfc65

Browse files
committed
vexos: move fs and stdio into respective modules
1 parent 6d53256 commit 5fdfc65

File tree

9 files changed

+26
-84
lines changed

9 files changed

+26
-84
lines changed

compiler/rustc_target/src/spec/targets/armv7a_vex_v5.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub(crate) fn target() -> Target {
3434
description: Some("ARMv7-A Cortex-A9 VEX V5 Brain".into()),
3535
tier: Some(3),
3636
host_tools: Some(false),
37-
std: Some(false),
37+
std: Some(true),
3838
},
3939
pointer_width: 32,
4040
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),

library/Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ dependencies = [
394394
[[package]]
395395
name = "vex-sdk"
396396
version = "0.27.0"
397+
source = "git+https://github.com/vexide/vex-sdk.git#67771319f730557693b2aa1e84c7ecd4831efb13"
397398
dependencies = [
398399
"rustc-std-workspace-core",
399400
]

library/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ rustc-std-workspace-core = { path = 'rustc-std-workspace-core' }
6060
rustc-std-workspace-alloc = { path = 'rustc-std-workspace-alloc' }
6161
rustc-std-workspace-std = { path = 'rustc-std-workspace-std' }
6262

63-
vex-sdk = { path = "../../vex-sdk/packages/vex-sdk" }
63+
vex-sdk = { git = "https://github.com/vexide/vex-sdk.git" }

library/std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ r-efi = { version = "5.2.0", features = ['rustc-dep-of-std'] }
9090
r-efi-alloc = { version = "2.0.0", features = ['rustc-dep-of-std'] }
9191

9292
[target.'cfg(target_os = "vexos")'.dependencies]
93-
vex-sdk = { version = "0.27.0", features = [
93+
vex-sdk = { git = "https://github.com/vexide/vex-sdk.git", features = [
9494
'rustc-dep-of-std',
9595
], default-features = false }
9696

library/std/src/sys/fs/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ cfg_select! {
3535
mod uefi;
3636
use uefi as imp;
3737
}
38+
target_os = "vexos" => {
39+
mod vexos;
40+
use vexos as imp;
41+
}
3842
target_os = "wasi" => {
3943
mod wasi;
4044
use wasi as imp;

library/std/src/sys/pal/vexos/fs.rs renamed to library/std/src/sys/fs/vexos.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
505505
}
506506

507507
fn map_fresult(fresult: vex_sdk::FRESULT) -> io::Result<()> {
508-
// VEX presumably uses a derivative of FatFs (most likely the xilffs library)
509-
// for sdcard filesystem functions.
510-
//
511-
// Documentation for each FRESULT originates from here:
512-
// <http://elm-chan.org/fsw/ff/doc/rc.html>
508+
// VEX uses a derivative of FatFs (Xilinx's xilffs library) for filesystem operations.
513509
match fresult {
514510
vex_sdk::FRESULT::FR_OK => Ok(()),
515511
vex_sdk::FRESULT::FR_DISK_ERR => Err(io::Error::new(

library/std/src/sys/pal/vexos/mod.rs

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
1-
#[path = "../unsupported/args.rs"]
2-
pub mod args;
3-
pub mod env;
4-
pub mod fs;
5-
#[path = "../unsupported/io.rs"]
6-
pub mod io;
7-
#[path = "../unsupported/net.rs"]
8-
pub mod net;
91
#[path = "../unsupported/os.rs"]
102
pub mod os;
113
#[path = "../unsupported/pipe.rs"]
124
pub mod pipe;
13-
#[path = "../unsupported/process.rs"]
14-
pub mod process;
15-
pub mod stdio;
165
pub mod thread;
176
pub mod time;
187

@@ -41,39 +30,19 @@ pub unsafe extern "C" fn _start() -> ! {
4130
fn main() -> i32;
4231
}
4332

44-
// VEXos doesn't explicitly clean out .bss.
45-
ptr::slice_from_raw_parts_mut(
46-
addr_of_mut!(__bss_start),
47-
addr_of_mut!(__bss_end).offset_from(addr_of_mut!(__bss_start)) as usize,
48-
)
49-
.as_mut()
50-
.unwrap_unchecked()
51-
.fill(0);
33+
// Clear the .bss (uninitialized statics) section by filling it with zeroes.
34+
// This is required, since the compiler assumes it will be zeroed on first access.
35+
ptr::write_bytes(
36+
&raw mut __bss_start,
37+
0,
38+
(&raw mut __bss_end).offset_from(&raw mut __bss_start) as usize,
39+
);
5240

5341
main();
5442

5543
abort_internal()
5644
}
5745

58-
// The code signature is a 32 byte header at the start of user programs that
59-
// identifies the owner and type of the program, as well as certain flags for
60-
// program behavior dictated by the OS. In the event that the user wants to
61-
// change this header, we use weak linkage so it can be overwritten.
62-
#[link_section = ".code_signature"]
63-
#[linkage = "weak"]
64-
#[used]
65-
static CODE_SIGNATURE: vex_sdk::vcodesig =
66-
vex_sdk::vcodesig { magic: u32::from_le_bytes(*b"XVX5"), r#type: 0, owner: 2, options: 0 };
67-
68-
// This function is needed by the panic runtime. The symbol is named in
69-
// pre-link args for the target specification, so keep that in sync.
70-
#[cfg(not(test))]
71-
#[no_mangle]
72-
// NB. used by both libunwind and libpanic_abort
73-
pub extern "C" fn __rust_abort() -> ! {
74-
abort_internal()
75-
}
76-
7746
// SAFETY: must be called only once during runtime initialization.
7847
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
7948
pub unsafe fn init(_argc: isize, _argv: *const *const u8, _sigpipe: u8) {}

library/std/src/sys/stdio/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ cfg_select! {
2929
mod uefi;
3030
pub use uefi::*;
3131
}
32+
target_os = "vexos" => {
33+
mod vexos;
34+
pub use vexos::*;
35+
}
3236
target_os = "wasi" => {
3337
mod wasi;
3438
pub use wasi::*;

library/std/src/sys/pal/vexos/stdio.rs renamed to library/std/src/sys/stdio/vexos.rs

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use crate::io;
22

3-
pub struct Stdin(());
4-
pub struct Stdout(());
5-
pub struct Stderr(());
3+
pub struct Stdin;
4+
pub struct Stdout;
5+
pub type Stderr = Stdout;
66

7-
pub const STDIO_CHANNEL: u32 = 1;
7+
const STDIO_CHANNEL: u32 = 1;
88

99
impl Stdin {
1010
pub const fn new() -> Stdin {
11-
Stdin(())
11+
Stdin
1212
}
1313
}
1414

@@ -34,7 +34,7 @@ impl io::Read for Stdin {
3434

3535
impl Stdout {
3636
pub const fn new() -> Stdout {
37-
Stdout(())
37+
Stdout
3838
}
3939
}
4040

@@ -64,38 +64,6 @@ impl io::Write for Stdout {
6464
}
6565
}
6666

67-
impl Stderr {
68-
pub const fn new() -> Stderr {
69-
Stderr(())
70-
}
71-
}
72-
73-
impl io::Write for Stderr {
74-
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
75-
let written =
76-
unsafe { vex_sdk::vexSerialWriteBuffer(STDIO_CHANNEL, buf.as_ptr(), buf.len() as u32) };
77-
78-
if written < 0 {
79-
return Err(io::Error::new(
80-
io::ErrorKind::Uncategorized,
81-
"Internal write error occurred.",
82-
));
83-
}
84-
85-
Ok(written as usize)
86-
}
87-
88-
fn flush(&mut self) -> io::Result<()> {
89-
unsafe {
90-
while (vex_sdk::vexSerialWriteFree(STDIO_CHANNEL) as usize) != STDOUT_BUF_SIZE {
91-
vex_sdk::vexTasksRun();
92-
}
93-
}
94-
95-
Ok(())
96-
}
97-
}
98-
9967
pub const STDIN_BUF_SIZE: usize = 4096;
10068
pub const STDOUT_BUF_SIZE: usize = 2048;
10169

0 commit comments

Comments
 (0)