GistTree.Com
Entertainment at it's peak. The news is by your side.

SCC – Small C Compiler for DOS

0

Introduction

SCC is a restricted C compiler producing diminutive-mannequin (i.e. single section) DOS COM files. It’ll aloof bustle on most operating programs and can self-host below DOS2.0+ love minded programs (e.g. SDOS) with 128Okay RAM (the compiler ideal uses 64Okay, but the operating system desires to live as neatly :)).

Furthermore integrated are a small spot of supporting software parts:

  • SCPP – Pre-processor
  • SAS – Assembler that may maybe maybe bootstrap SDOS/SASM
  • SIM86 – Classic x86 simulator (Smartly abundant adequate to simulate the ecosystem)

Constructing

Assemble scc.c utilizing a C99 compiler and bustle the output on scc.c, this produces scc.com which can then be bustle below DOS (utilizing e.g. DOSBox or the supplied simulator) the establish it’ll self-compile: scc.com scc.c. These steps can then be repeated for the remainig software parts.

Or utilizing CMake:

mkdir produce && cd produce && cmake -DMAKE_DISKS:BOOL=TRUE .. && cmake --produce .

That you just may maybe also inch over -DMAKE_DISKS:BOOL=TRUE in the occasion you manufacture now not prefer the disk photos constructed.

Working the take a look at suite (will use DOSBox if available in the market):

cmake --produce . --design take a look at

If constructing the disk photos is enabled and QEMU became stumbled on, that you may produce the qemu_test design to birth QEMU with the tall disk image linked. Use the CMake variable QEMU_EXTRA_ARGS to inch in additional arguments to QMEU.

Trying

SCC in action

Download a birth or produce the software your self (look above).

I imply utilizing some of the disk photos:

  • small.img is a 360Okay disk image containing the naked minimum. It be appropriate for use with genuinely primitive machines.
  • tall.img is a 1440Okay disk image. You will are looking out out for to utilize this in the occasion that you may.

Fireplace up an emulator (or the notify thing in the occasion you’re lucky) e.g. PCem, QEMU or the resplendent online PCjs.

