WonderWitch/Process: Difference between revisions

From WSdev Wiki
Jump to navigationJump to search
(Created page with "== Memory layout == Process memory is stored in SRAM banks 3 (process 0 - typically used by FreyaOS), 2 (process 1) and 1 (process 2). The entire bank is available to the process. === Process control block === The process control block contains information about the running process. It is stored in the first 96 bytes of data. {| class="wikitable" |+ Process control block structure |- ! Offset !! Length !! Contents |- | 0 || 4 || Compiler ID, zero-terminated string; s...")
 
 
(One intermediate revision by the same user not shown)
Line 50: Line 50:
| <code>DMC</code> || Digital Mars C || WonderWitch SDK (newer versions)
| <code>DMC</code> || Digital Mars C || WonderWitch SDK (newer versions)
|-
|-
| <code>GCC</code> || GCC || Wonderful Toolchain
| <code>GCC</code> || gcc-ia16 || Wonderful Toolchain
|-
|-
| <code>TCC</code> || Visual C++ || WonBe
| <code>TCC</code> || Visual C++ || WonBe
Line 63: Line 63:
The load routine begins at offset 0 into the application. It performs the following activities:
The load routine begins at offset 0 into the application. It performs the following activities:


- SRAM initialization: copying static data from ROM to SRAM and zeroing SRAM memory,
* SRAM initialization: copying static data from ROM to SRAM and zeroing SRAM memory,
- copying the compiler ID to the PCB,
* copying the compiler ID to the PCB,
- heap initialization: setting the argv and heap pointers to the location of the first free byte in SRAM,
* heap initialization: setting the argv and heap pointers to the location of the first free byte in SRAM,
- returning in <code>AX</code> a near pointer to the start function (see "Run").
* returning in <code>AX</code> a near pointer to the start function (see "Run").


=== Run ===
=== Run ===
Line 72: Line 72:
The start function is of the form <code>void main(int argc, char* argv);</code>. It typically performs the following activities before jumping to C code:
The start function is of the form <code>void main(int argc, char* argv);</code>. It typically performs the following activities before jumping to C code:


- configuring the stack pointer,
* configuring the stack pointer (SP) and data segment (DS),
- resetting the display (disabling screen/sprite layers, clearing window and sprite configuration, resetting scroll),
* resetting the display (disabling screen/sprite layers, clearing window and sprite configuration, resetting scroll),
- initializing screen/sprite VRAM locations according to user needs (one/two screens, 256/512 free tiles),
* initializing screen/sprite VRAM locations according to user needs (one/two screens, 256/512 free tiles),
- initializing the default display settings (configuring text mode, enabling screen layers).
* initializing the default display settings (configuring text mode, enabling screen layers).


After running C code, <code>INT $10</code> is triggered to exit the process.
After running C code, <code>INT $10</code> is triggered to exit the process.

Latest revision as of 07:51, 19 October 2024

Memory layout

Process memory is stored in SRAM banks 3 (process 0 - typically used by FreyaOS), 2 (process 1) and 1 (process 2). The entire bank is available to the process.

Process control block

The process control block contains information about the running process. It is stored in the first 96 bytes of data.

Process control block structure
Offset Length Contents
0 4 Compiler ID, zero-terminated string; see below
4 2 TODO
6 2 TODO
8 2 TODO
10 2 TODO
12 4 Far pointer to IlibIL library
16 4 Far pointer to ProcIL library
20 4 TODO
24 64 Current working directory of the process
88 2 Near pointer to an array of near pointers to arguments (argv)
90 4 Far pointer to the process's resource data
94 2 Near pointer to the beginning of the process's free heap area.

Compiler IDs

Known compiler IDs
ID Compiler Source
LCC LSI C WonderWitch SDK
TCC Turbo C/C++ WonderWitch SDK
DMC Digital Mars C WonderWitch SDK (newer versions)
GCC gcc-ia16 Wonderful Toolchain
TCC Visual C++ WonBe

Launching procedure

Launching a process is split into two stages: loading and running.

Load

The load routine begins at offset 0 into the application. It performs the following activities:

  • SRAM initialization: copying static data from ROM to SRAM and zeroing SRAM memory,
  • copying the compiler ID to the PCB,
  • heap initialization: setting the argv and heap pointers to the location of the first free byte in SRAM,
  • returning in AX a near pointer to the start function (see "Run").

Run

The start function is of the form void main(int argc, char* argv);. It typically performs the following activities before jumping to C code:

  • configuring the stack pointer (SP) and data segment (DS),
  • resetting the display (disabling screen/sprite layers, clearing window and sprite configuration, resetting scroll),
  • initializing screen/sprite VRAM locations according to user needs (one/two screens, 256/512 free tiles),
  • initializing the default display settings (configuring text mode, enabling screen layers).

After running C code, INT $10 is triggered to exit the process.