Giter VIP home page Giter VIP logo

rusty-dos's Introduction

Rusty DOS

A Rust skeleton for an MS-DOS program for IBM compatibles and the PC-98, including some PC-98-specific functionality. It requires at least a 386, as this is LLVM's minimum supported x86 target. Right now it's in real mode (albeit wastefully using 32-bit near pointers that still only have a 64 KiB range). My plan is currently to start using unreal mode if possible, which might allow the requirements to be lowered to a 286 in the future, if compiler support gets there. I had considered switching it to use protected mode and DJGPP, but unreal mode has a sort of charm to it as a weird hack, as well as being closer to real mode for that classic, bare-metal feel.

Unicode

Strings are all Unicode-enabled, encoded using UTF-8, just as they usually are in Rust. When writing strings, they get converted to codepage 437 at the last minute, but this does not require any allocation as it done character-by-character instead of converting the whole string. This unfortunately means that any decomposed representation will not work, but to be honest, everyone uses the precomposed versions of all of the characters in codepage 437 anyway.

The advantage of this approach is that it means that using your existing Rust code should be seamless. There is no need to work with byte strings instead. ASCII strings should be really fast, while the additional characters available in codepage 437 require only a small table lookup which is practically instanteous on a 386. Unsupported characters will show up as tofu instead of mojibake, which I find more user-friendly.

Building

Thanks to the build-std feature, you should only need a vanilla Rust toolchain now. I build it like this, but you can tune it for your needs.

RUSTFLAGS="-C opt-level=z" cargo build --release --target dos.json

It seems that this won't build properly with MSVC's linker. Using GCC instead should fix this.

rusty-dos's People

Contributors

coltonoscopy avatar geriatricjacob avatar rzumer avatar serentty avatar stuaxo avatar teknoman117 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rusty-dos's Issues

Compilation error on macOS 12.6.3 (clang-1400.0.29.202)

I entirely expect this is because I'm not using actual gcc but I hit link-time errors when building at the moment:

WARN rustc_codegen_ssa::back::link Linker does not support -no-pie command line option. Retrying without.
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/Users/me/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/me/.cargo/bin:/opt/homebrew/opt/openjdk/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion Tech Preview.app/Contents/Public" VSLANG="1033" "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-Wl,--gc-sections" "-m16" "-nostdlib" "-march=i386" "-ffreestanding" "-fno-pie" "-Tcom.ld" "/var/folders/db/k7txrdsj4cl_p_bf5_5gz9c00000gn/T/rustceH6GoE/symbols.o" "/Users/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/dos-094b9fa3f51d414f.dos.49079d62-cgu.0.rcgu.o" "/Users/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/dos-094b9fa3f51d414f.dos.49079d62-cgu.1.rcgu.o" "/Users/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/dos-094b9fa3f51d414f.dos.49079d62-cgu.2.rcgu.o" "/Users/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/dos-094b9fa3f51d414f.dos.49079d62-cgu.3.rcgu.o" "/Users/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/dos-094b9fa3f51d414f.dos.49079d62-cgu.4.rcgu.o" "/Users/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/dos-094b9fa3f51d414f.dos.49079d62-cgu.5.rcgu.o" "/Users/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/dos-094b9fa3f51d414f.dos.49079d62-cgu.6.rcgu.o" "-Wl,--as-needed" "-L" "/Users/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps" "-L" "/Users/me/Documents/Code/rust/other/rusty-dos/target/release/deps" "-L" "/Users/me/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/dos/lib" "-Wl,-Bstatic" "/Users/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/libstatic_assertions-7b3a22f385d712a5.rlib" "/Users/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/libbitflags-df4d6f15de3bffa7.rlib" "/Users/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/librustc_std_workspace_core-72e6f8c8fd97affe.rlib" "/Users/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/libcore-9701ff8d25450f25.rlib" "/Users/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/libcompiler_builtins-1f1e3cf246152175.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/Users/me/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/dos/lib" "-o" "/Users/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/dos-094b9fa3f51d414f.com" "-Wl,--gc-sections" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: ld: warning: directory not found for option '-L/Users/me/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/dos/lib'
          ld: warning: directory not found for option '-L/Users/me/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/dos/lib'
          ld: unknown option: --as-needed
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
          

warning: `dos` (bin "dos") generated 14 warnings
error: could not compile `dos` (bin "dos") due to previous error; 14 warnings emitted
MyMachin:rusty-dos me$ cc --version
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Compilation error on Ubuntu 22.10 (gcc 12.2.0)

