diff --git a/README.md b/README.md index a7b24a4f7..b484c28fd 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ see the [SDK section of the book](https://op-rs.github.io/kona/sdk/intro.html). **Build Pipelines** -- [`cannon`](./build/cannon): Docker image for compiling to the bare-metal `mips-unknown-none` target. +- [`cannon`](./build/cannon): Docker image for compiling to the bare-metal `mips64-unknown-none` target. - [`asterisc`](./build/asterisc): Docker image for compiling to the bare-metal `riscv64imac-unknown-none-elf` target. **Protocol** diff --git a/bin/client/src/kona.rs b/bin/client/src/kona.rs index 2e91cd30e..a3189ff73 100644 --- a/bin/client/src/kona.rs +++ b/bin/client/src/kona.rs @@ -3,7 +3,7 @@ #![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![no_std] -#![cfg_attr(any(target_arch = "mips", target_arch = "riscv64"), no_main)] +#![cfg_attr(any(target_arch = "mips64", target_arch = "riscv64"), no_main)] extern crate alloc; diff --git a/bin/client/src/kona_interop.rs b/bin/client/src/kona_interop.rs index a0b33e0e1..34f89d592 100644 --- a/bin/client/src/kona_interop.rs +++ b/bin/client/src/kona_interop.rs @@ -3,7 +3,7 @@ #![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![no_std] -#![cfg_attr(any(target_arch = "mips", target_arch = "riscv64"), no_main)] +#![cfg_attr(any(target_arch = "mips64", target_arch = "riscv64"), no_main)] extern crate alloc; diff --git a/book/src/fpp-dev/targets.md b/book/src/fpp-dev/targets.md index f1237a35d..eb44f4f7b 100644 --- a/book/src/fpp-dev/targets.md +++ b/book/src/fpp-dev/targets.md @@ -35,9 +35,9 @@ programs to directly invoke a select few syscalls: [asterisc-syscalls]: https://github.com/ethereum-optimism/asterisc/blob/master/docs/golang.md#linux-syscalls-used-by-go -## Cannon (MIPS32r2) +## Cannon (MIPS64r2) -Cannon is based off of the `mips32r2` target architecture, specified in [_MIPS32™ Architecture For Programmers Volume III: The MIPS32™ Privileged Resource Architecture_](https://www.cs.cornell.edu/courses/cs3410/2013sp/MIPS_Vol3.pdf) +Cannon is based off of the `mips64r2` target architecture, specified in [MIPS® Architecture For Programmers Volume II-A: The MIPS64® Instruction Set Reference Manual](https://s3-eu-west-1.amazonaws.com/downloads-mips/documents/MIPS_Architecture_MIPS64_InstructionSet_%20AFP_P_MD00087_06.05.pdf) ### Syscalls diff --git a/book/src/intro.md b/book/src/intro.md index a2ebecc9e..3bbc191cc 100644 --- a/book/src/intro.md +++ b/book/src/intro.md @@ -40,7 +40,7 @@ experience by standardizing and streamlining the process of developing and compi **4. Performance** Kona is opinionated in that it favors `no_std` Rust programs for embedded FPVM development, for both performance and portability. In contrast with alternative approaches, such -as the [`op-program`][op-program] using the Golang `MIPS32` target, `no_std` Rust programs produce much smaller binaries, resulting in fewer instructions +as the [`op-program`][op-program] using the Golang `MIPS64` target, `no_std` Rust programs produce much smaller binaries, resulting in fewer instructions that need to be executed on the FPVM. In addition, this offers developers more low-level control over interactions with the FPVM kernel, which can be useful for optimizing performance-critical code. diff --git a/build/cannon/cannon.dockerfile b/build/cannon/cannon.dockerfile index 703e86dbd..b504a8206 100644 --- a/build/cannon/cannon.dockerfile +++ b/build/cannon/cannon.dockerfile @@ -1,41 +1,36 @@ -# This image and the `mips-unknown-none` target were derived from `BadBoiLabs`'s -# `cannon-rs` project. -# -# https://github.com/BadBoiLabs/Cannon-rs - FROM --platform=linux/amd64 ubuntu:22.04 ENV SHELL=/bin/bash -ENV DEBIAN_FRONTEND noninteractive +ENV DEBIAN_FRONTEND=noninteractive # todo: pin `nightly` version -ENV RUST_VERSION nightly +ENV RUST_VERSION=nightly RUN apt-get update && apt-get install --assume-yes --no-install-recommends \ ca-certificates \ build-essential \ curl \ - g++-mips-linux-gnu \ - libc6-dev-mips-cross \ - binutils-mips-linux-gnu \ + g++-mips64-linux-gnuabi64 \ + libc6-dev-mips64-cross \ + binutils-mips64-linux-gnuabi64 \ llvm \ clang \ make \ cmake \ - git + git # Install Rustup and Rust RUN curl https://sh.rustup.rs -sSf | bash -s -- -y --default-toolchain ${RUST_VERSION} --component rust-src ENV PATH="/root/.cargo/bin:${PATH}" # Add the special cannon build target -COPY ./mips-unknown-none.json . +COPY ./mips64-unknown-none.json . # Set up the env vars to instruct rustc to use the correct compiler and linker # and to build correctly to support the Cannon processor -ENV CC_mips_unknown_none=mips-linux-gnu-gcc \ - CXX_mips_unknown_none=mips-linux-gnu-g++ \ - CARGO_TARGET_MIPS_UNKNOWN_NONE_LINKER=mips-linux-gnu-gcc \ - RUSTFLAGS="-Clink-arg=-e_start -C llvm-args=-mno-check-zero-division" \ - CARGO_BUILD_TARGET="/mips-unknown-none.json" \ +ENV CC_mips64_unknown_none=mips64-linux-gnuabi64-gcc \ + CXX_mips64_unknown_none=mips64-linux-gnuabi64-g++ \ + CARGO_TARGET_MIPS64_UNKNOWN_NONE_LINKER=mips64-linux-gnuabi64-gcc \ + RUSTFLAGS="-Clink-arg=-e_start -Cllvm-args=-mno-check-zero-division" \ + CARGO_BUILD_TARGET="/mips64-unknown-none.json" \ RUSTUP_TOOLCHAIN=${RUST_VERSION} diff --git a/build/cannon/mips-unknown-none.json b/build/cannon/mips64-unknown-none.json similarity index 51% rename from build/cannon/mips-unknown-none.json rename to build/cannon/mips64-unknown-none.json index 9d0ce305e..40e3894e8 100644 --- a/build/cannon/mips-unknown-none.json +++ b/build/cannon/mips64-unknown-none.json @@ -1,14 +1,14 @@ { - "arch": "mips", - "cpu": "mips32", - "llvm-target": "mips-unknown-none", - "data-layout": "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64", + "arch": "mips64", + "cpu": "mips64", + "llvm-target": "mips64-unknown-none", + "data-layout": "E-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128", "target-endian": "big", - "target-pointer-width": "32", + "target-pointer-width": "64", "target-c-int-width": "32", "os": "none", - "features": "+soft-float,+mips32,-mips32r2", - "max-atomic-width": "0", + "features": "+soft-float,+mips64r2,+xgot,+noabicalls", + "max-atomic-width": "64", "linker": "rust-lld", "linker-flavor": "ld.lld", "executables": true, diff --git a/crates/proof-sdk/std-fpvm-proc/src/lib.rs b/crates/proof-sdk/std-fpvm-proc/src/lib.rs index dd13ad8e7..e115fa425 100644 --- a/crates/proof-sdk/std-fpvm-proc/src/lib.rs +++ b/crates/proof-sdk/std-fpvm-proc/src/lib.rs @@ -41,7 +41,7 @@ pub fn client_entry(attr: TokenStream, input: TokenStream) -> TokenStream { } cfg_if::cfg_if! { - if #[cfg(any(target_arch = "mips", target_arch = "riscv64"))] { + if #[cfg(any(target_arch = "mips64", target_arch = "riscv64"))] { const HEAP_SIZE: usize = #heap_size; #[doc = "Program entry point"] diff --git a/crates/proof-sdk/std-fpvm/src/io.rs b/crates/proof-sdk/std-fpvm/src/io.rs index d7301d9a9..79c93070a 100644 --- a/crates/proof-sdk/std-fpvm/src/io.rs +++ b/crates/proof-sdk/std-fpvm/src/io.rs @@ -4,9 +4,9 @@ use crate::{errors::IOResult, BasicKernelInterface, FileDescriptor}; use cfg_if::cfg_if; cfg_if! { - if #[cfg(target_arch = "mips")] { - #[doc = "Concrete implementation of the [BasicKernelInterface] trait for the `MIPS32rel1` target architecture."] - pub(crate) type ClientIO = crate::mips32::io::Mips32IO; + if #[cfg(target_arch = "mips64")] { + #[doc = "Concrete implementation of the [BasicKernelInterface] trait for the `MIPS64r2` target architecture."] + pub(crate) type ClientIO = crate::mips64::io::Mips64IO; } else if #[cfg(target_arch = "riscv64")] { #[doc = "Concrete implementation of the [BasicKernelInterface] trait for the `riscv64` target architecture."] pub(crate) type ClientIO = crate::riscv64::io::RiscV64IO; diff --git a/crates/proof-sdk/std-fpvm/src/lib.rs b/crates/proof-sdk/std-fpvm/src/lib.rs index 14482e862..2b0c793b9 100644 --- a/crates/proof-sdk/std-fpvm/src/lib.rs +++ b/crates/proof-sdk/std-fpvm/src/lib.rs @@ -4,8 +4,8 @@ html_favicon_url = "https://raw.githubusercontent.com/op-rs/kona/main/assets/favicon.ico" )] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -#![cfg_attr(target_arch = "mips", feature(asm_experimental_arch))] -#![cfg_attr(any(target_arch = "mips", target_arch = "riscv64"), no_std)] +#![cfg_attr(target_arch = "mips64", feature(asm_experimental_arch))] +#![cfg_attr(any(target_arch = "mips64", target_arch = "riscv64"), no_std)] extern crate alloc; @@ -29,8 +29,8 @@ pub use channel::FileChannel; pub(crate) mod linux; -#[cfg(target_arch = "mips")] -pub(crate) mod mips32; +#[cfg(target_arch = "mips64")] +pub(crate) mod mips64; #[cfg(target_arch = "riscv64")] pub(crate) mod riscv64; diff --git a/crates/proof-sdk/std-fpvm/src/malloc.rs b/crates/proof-sdk/std-fpvm/src/malloc.rs index 324d13d53..45a202b7a 100644 --- a/crates/proof-sdk/std-fpvm/src/malloc.rs +++ b/crates/proof-sdk/std-fpvm/src/malloc.rs @@ -5,7 +5,7 @@ //! well-known and widely used allocator software such as OS Kernels. /// The global allocator for the program in embedded environments. -#[cfg(any(target_arch = "mips", target_arch = "riscv64"))] +#[cfg(any(target_arch = "mips64", target_arch = "riscv64"))] pub mod global_allocator { use linked_list_allocator::LockedHeap; @@ -32,17 +32,17 @@ pub mod global_allocator { /// /// # Safety #[cfg_attr( - any(target_arch = "mips", target_arch = "riscv64"), + any(target_arch = "mips64", target_arch = "riscv64"), doc = "See [global_allocator::init_allocator] safety comment." )] #[cfg_attr( - not(any(target_arch = "mips", target_arch = "riscv64")), + not(any(target_arch = "mips64", target_arch = "riscv64")), doc = "This macro is entirely safe to invoke in non-MIPS and non-RISC-V64 profiles, and functions as a no-op." )] #[macro_export] macro_rules! alloc_heap { ($size:expr) => {{ - #[cfg(any(target_arch = "mips", target_arch = "riscv64"))] + #[cfg(any(target_arch = "mips64", target_arch = "riscv64"))] { use $crate::malloc::global_allocator::init_allocator; diff --git a/crates/proof-sdk/std-fpvm/src/mips32/io.rs b/crates/proof-sdk/std-fpvm/src/mips64/io.rs similarity index 85% rename from crates/proof-sdk/std-fpvm/src/mips32/io.rs rename to crates/proof-sdk/std-fpvm/src/mips64/io.rs index fc8f1beba..615f7525e 100644 --- a/crates/proof-sdk/std-fpvm/src/mips32/io.rs +++ b/crates/proof-sdk/std-fpvm/src/mips64/io.rs @@ -1,11 +1,11 @@ -use crate::{errors::IOResult, mips32::syscall, BasicKernelInterface, FileDescriptor}; +use crate::{errors::IOResult, mips64::syscall, BasicKernelInterface, FileDescriptor}; -/// Concrete implementation of the [BasicKernelInterface] trait for the `MIPS32rel1` target +/// Concrete implementation of the [BasicKernelInterface] trait for the `MIPS64r2` target /// architecture. Exposes a safe interface for performing IO operations within the kernel. #[derive(Debug)] -pub(crate) struct Mips32IO; +pub(crate) struct Mips64IO; -/// Relevant system call numbers for the `MIPS32rel1` target architecture. +/// Relevant system call numbers for the `MIPS64r2` target architecture. /// /// See [Cannon System Call Specification](https://specs.optimism.io/experimental/fault-proof/cannon-fault-proof-vm.html#syscalls) /// @@ -16,14 +16,14 @@ pub(crate) struct Mips32IO; #[repr(usize)] pub(crate) enum SyscallNumber { /// Sets the Exited and ExitCode states to true and $a0 respectively. - Exit = 4246, + Exit = 5205, /// Similar behavior as Linux/MIPS with support for unaligned reads. - Read = 4003, + Read = 5000, /// Similar behavior as Linux/MIPS with support for unaligned writes. - Write = 4004, + Write = 5001, } -impl BasicKernelInterface for Mips32IO { +impl BasicKernelInterface for Mips64IO { fn write(fd: FileDescriptor, buf: &[u8]) -> IOResult { unsafe { crate::linux::from_ret(syscall::syscall3( diff --git a/crates/proof-sdk/std-fpvm/src/mips32/mod.rs b/crates/proof-sdk/std-fpvm/src/mips64/mod.rs similarity index 72% rename from crates/proof-sdk/std-fpvm/src/mips32/mod.rs rename to crates/proof-sdk/std-fpvm/src/mips64/mod.rs index 012070c16..f4f2e06d2 100644 --- a/crates/proof-sdk/std-fpvm/src/mips32/mod.rs +++ b/crates/proof-sdk/std-fpvm/src/mips64/mod.rs @@ -1,4 +1,4 @@ -//! This module contains raw syscall bindings for the `MIPS32r2` target architecture, as well as a +//! This module contains raw syscall bindings for the `MIPS64r2` target architecture, as well as a //! high-level implementation of the [crate::BasicKernelInterface] trait for the `Cannon` kernel. pub(crate) mod io; diff --git a/crates/proof-sdk/std-fpvm/src/mips32/syscall.rs b/crates/proof-sdk/std-fpvm/src/mips64/syscall.rs similarity index 100% rename from crates/proof-sdk/std-fpvm/src/mips32/syscall.rs rename to crates/proof-sdk/std-fpvm/src/mips64/syscall.rs diff --git a/justfile b/justfile index 239408c04..bdafb5d08 100644 --- a/justfile +++ b/justfile @@ -72,7 +72,7 @@ lint-cannon: --platform linux/amd64 \ -v `pwd`/:/workdir \ -w="/workdir" \ - ghcr.io/op-rs/kona/cannon-builder:main cargo +nightly clippy -p kona-std-fpvm --all-features --target /mips-unknown-none.json -Zbuild-std=core,alloc -- -D warnings + ghcr.io/op-rs/kona/cannon-builder:main cargo +nightly clippy -p kona-std-fpvm --all-features -Zbuild-std=core,alloc -- -D warnings # Lint the workspace (risc-v arch). Currently, only the `kona-std-fpvm` crate is linted for the `asterisc` target, as it is the only crate with architecture-specific code. lint-asterisc: @@ -81,7 +81,7 @@ lint-asterisc: --platform linux/amd64 \ -v `pwd`/:/workdir \ -w="/workdir" \ - ghcr.io/op-rs/kona/asterisc-builder:main cargo +nightly clippy -p kona-std-fpvm --all-features --target riscv64imac-unknown-none-elf -Zbuild-std=core,alloc -- -D warnings + ghcr.io/op-rs/kona/asterisc-builder:main cargo +nightly clippy -p kona-std-fpvm --all-features -Zbuild-std=core,alloc -- -D warnings # Lint the Rust documentation lint-docs: