C--

From OSDev.wiki
Jump to navigation Jump to search

C--

(This page is about Sphinx Full C--, not about C--, the portable assembly language

Sphinx Full C-- language is in between the C language and x86-assembly. It is a very neat computer language and the Shinx Full C-- compiler allows to produce (and mix) 16 bit and 32 bit code for real and protected modes.

Pros

  • good for writing real mode x86 operating systems;
  • good for writing TSR programs for DOS
  • good for writing x86-related parts of an operating system in a structured and easily readable and easier debuggable way related to structured languages like C and Pascal;
  • the code can be either low level (assembly-like), medium level (C like) or very easily mixed;
  • very good (because of the structured form) for writing small toy programs which are close to the hardware;
  • relatively easy to port from and to C-with-assembly.


Cons

  • not portable; it is very closely tied to the x86 assembly;
  • is developed by few developers, the community is small;
  • one compiler implementation availlable and only for one platform (DOS);
  • larger projects generally should be written in high-level languages, not low-level like Sphinx Full C--;
  • can be used for x86-related parts of an operating system, but doesn't give as much control as assembly and requires to have both C (or C++) and C-- compilers;

I am not sure on the output formats of the compiler but I fear it provides only flat-binary and dos exes. I don't know if it can output 64bit code.

Early versions of panaLiX used Sphinx Full C--.

Examples

?include "nosys.inc"
dword old0x21 = {};
interrupt int0x21()
{
    $PUSH DS
    $PUSH ES
    $PUSHA
    $PUSH FS
    //
    DS = CS;
    FS = 0xb800;
    FSBYTE[1682] = '!';
    //
    $POP FS
    $POPA
    $POP ES
    $POP DS
}
...
int registerInterrupt0x21()
{
    FS = 0;
    old0x21 = FSDWORD[0x21 * 4];
    FSWORD[0x21 * 4] = #int0x21;
    FSWORD[0x21 * 4 + 2] = CS;
    Log(3, "0x21 registered", 0);
}
    ESBYTE[0x1b8003]= 'z';
    //
    $ CLI
    kb_cmd(0xad);
    kb_cmd(0xd0);
    kb_read();
    tepx=AL;
    kb_cmd(0xd1);
    $ MOV AL, tepx
    $ OR AL, 2
    $ MOV tepx, AL
    kb_write(tepx);
    kb_cmd(0xae);
    $ STI
    //
    ESBYTE[0x1b8005]= 127;

These snippets may seem a bit spaghetti code, but not because of some language defficiency but because I didn't look very far for them snippets.

References