For instance that you may use the IBM PC (Mannequin 5150), 256Kb RAM, Shade Show off.

  1. Press the “Browse…” button and steal the small disk image.
  2. Press “Mount” after which “Ctrl-Alt-Del”
  3. (Optional) At the SDOS instructed (# ) form produce and press enter to provide the integrated software. Wait a short time for the software to provide (Or press the 4.77MHz button about a times to trail it up).
  4. Use uvi (a diminutive vi clone) to edit source code, scpp to pre-route of, scc to compile, debug to debug and sim86 to simulate.

Take into fable the classic hi there world tailored to SCC:

// hi there.c
#encompass "lib.h"
void fundamental() {
  locations("Hiya world! From DOS!");
}

To provide and bustle (manufacture now not genuinely form the feedback):

uvi hi there.c       # Edit (press "i" to enter insert mode and press compile away to exit it. ":wq" to jot down & stop)
scpp hi there.c      # Pre-route of to create hi there.i
scc hi there.i       # Assemble
hi there.com         # Lumber

Or on your popular system:

current-editor hi there.c && scpp hi there.c && scc hi there.i && sim86 hi there.com

Some notes:

  • To your host system, that you may use sim86 -p hi there.com to compile general efficiency files (most continuously the choice of memory accesses performed)
  • lib.h comprises an especially naked-bones popular library and birth-up code that calls fundamental. On non-SCC platforms it involves the corresponding headers as one more, allowing the equivalent code to compile unmodified on quite about a programs.
  • You will maybe are looking out out for to function a batch file with these steps in the occasion you intend on operating them bigger than once.
  • Whilst you occur to’re doing the leisure remotely purposeful, which that you may maybe maybe are looking out out for to ditch the pre-processing step and produce your maintain popular library.

A more sensible hi there world example would be:

void PutChar(int ch) {
    _emit 0xB4 _emit 0x02            // MOV AH, 2
    _emit 0x8A _emit 0x56 _emit 0x04 // MOV DL, [BP+4]
    _emit 0xCD _emit 0x21            // INT 0x21
}

void _start() {
    const chars = "Hiya DOS!rn";
    whereas (*s) PutChar(*s++);
}

Which may maintain to aloof come up with a (imprecise) thought of overcome the boundaries of SCC (that you may look more examples in lib.h and sim86.c by browsing for _emit).

Q&A

Why would I need this?

You maybe manufacture now not. Whilst you occur to’re genuinely taking a inquire to compile C code for DOS gaze into DJGPP or OpenWatcom.
This is appropriate a ardour mission to function a compiler for one other NIH mission of mine: SDOS/SASM.

Why is the particular person experience so abominable?

Smartly abundant UX uses precious bytes. Sorry 🙁

Why now not toughen quite about a memory fashions?

I wanted to preserve it easy and now not wish to count too worthy on inline “assembly” (learn: _emit statements) magic.
Out of necessity SIM86 has to utilize bigger than 64Okay, so there could be a transparent course to allowing elevated output files, but for now I opt the mission of conserving the memory usage down 🙂

What are some equivalent projects?

Limitations

A non-exhaustive checklist of primarily the most recent boundaries of SCC:

  • Arbitrary limits to e.g. the choice of struct members (that you may to about a stage exchange these)
  • Very restricted error checking/files (look the debugging half for encourage)
  • Integers are restricted to 16-bits (and no toughen for lengthy)
  • Tiny memory mannequin (i.e. all code and knowledge should always live inner a single 64Okay section). CS=DS=ES=SS is assumed. (Salvage out about SIM86 for an example of work round this limitation)
  • Handiest general toughen for initializers (principles are complex, but if it be now not in the take a look at suite it be now not supported…)
  • No floating point toughen
  • No bitfields
  • Uncountably many bugs 🙂

Debugging

First manufacture sure the source code (to the ideal stage that you may imagine) compiles and works with one other C compiler.
SCC assumes the source code works and ideal does a naked minimum of checking. Many invalid C applications are current and quite a bit of suited C applications are rejected (or miscompiled!).

Are trying simplifying the code. SCC is now not artful yet.

Use the simulator (SIM86) – on your host system -p also offers a convinient disassembly of all reached instructions.

Replace the code of the simulator to debug tough concerns!

Stack traces

Some errors will doubtless be reported as a stack worth (look below). For these cases which that you may maybe should always consult the procedure file produced as neatly as to the com file (i.e. scc.procedure for scc.com).

Example:

BP   Return contend with
FFBE 07A5
FFC8 4844
FFD6 48E4
FFDA 4920
FFDE 51FE
FFE8 5892
FFFC 03D5
In line 48: Test failed

Consulting the procedure file for the closest (now not larger than) image:

07A5 # 0786 Fail
4844 # 4666 ParseDeclarator
48E4 # 48D5 DoDecl
4920 # 4908 ParseFirstDecl
51FE # 51F8 ParseExternalDefition
5892 # 55F3 fundamental
03D5 # 03A2 _start

Assemble errors

Show off that:

  • The reported line number is previous primarily the most recent token (meaning quite a bit of whitespace/feedback may maybe maybe were skipped).
  • If the pre-processor became feeble it be a should always to manually reverse engineer the notify line from the pre-processed file (since that is the establish the toll road number points)
  • Working SCC on your host system may maybe maybe provide a line number to gaze up in scc.c for take a look at screw ups.

Whilst you occur to can reproduce the procedure back on your host system which that you may maybe maintain to aloof use a debugger linked to scc to compile a blueprint of the establish and why the hiss occurs.

Totally different concerns

Whilst you occur to suspect a compiler computer virus, which that you may maybe maybe wish to isolate the hiss and gaze manually inquire the generated code.

Technical Notes

Moreover some minor exceptions SCC is a single inch compiler. It tries genuinely tough to ideal have confidence primarily the most recent character/token/(sub-)expression to withhold memory.
An AST is now not constructed, rather code is outputted in an instant in step with expressions and statements.

Inner these constraints SCC tries to generate a small of optimized code. Many that you may imagine optimizations are now not performed on fable of they manufacture now not pay off (meaning they manufacture now not optimize SCC itself either in time or size).

There are some minor optimizations executed whereas doing contend with fixups to atone for the restricted optimizations. These are the ideal backward taking a inquire optimizations.

More to attain encourage… (per chance).

Read More

Leave A Reply

Your email address will not be published.