It is possible to create a DOS executable or 1st stage bootloader with Rust.
This is a quick demo of creating COM executable for DOS.
You need a binutils and llvm-tools-preview.
cargo install cargo-binutils
rustup component add llvm-tools-previewThen you can build the project by running:
cargo build --releaseTo create a COM executable for DOS, run:
cargo objcopy --release -- -O binary --binary-architecture=i386:x86 rust_dos.comYou can copy rust_dos.com to your DOS image.
examples on Linux
$ sudo partx -av freedos.img
partition: none, disk: freedos.img, lower: 0, upper: 0
Trying to use '/dev/loop1' for the loop device
/dev/loop1: partition table type 'dos' detected
range recount: max partno=1, lower=0, upper=0
/dev/loop1: partition #1 added
$ sudo mount /dev/loop1p1 /mnt
$ sudo cp rust_dos.com /mnt/
$ sudo umount /mnt
$ sudo partx -dv /dev/loop1Then, you can test it using QEMU:
qemu-system-i386 freedos.img -boot cYou can use the println! macro.
Below is an example of HelloWorld:
First install DOSBox. Some examples if you like using package managers:
sudo apt install dosbox
brew install dosbox
choco install dosbox
Once installed, you can launch DOSBox and give it the path to your executable. For example, you can just give it the current working directory like the following:
dosbox .
And this will open DOSBox and have the "C:" drive be the current working directory. It's usually good to do this from another console so you don't have to close DOSBox every time you want to compile your application again.
dpkey module steals key input processing from DOS and converts scan code to ascii code.
about scan code: see PS/2 Keyboard - OSDev Wiki.