Hmm. Not much luck at all today. GCC on Ubuntu 22.10 may have dropped support for 16bit binaries:

error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/me/.rustup/toolchains/nightly-aarch64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/bin:/home/me/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" VSLANG="1033" "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-Wl,--gc-sections" "-m16" "-nostdlib" "-march=i386" "-ffreestanding" "-fno-pie" "-Tcom.ld" "/tmp/rustclAL3QR/symbols.o" "/home/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/dos-455e65f67464e693.dos.5a5b3b06-cgu.0.rcgu.o" "/home/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/dos-455e65f67464e693.dos.5a5b3b06-cgu.1.rcgu.o" "/home/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/dos-455e65f67464e693.dos.5a5b3b06-cgu.2.rcgu.o" "/home/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/dos-455e65f67464e693.dos.5a5b3b06-cgu.3.rcgu.o" "/home/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/dos-455e65f67464e693.dos.5a5b3b06-cgu.4.rcgu.o" "/home/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/dos-455e65f67464e693.dos.5a5b3b06-cgu.5.rcgu.o" "/home/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/dos-455e65f67464e693.dos.5a5b3b06-cgu.6.rcgu.o" "-Wl,--as-needed" "-L" "/home/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps" "-L" "/home/me/Documents/Code/rust/other/rusty-dos/target/release/deps" "-L" "/home/me/.rustup/toolchains/nightly-aarch64-unknown-linux-gnu/lib/rustlib/dos/lib" "-Wl,-Bstatic" "/home/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/libstatic_assertions-609e5ed2fb2e7024.rlib" "/home/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/libbitflags-c5fa9dcb2204815e.rlib" "/home/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/librustc_std_workspace_core-39ea25ee3b450edd.rlib" "/home/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/libcore-e6792bc159198733.rlib" "/home/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/libcompiler_builtins-01f05df35140a5a9.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/me/.rustup/toolchains/nightly-aarch64-unknown-linux-gnu/lib/rustlib/dos/lib" "-o" "/home/me/Documents/Code/rust/other/rusty-dos/target/dos/release/deps/dos-455e65f67464e693.com" "-Wl,--gc-sections" "-no-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: cc: error: unrecognized command-line option '-m16'


$ cc --version
cc (Ubuntu 12.2.0-3ubuntu1) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I'm not sure it'll matter but this is an ARM64-based VM.

$ uname -a
Linux ubuntu-arm 5.19.0-38-generic #39-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 17 17:36:31 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux

Exiting due to signal SIGSEGV

C:\> gcc 
Exiting due to signal SIGSEGV
Page fault at eip=00041381, error=0004
eax=00000000 ebx=0016bba0 ecx=00000001 edx=00000000 esi=001f22b8 edi=0000b078
ebp=001f2298 esp=001f20d0 program=C:\DEVEL\DJGPP\BIN\GCC.EXE
cs: sel=00a7  base=00400000  limit=001fffff
ds: sel=00af   base=00400000  limit=001fffff
es: sel=00af   base=00400000  limit=001fffff
fs: sel=008f   base=000034f0  limit=0000ffff
gs: sel=00bf  base=00000000  limit=0010ffff
ss: sel=00af  base=00400000  limit=001ffffff
App stack: [001f2394..00172394]  Exceptn stack: [00171d9c..0016fe5c]

Call frame traceback EIPs:
  0x00041381
  0x0004080a
  0x0014b108

My os: FreeDOS 1.3-rc4,
i have got the package from FreeDOS 1.3 bonus image with additional software and installed using fdimples FreeDOS package manager.

djgpp ?

djgpp has been packaged for Linux https://launchpad.net/~stsp-0/+archive/ubuntu/djgpp/+packages could that help, or is the aim just to have 16 bit code ?

I'm pretty fuzzy on how this works (though managed to compile the example and run in dosbox).

I read your post -
https://www.reddit.com/r/rust/comments/ask2v5/dos_the_final_frontier/

As I'm new to rust, I'm pretty fuzzy on how this works, and where to extend things to play with this..

BlogOS has some VGA text mode routines, which looks like an interesting place to start playing with, though at the moment, not even sure how to build another file apart from dos.com

What about Unreal Mode?

Have you thought of using the latest and greatest in pure DOS programming, i.e. unreal mode which lets you access the whole range of memory from real mode, as a flat address space?

The main drawback is that the resulting binary will not be compatible with exotic shells and OSes like MS Windows or OS/2 Warp, but seriously, who cares about them?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.