From a63c252c7aa24afc8f4f663e74d16a67c4c2f3a4 Mon Sep 17 00:00:00 2001 From: able Date: Mon, 26 Jun 2023 05:18:14 -0500 Subject: [PATCH] HBASM: no_std compatible now --- Cargo.lock | 21 +++++++++++++++++++-- hbasm/Cargo.toml | 5 +++-- hbasm/assets/serial_driver.hbasm | 11 +++++++++++ hbasm/src/lib.rs | 15 +++++++++++---- rust-toolchain | 2 +- 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6ab71b07..d1373f7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,6 +13,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "allocator-api2" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56fc6cf8dc8c4158eed8649f9b8b0ea1518eb62b544fe9490d66fa0b349eafe9" + [[package]] name = "beef" version = "0.5.2" @@ -70,10 +76,21 @@ dependencies = [ "ahash", ] +[[package]] +name = "hashbrown" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +dependencies = [ + "ahash", + "allocator-api2", +] + [[package]] name = "hbasm" version = "0.1.0" dependencies = [ + "hashbrown 0.14.0", "hbbytecode", "lasso", "logos", @@ -90,7 +107,7 @@ version = "0.1.0" dependencies = [ "delegate", "derive_more", - "hashbrown", + "hashbrown 0.13.2", "hbbytecode", "log", "paste", @@ -103,7 +120,7 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4644821e1c3d7a560fe13d842d13f587c07348a1a05d3a797152d41c90c56df2" dependencies = [ - "hashbrown", + "hashbrown 0.13.2", ] [[package]] diff --git a/hbasm/Cargo.toml b/hbasm/Cargo.toml index 1ab3f41f..ff364ad7 100644 --- a/hbasm/Cargo.toml +++ b/hbasm/Cargo.toml @@ -5,8 +5,9 @@ edition = "2021" [dependencies] hbbytecode = { path = "../hbbytecode" } -lasso = "0.7" -paste = "1.0" +lasso = "0.7" +paste = "1.0" +hashbrown = "0.14.0" [dependencies.logos] version = "0.13" diff --git a/hbasm/assets/serial_driver.hbasm b/hbasm/assets/serial_driver.hbasm index 306bbf7a..13bcb3a1 100644 --- a/hbasm/assets/serial_driver.hbasm +++ b/hbasm/assets/serial_driver.hbasm @@ -5,3 +5,14 @@ start: -- Uses r20 to set the port init_serial_port: add r20, r30, r10 + li r20, 00 + + -- outb(PORT + 1, 0x00); // Disable all interrupts + -- outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor) + -- outb(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud + -- outb(PORT + 1, 0x00); // (hi byte) + -- outb(PORT + 3, 0x03); // 8 bits, no parity, one stop bit + -- outb(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold + -- outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set + -- outb(PORT + 4, 0x1E); // Set in loopback mode, test the serial chip + -- outb(PORT + 0, 0xAE); // Test serial chip (send byte 0xAE and check if serial returns same byte) \ No newline at end of file diff --git a/hbasm/src/lib.rs b/hbasm/src/lib.rs index 3313693e..121927a8 100644 --- a/hbasm/src/lib.rs +++ b/hbasm/src/lib.rs @@ -1,8 +1,15 @@ -use std::collections::HashMap; +#![no_std] +#![feature(error_in_core)] + +// use std::collections::HashMap; +extern crate alloc; +use alloc::vec::Vec; + use { + core::fmt::{Display, Formatter}, + hashbrown::HashMap, lasso::{Rodeo, Spur}, logos::{Lexer, Logos, Span}, - std::fmt::{Display, Formatter}, }; macro_rules! tokendef { @@ -73,12 +80,12 @@ pub struct Error { } impl Display for Error { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { write!(f, "Error {:?} at {:?}", self.kind, self.span) } } -impl std::error::Error for Error {} +impl core::error::Error for Error {} macro_rules! expect_matches { ($self:expr, $($pat:pat),* $(,)?) => {$( diff --git a/rust-toolchain b/rust-toolchain index 870bbe4e..07ade694 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -stable \ No newline at end of file +nightly \ No newline at end of file