Example Sega Megadrive hello world written in Rust. This example is built on top of megadrive-sys.
Tested on rustc 1.99.0-nightly (87e5904f5 2026-07-20) and cargo 1.99.0-nightly (3efb1f477 2026-07-17).
- Install the m68k linker
m68k-linux-gnu-ldas described by the m68k target requirements (no need to install qemu). - Install Rust nightly:
rustup toolchain install nightly - Install Rust standard library source code
(needed to build
corefor m68k):rustup component add rust-src
The megadrive-sys dependency needs to be patched for m68k-unknown-none-elf. Run these
on the megahello folder:
git clone https://github.com/ricky26/rust-mega-drive.git
cd rust-mega-drive
git checkout c9353be # get the correct commit
git apply ../rust-mega-drive.patch
Build the Megadrive ROM. Note that this uses the .cargo/config.toml configuration parameters
and the link-megadrive.ld linker script to build the ROM.
cargo +nightly build --target m68k-unknown-none-elf --release
Convert the ELF file to a Megadrive binary ROM with the .bin file suffix:
m68k-linux-gnu-objcopy -O binary target/m68k-unknown-none-elf/release/megahello target/m68k-unknown-none-elf/release/megahello.bin
Note that the Rust 1.99 compiler has many bugs for m68k and LLVM has more bugs for m68k. It is very likely that the generated code is bad or the compiler crashes. Avoid building debug builds, always build release builds.
View the memory map:
cat target/Output.map
Dump the sections of the ELF file:
m68k-linux-gnu-objdump -x target/m68k-unknown-none-elf/release/megahello
Disassemble machine code instructions from the ELF file:
m68k-linux-gnu-objdump --disassemble --no-show-raw-ins --visualize-jumps -S target/m68k-unknown-none-elf/release/megahello
0BSD