aboutsummaryrefslogtreecommitdiff
path: root/cortex-m-semihosting
diff options
context:
space:
mode:
Diffstat (limited to 'cortex-m-semihosting')
-rw-r--r--cortex-m-semihosting/CHANGELOG.md2
-rw-r--r--cortex-m-semihosting/src/export.rs6
-rw-r--r--cortex-m-semihosting/src/hio.rs39
-rw-r--r--cortex-m-semihosting/src/lib.rs8
4 files changed, 17 insertions, 38 deletions
diff --git a/cortex-m-semihosting/CHANGELOG.md b/cortex-m-semihosting/CHANGELOG.md
index f813f8b..aa7cb9b 100644
--- a/cortex-m-semihosting/CHANGELOG.md
+++ b/cortex-m-semihosting/CHANGELOG.md
@@ -5,6 +5,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
+- Merge `HStdout` and `HStderr` into one type: `HostStream`
+
## [v0.3.5] - 2019-08-29
### Added
diff --git a/cortex-m-semihosting/src/export.rs b/cortex-m-semihosting/src/export.rs
index c188ab0..0bbd09f 100644
--- a/cortex-m-semihosting/src/export.rs
+++ b/cortex-m-semihosting/src/export.rs
@@ -4,9 +4,9 @@ use core::fmt::{self, Write};
use cortex_m::interrupt;
-use crate::hio::{self, HStderr, HStdout};
+use crate::hio::{self, HostStream};
-static mut HSTDOUT: Option<HStdout> = None;
+static mut HSTDOUT: Option<HostStream> = None;
pub fn hstdout_str(s: &str) {
let _result = interrupt::free(|_| unsafe {
@@ -28,7 +28,7 @@ pub fn hstdout_fmt(args: fmt::Arguments) {
});
}
-static mut HSTDERR: Option<HStderr> = None;
+static mut HSTDERR: Option<HostStream> = None;
pub fn hstderr_str(s: &str) {
let _result = interrupt::free(|_| unsafe {
diff --git a/cortex-m-semihosting/src/hio.rs b/cortex-m-semihosting/src/hio.rs
index 61ac749..b0ca2fb 100644
--- a/cortex-m-semihosting/src/hio.rs
+++ b/cortex-m-semihosting/src/hio.rs
@@ -3,64 +3,45 @@
use core::{fmt, slice};
use crate::nr;
-/// Host's standard error
+/// A byte stream to the host (e.g., host's stdout or stderr).
#[derive(Clone, Copy)]
-pub struct HStderr {
+pub struct HostStream {
fd: usize,
}
-impl HStderr {
+impl HostStream {
/// Attempts to write an entire `buffer` into this sink
pub fn write_all(&mut self, buffer: &[u8]) -> Result<(), ()> {
write_all(self.fd, buffer)
}
}
-impl fmt::Write for HStderr {
- fn write_str(&mut self, s: &str) -> fmt::Result {
- self.write_all(s.as_bytes()).map_err(|_| fmt::Error)
- }
-}
-
-/// Host's standard output
-#[derive(Clone, Copy)]
-pub struct HStdout {
- fd: usize,
-}
-
-impl HStdout {
- /// Attempts to write an entire `buffer` into this sink
- pub fn write_all(&mut self, buffer: &[u8]) -> Result<(), ()> {
- write_all(self.fd, buffer)
- }
-}
-
-impl fmt::Write for HStdout {
+impl fmt::Write for HostStream {
fn write_str(&mut self, s: &str) -> fmt::Result {
self.write_all(s.as_bytes()).map_err(|_| fmt::Error)
}
}
/// Construct a new handle to the host's standard error.
-pub fn hstderr() -> Result<HStderr, ()> {
+pub fn hstderr() -> Result<HostStream, ()> {
// There is actually no stderr access in ARM Semihosting documentation. Use
// convention used in libgloss.
// See: libgloss/arm/syscalls.c, line 139.
// https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=libgloss/arm/syscalls.c#l139
- open(":tt\0", nr::open::W_APPEND).map(|fd| HStderr { fd })
+ open(":tt\0", nr::open::W_APPEND)
}
/// Construct a new handle to the host's standard output.
-pub fn hstdout() -> Result<HStdout, ()> {
- open(":tt\0", nr::open::W_TRUNC).map(|fd| HStdout { fd })
+pub fn hstdout() -> Result<HostStream, ()> {
+ open(":tt\0", nr::open::W_TRUNC)
}
-fn open(name: &str, mode: usize) -> Result<usize, ()> {
+fn open(name: &str, mode: usize) -> Result<HostStream, ()> {
let name = name.as_bytes();
match unsafe { syscall!(OPEN, name.as_ptr(), mode, name.len() - 1) } as
isize {
-1 => Err(()),
- fd => Ok(fd as usize),
+ fd => Ok(HostStream { fd: fd as usize }),
}
}
diff --git a/cortex-m-semihosting/src/lib.rs b/cortex-m-semihosting/src/lib.rs
index b70dea0..de52ae1 100644
--- a/cortex-m-semihosting/src/lib.rs
+++ b/cortex-m-semihosting/src/lib.rs
@@ -25,7 +25,7 @@
//!
//! # Example
//!
-//! ## Using `hio::HStdout`
+//! ## Using `hio::hstdout`
//!
//! This example will demonstrate how to print formatted strings.
//!
@@ -35,11 +35,7 @@
//!
//! // This function will be called by the application
//! fn print() -> Result<(), core::fmt::Error> {
-//! let mut stdout = match hio::hstdout() {
-//! Ok(fd) => fd,
-//! Err(()) => return Err(core::fmt::Error),
-//! };
-//!
+//! let mut stdout = hio::hstdout().map_err(|_| core::fmt::Error)?;
//! let language = "Rust";
//! let ranking = 1;
//!
class='list nowrap'>AgeCommit message (Collapse)AuthorFilesLines 2023-04-06fix(node:events): fix abort behaviorGravatar Derrick Farris 3-170/+177 2023-04-06test(node:events): remove `console.log`Gravatar Derrick Farris 1-1/+0 2023-04-06feat(node:events): finish `EE.AsyncIterator` and `node:events.on()`, add ↵Gravatar Derrick Farris 5-369/+276 some tests 2023-04-06wip(node:events): get async iter working, work through test flakinessGravatar Derrick Farris 5-236/+328 2023-04-06wip(node:events): fix `node:events.on` async iter to specGravatar Derrick Farris 16-136/+1116 2023-04-06docs: add a section on uninstalling bun (#2560)Gravatar dave caruso 1-0/+8 2023-04-06docs(cli/bunx): add notice (#2574)Gravatar Jozef Steinhübl 1-0/+4 * docs(cli/bunx): add notice bunx alias bun x * docs: grammar 2023-04-06Fix `toEqual` when the second array has extra array holes (#2580)Gravatar Dylan Conway 3-18/+76 * iterate through remaining indexes, keep prop identifier * tests * format 2023-04-06Add last modify field "mtime" for FileBlob (#1431) (#2491)Gravatar Zhongwei Yao 6-33/+128 * Add lastModified field for FileBlob (#1431) lastModified value is epoch timestamp in millisecond unit. * update according to review comment. 2023-04-06bun-types: infer strict `Subprocess` from `Bun.spawn()` options, part 2 (#2573)Gravatar dave caruso 9-67/+165 2023-04-06cache needs to update, move to another process (#2578)Gravatar Dylan Conway 2-156/+171 2023-04-06fix(ws): export Server (#2575)Gravatar hiroki osame 1-13/+30 2023-04-06docs(CONTRIBUTING): referece development guide (#2576)Gravatar hiroki osame 1-1/+5 2023-04-05rebase (#1501)Gravatar dave caruso 2-144/+305 2023-04-05Update `typecheck` (#2572)Gravatar Colin McDonnell 3-4/+8 * Update typecheck * Test ci * Test ci * Prettify files 2023-04-05prependGravatar Jarred Sumner 1-7/+3 2023-04-05Add tests for `bun test` with preload scripts (#2566)Gravatar Jake Boone 2-1/+107 * Use zsh-compatible syntax in cowsay example zsh interprets the string !" differently than bash or sh, but we can use single quotes in all of them. See https://unix.stackexchange.com/a/497335/548905. * Add tests for bun:test with preload scripts * Look at `stderr` in `bun test --preload` tests 2023-04-05Disable buffering when we clear terminalGravatar Jarred Sumner 1-0/+2 hopefully fixes an issue reported in Discord 2023-04-05PrettierGravatar Jarred Sumner 3-4/+4 2023-04-05fix(fetch.proxy) fix proxy authentication (#2554)Gravatar Ciro Spaciari 3-31/+186 * fix proxy authentication * add auth tests * remove unused 2023-04-05fix: build warnings (#2562)Gravatar hiroki osame 4-4/+1 2023-04-05In Documentation, move --watch before the script name (#2569)Gravatar Lawlzer 1-4/+5 Related message by Jarred: https://discord.com/channels/876711213126520882/876711213126520885/1093286199369682944 If you put `--watch` after the script name, it will not work. 2023-04-05fix `deepEquals` with array holes and accessors (#2557)Gravatar Dylan Conway 2-10/+249 * `deepEqual` handles slow array indexes * another test * oops * remove bad test * compare indexes in non-strict mode * more tests 2023-04-05fix: modules to have null prototype (#2561)Gravatar hiroki osame 2-2/+9 2023-04-04:clock1: :clock2: :clock3:Gravatar Jarred Sumner 1-1/+1 2023-04-04Implement `import.meta.main` (#2556)Gravatar Jarred Sumner 10-8/+89 * Implement `import.meta.main` * Update main-test-1.js * Update fs.test.ts --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-04-04Dylan/fix some failing tests (#2544)Gravatar Jarred Sumner 10-29/+72 * handle `umask()` invalid arguments * move `bktree-fast` to test root, fix postinstall * fix fs test * could be baseline * handle different timezones * accidentally deleted tests * fix hang in `AbortSignal.timeout` * bring abort tests back * Revert "bring abort tests back" This reverts commit 0ff2ad5bf408694ac719b8ba0a38b16070e10201. * bunx node-gyp * bun x * fix typecheck * test * Update inspect.test.js --------- Co-authored-by: Dylan Conway <dylan.conway567@gmail.com> 2023-04-04Add npm benchmark (#2555)Gravatar Colin McDonnell 13-1/+271 * Add install bench * Update scripts and readme * remove lockfiles * Format bench * Add dev instructions 2023-04-03Use absolute paths morebun-v0.5.9Gravatar Jarred Sumner 2-6/+11 2023-04-03Fix test failureGravatar Jarred Sumner 1-15/+18