Skip to content

arceos-org/exercise-printcolor

Repository files navigation

arceos-printcolor

A standalone colored-print exercise for ArceOS: a minimal unikernel with dependencies from crates.io, multi-architecture builds and QEMU runs via cargo xtask.

This repository is the exercise.

Supported Architectures

Architecture Rust Target QEMU Machine Platform
riscv64 riscv64gc-unknown-none-elf qemu-system-riscv64 -machine virt riscv64-qemu-virt
aarch64 aarch64-unknown-none-softfloat qemu-system-aarch64 -machine virt aarch64-qemu-virt
x86_64 x86_64-unknown-none qemu-system-x86_64 -machine q35 x86-pc
loongarch64 loongarch64-unknown-none qemu-system-loongarch64 -machine virt loongarch64-qemu-virt

Prerequisites

  • Rust nightly toolchain (edition 2024)

    rustup install nightly
    rustup default nightly
  • Bare-metal targets (install the ones you need)

    rustup target add riscv64gc-unknown-none-elf
    rustup target add aarch64-unknown-none-softfloat
    rustup target add x86_64-unknown-none
    rustup target add loongarch64-unknown-none
  • QEMU (install the emulators for your target architectures)

    # Ubuntu/Debian
    sudo apt install qemu-system-riscv64 qemu-system-aarch64 \
                     qemu-system-x86 qemu-system-loongarch64  # OR qemu-systrem-misc
    
    # macOS (Homebrew)
    brew install qemu
  • rust-objcopy (from cargo-binutils, required for non-x86_64 targets)

    cargo install cargo-binutils
    rustup component add llvm-tools

Quick Start

Get Source Code

Method 1: Get source code from crates.io

# install cargo-clone sub-command
cargo install cargo-clone 
# get source code of arceos-printcolor crate from crates.io
cargo clone arceos-printcolor
# into crate dir
cd arceos-printcolor

Method 2: Clone the tg-arceos-tutorial repository

git clone https://github.com/arceos-org/tg-arceos-tutorial.git
cd tg-arceos-tutorial/exercise-printcolor

Build & Run

# Build and run on RISC-V 64 QEMU (default)
cargo xtask run

# Build and run on other architectures
cargo xtask run --arch aarch64
cargo xtask run --arch x86_64
cargo xtask run --arch loongarch64

# Build only (no QEMU)
cargo xtask build --arch riscv64
cargo xtask build --arch aarch64

Exercise

Expectation

The output of the string "Hello, Arceos!" shall be displayed with color. (No specific color requirements are imposed.)

Verification

  • The serial output must contain Hello, Arceos!.
  • Coloring must show up as ANSI SGR sequences (e.g. \x1b[32m, \x1b[1;31m).

Run the test script:

bash scripts/test.sh

Tips

Changes at different layers of ArceOS affect different parts of the output: editing axstd mostly affects println!; editing axhal can also change startup banner styling.

To hack on ArceOS crates locally, clone the crate and switch the dependency in Cargo.toml from a version requirement to path:

cargo clone axstd@0.3.0-preview.1
[dependencies]
axstd = { path = "./axstd", features = ["defplat"], optional = true }

(Adjust the path to match where you put the sources.)

Project Structure

exercise-printcolor/
├── .cargo/
│   └── config.toml       # cargo xtask alias
├── configs/
│   ├── riscv64.toml
│   ├── aarch64.toml
│   ├── x86_64.toml
│   └── loongarch64.toml
├── scripts/
│   └── test.sh           # Multi-arch output + ANSI color checks
├── src/
│   └── main.rs           # Application entry point
├── xtask/
│   └── src/
│       └── main.rs       # build/run and QEMU wiring
├── build.rs              # Linker script path (arch auto-detect)
├── Cargo.toml            # Package arceos-printcolor, axstd, etc.
├── rust-toolchain.toml   # Nightly, targets, llvm-tools
└── README.md

Key Components

Component Role
axstd ArceOS standard library (replaces Rust's std in no_std environment)
axhal Hardware abstraction layer, generates the linker script at build time
build.rs Locates the linker script generated by axhal and passes it to the linker
configs/*.toml Pre-generated platform configuration for each architecture

License

GPL-3.0

About

A simple printcolor exercise for ArceOS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors