This commit is contained in:
Alvin-Zilverstand committed 2026-10-08 01:02:30 +02:00
1 parent 96cd1ac97d
commit 6dfe517094
33 files changed
+9970 -3177

No files matched your search

+203 -26
View File
@@ -12,9 +12,55 @@ The supplied emulator has been rebuilt for the new kernel services; older
executables lack the character-input and supervised-program traps.
Alternatively run `bob.exe --boot build/kernel.b16` from the repository root.
To build and boot the native 32-bit kernel, close the current emulator session
and run `build.exe --run32`. The build also creates `build/kernel32.b32`, which
can be started directly with `bob32.exe --boot build/kernel32.b32`. The native
kernel supports the shell, RAM files, editor, resident C compiler, supervised
bob16 applications and B32S snapshots. In B32 mode, `cc` and `go` compile the
resident C subset to native bob32 programs with 32-bit `int`; kind-1 bob16 apps
still run with 16-bit arithmetic compatibility. The host `bobcc --wide` option
also emits native bob32 application images for direct boot.
The host compiler also emits a runnable bob32 BASM listing; start it with
`bob32.exe --asm32 build/program.basm`.
To build a native bob32 application for the running bob32 OS, preprocess the C
source and compile it with `--wide-app`:
```text
gcc -E -P -nostdinc -undef -I kernel app.c -o build/app.i
build/bobcc build/app.i build/app.basm build/app.b32 --wide-app
```
Then start the B32 OS with `build.exe --run32` and enter `run32 build/app.b32`.
The application uses the supervised high-memory region and its own 32-bit
stack. `run32` validates the B32K v2 header, range, checksum and file length
before loading it. The image limit is 65,536 words. Apps load from the emulator
host's working directory and are not stored in the guest snapshot. To keep an
image in the guest filesystem, use `import32 build/app.b32 myapp`, then launch
it with `run myapp`. `save` includes imported applications in the B32S snapshot;
after `restore yes`, run them again without re-importing. `run32` remains
available for direct host-path launches.
Set `BOB16_TRACE_FAULT=1` before launching the emulator to log the address and
instruction when a supervised application faults.
The updated emulator also accepts `bob.exe --os` from that directory to boot
the supplied image directly. The welcome message points to `help` and `go bob.c`.
## Small application string library
Native C applications may include `bob_string.h` along with `bob.h`. The string
header supplies word-addressed `bob_strlen`, `bob_strcpy`, `bob_strcmp`,
`bob_strcat`, and `bob_strchr`, plus `bob_isspace`, `bob_parse_int`,
`bob_format_int`, and `bob_token_next`. It is included in the app translation
unit, so the compiler emits only helpers reachable from that app; no separate
library link step is needed. The caller provides enough space for copy/append
destinations. `bob_parse_int` accepts signed decimal or `0x` hexadecimal with
surrounding whitespace and reports validity through its second argument.
`bob_format_int` returns the character count or -1 when the output buffer is
too small. `bob_token_next` edits a writable command buffer in place, groups
single- or double-quoted text, honors backslash escapes, and returns 1 for a
token, 0 at end, or -1 for an unclosed quote.
## Commands
| Command | Behavior |
@@ -24,7 +70,7 @@ the supplied image directly. The welcome message points to `help` and `go bob.c`
| `clear` | Clear an ANSI-capable terminal |
| `mem` | Show heap usage and memory regions |
| `peek 0xC000` | Read a word |
| `poke 0xC000 98` | Write a word in heap RAM only |
| `poke 0xC000 98` | Write a word in the heap (bob16 mode) |
| `alloc 32` | Allocate and zero 32 words; print their address |
| `list` | List RAM files, lengths and kinds |
| `ls` / `dir` | Aliases for list, with the same RAM-file view |
@@ -42,6 +88,8 @@ the supplied image directly. The welcome message points to `help` and `go bob.c`
| `restore yes` | Validate/load that snapshot, replacing the RAM files |
| `load name 0x4001 ...` | Store raw bob16 machine words as a program file |
| `run name` | Load a binary program into reserved RAM, execute, return |
| `run32 path` | Load and run a native B32K v2 image from a host path or guest filename |
| `import32 path name` | Import a host B32K v2 image into bob32 RAM files |
| `halt` | Stop the emulator |
Command lines hold up to 127 characters. Longer lines are completely consumed
@@ -71,9 +119,12 @@ Windows console. Redirected input emits no
redraw or candidate lists. Other terminals use ordinary input; full interactive
key handling currently targets the native Windows console.
The RAM filesystem has eight slots, names up to 23 characters and content up
to 511 words per file. A character occupies one word. `bob.c` occupies one slot
initially. Unsaved files and allocations are lost on exit. Use `save` to retain
The RAM filesystem has eight slots and names up to 23 characters. bob16 keeps
eight fixed 511-word slots. bob32 packs files into 4,096 words total; text and
resident programs remain limited to 511 words, while native apps use six
metadata words plus payload and a terminator, sharing space with other files.
A character occupies one word. `bob.c` occupies one slot initially. Unsaved
files and allocations are lost on exit. Use `save` to retain
files between sessions. Allocation is a zeroing bump allocator with no freeing. `poke` is
restricted to heap RAM so it cannot corrupt the shell.
@@ -207,36 +258,95 @@ int main(void) {
Enter `.` on its own line, followed by `cc count.c count` and `run count`.
The resident compiler supports one `int main(void)` or `int main()` function,
up to 16 integer variables, assignments and compound assignments, decimal/hex/
character/string literals, parentheses, unary `+ - ! ~`, prefix/postfix increment
The resident compiler supports one zero-argument `int main(void)` plus up to
15 additional `int` functions with integer parameters. Calls may be forward,
nested or recursive, and may be used as expression statements; each function
gets its own parameter/local stack frame.
The compiler supports up to 16 functions, 16 parameters per function and 16
simultaneously visible local/parameter names. B32 stack frames can reserve up
to 32 local slots across nested scopes; a further declaration is rejected
because frame loads/stores use signed six-bit offsets. It also supports
assignments and compound
assignments, decimal/hex/character/string literals, parentheses, unary `+ - ! ~`, prefix/postfix increment
and decrement, arithmetic, bitwise operators, shifts, short-circuit `&&`/`||`,
comparisons with C operator precedence, blocks, `if`/`else`, `while`, `for`,
`break`, `continue`, and `return`. For-loop initialization can declare an int;
its increment can assign, compound-assign or increment/decrement a variable.
It supports `print`, `println`, `print_dec`, `print_hex`
and `bob_putc` calls with one argument, comments and common string escapes.
Variables have a flat function scope; declare names once (including for-loop
variables). Compound assignments support `+= -= *= /= %= &= |= ^=`; shift
assignments and assignments inside expressions are unsupported. Strings hold up to
Variables follow block scope, including declarations in `for` initializers;
inner blocks may shadow outer names, while duplicate names in one block are
rejected. Compound assignments support `+= -= *= /= %= &= |= ^=`; shift
assignments and assignments inside expressions are unsupported in bob16. Strings hold up to
63 characters and nesting is bounded at 32 parser frames. Both source and
output must fit RAM-file limits. Invalid or unsupported syntax reports an error
without replacing the output file.
The bob32 resident compiler additionally supports C's right-associative `?:`
conditional expression, including evaluation of only the selected branch. This
operator is not enabled in bob16 because its kernel image is at the address
limit; bob16's compiler behavior is unchanged. B32 resident C also supports
`do/while`, including `break` and `continue` (which proceeds to the condition),
assignment expressions (including right-associative chains), and `<<=`/`>>=`.
Both resident compilers provide `print`, `println`, `print_dec`, and `print_hex`
as one-argument built-ins; bob32 source can call them without a prior prototype.
This is a small C subset, not a complete C implementation. Resident includes,
macros, arrays, pointers, additional functions, structs, floating point
and a standard library are unsupported. Programs call the current kernel's
macros, pointers, globals, structs, floating point and a standard library are
unsupported. The bob32 resident compiler supports `int` function prototypes
with integer parameters (prototype parameter names are optional); incompatible
parameter counts are rejected, and a referenced function still needs a
definition. Empty `f()` declarations retain unspecified-parameter status and
may be followed by a typed declaration or definition; calls made through that
declaration must match the eventual definition's arity. bob16 resident
prototypes remain unsupported. The bob32 resident
compiler supports fixed-size,
one-dimensional local `int` arrays with indexed reads and assignment statements;
their elements use the function's 32-word stack-slot budget. Indexed prefix and
postfix increment/decrement work in expressions; indexed compound assignments
work in statements.
Brace initializer lists accept scalar expressions and a trailing comma; omitted
elements are zero-filled and excess elements are rejected. The bob32 resident
compiler accepts one-dimensional `int` array parameters as `values[]` or with a
fixed bound, passing the word-addressed pointer through the ordinary argument
stack. Helpers can index or modify the caller's elements and forward the array
to another helper. Nested/multidimensional arrays and bob16 resident array
parameters remain unsupported.
Local `int` declarations may contain comma-separated scalar and fixed-array
declarators, each with its own initializer.
The bob32 resident compiler also supports local pointers to integer-returning
functions with integer parameters. Initialize or assign one from a previously
declared matching function, copy it to a compatible local pointer, or assign
null (`0`), then call indirectly. Mismatched signatures and integer values are
rejected. Function-pointer parameters, returns, globals, pointer arithmetic
and bob16 resident function pointers remain unsupported.
Programs call the current kernel's
console/arithmetic routines and belong to the kernel build that compiled them.
In bob32 mode the same syntax emits native 32-bit instructions and kind-2 RAM
program files, which can be run with `run` and retained in B32S snapshots. B32
resident programs start at `0x20000` and use variables at `0xF0000..0xF000F`;
their output can use the remaining shared 4,096-word filesystem space. Source
text files remain limited to 511 words. In bob16 mode files remain kind 1 and
use 16-bit integers and the `0xA000` program region. The bob32 shell also runs
kind-1 legacy programs at `0xC200`, clear of the expanded kernel image.
## Native programs and recovery
`run` clears the program region and copies in the binary RAM file at `0x9000`.
`run` clears the program region and copies in the binary RAM file at `0xA000`
in bob16 mode or `0xC200` in bob32 mode.
`RET` (`0xE000`) returns to the shell with r0 as the exit status. `TRAP 0` also
ends the running program without ending the shell. The emulator saves/restores
the shell's CPU state, supplies a separate program stack, stops execution after
five million cycles, and rejects writes outside `0x9000..0xDFFF`. Invalid
five million cycles, and rejects writes outside the legacy app/heap range
(`0xA000..0xDFFF` in bob16, `0xC200..0xDFFF` for bob32 compatibility apps).
Native bob32 apps write only their supervised application and stack region.
Invalid
instructions and forbidden services return a program fault.
In bob32 mode `run` also accepts resident kind-2 programs, loading them at
`0x20000` with 32-bit arithmetic. Their compiler variables occupy
`0xF0000..0xF000F`; the host `run32 PATH` command remains available for larger
external B32K images.
Programs can write their program region and the shared heap. This is not process
isolation, and input services can wait for input. The raw `load` command accepts
what fits in a single command line; use the resident compiler for larger programs.
@@ -254,13 +364,16 @@ what fits in a single command line; use the resident compiler for larger program
| --- | --- |
| `0x0000..0x00FF` | Boot ROM and reserved return sentinel |
| `0x0100..0x01FF` | Shell and fallback editor input buffers |
| `0x0300..0x8FFF` | Kernel code, globals and strings |
| `0x9000..0xBFFF` | Loaded program, variables and downward program stack |
| `0xC000..0xDFFF` | 8,192-word heap |
| `0xE000..0xE3FF` | Shared editor/compiler scratch (never used concurrently) |
| `0xE400..0xE5FF` | Four-command shell history |
| `0xE600..0xEFFF` | Kernel stack, growing down from `0xF000` |
| `0xF000..0xFFFF` | Eight file-content buffers; protected from program writes |
| `0x0300..0x9FFF` | Kernel code, globals and strings in bob16; current image ends at `0x90E4` |
| `0xA000..0xBFFF` | Loaded program, variables and downward program stack in bob16 |
| `0x0300..0x9FFF` | bob32 low-memory shell data and compatibility space |
| `0xA000..0xCFFF` | Loaded bob16 compatibility program at `0xC200..0xCFFF` |
| `0xD000..0xDFFF` | bob32 heap and compatibility stack region |
| `0xE000..0xEFFF` | Editor/compiler scratch, history and shell stack |
| `0xF000..0xFFFF` | Packed bob32 RAM filesystem contents |
| `0x10000..0x1FFFF` | Native bob32 kernel code, globals and strings |
| `0x20000..0xEFFFF` | Supervised native bob32 program entry/code region |
| `0xF0000..0xFFFFF` | Native app data and compiler variables; stack starts at `0x100000` |
There are no interrupts, multitasking or hardware memory protection. The write
checks and cycle limits are emulator services. Keep kernel recursion within its
@@ -284,9 +397,11 @@ it does not preserve the volatile RAM files from a previous session.
./build.exe --test
```
The C build utility detects MSYS2 GCC on Windows. It builds `bob.exe` and
`build/bobcc.exe`, preprocesses guest C with GCC, and generates `kernel.basm`,
`build/kernel.b16` and `build/kernel.map`. `./build.exe --run` builds and boots.
The C build utility detects MSYS2 GCC on Windows. It builds `bob.exe`,
`bob32.exe` and `build/bobcc.exe`, preprocesses guest C with GCC, and generates
both `kernel.basm`/`build/kernel.b16` and `build/kernel32.basm`/
`build/kernel32.b32`. `./build.exe --run` boots bob16; `./build.exe --run32`
boots bob32.
On Linux/macOS compile the utility as `build-tool`, then run `./build-tool`.
GCC builds host executables and preprocesses guest C only; `tools/bobcc.c` does
@@ -294,6 +409,7 @@ the bob16 code generation. The host compiler supports a broader subset:
signed ints/chars, word pointers and casts, fixed arrays, constant global
initialization, functions and recursion, assignments/compound assignments,
arithmetic/bitwise/shift operators, short-circuit logic, comparisons,
including all arithmetic/bitwise compound assignments and `<<=`/`>>=`,
increment/decrement, if, while, do/while, for, break, continue, function-scoped
labels/goto and returns. Blocks permit shadowing; for-loop declarations have
loop scope. Duplicate declarations in the same scope are rejected.
@@ -312,6 +428,12 @@ adjust to pointers to their element or row type; the outer bound may be omitted.
Unused prototypes need no definition. Pointer descriptors distinguish current
pointee kinds and indirection depth in prototype checks. Qualifier compatibility,
complete expression checking and linking external definitions remain incomplete.
Repeated function declarations merge compatible incomplete/complete array bounds
through pointer types; differing known bounds, element types or depths reject.
Compound assignments validate pointer offsets and integer operands, including
within sizeof. Assignment/increment operands in sizeof must be modifiable scalar
lvalues; their side effects remain unevaluated. Const enforcement and full
assignment conversion checks remain incomplete.
Multidimensional arrays support indexing, row pointers, scaled pointer arithmetic,
increments and pointer differences. Objects are limited to 4096 words and 16
dimensions. Global/local initializer lists accept nested braces and brace
@@ -329,8 +451,28 @@ embedded zero characters, including their contribution to sizeof.
Conditional `?:` and comma expressions preserve branch/sequence behavior.
`sizeof` handles the current word-sized scalar/pointer types, declared arrays
and string literals without evaluating its operand; void operands are rejected.
Structs, typedefs, unsigned types, floating point, function pointers,
Variadics and standard headers are unsupported. `sizeof` tracks array/pointer
Typedef declarations support current scalar, pointer and array types at file and
block scope. Aliases work in parameters, casts, sizeof and further declarations;
void aliases can specify a no-argument function. Compatible identical typedef
redeclarations are accepted; namespace conflicts reject. Inner objects or aliases
can shadow an outer alias, which is restored when the inner scope ends.
Structs, short integer types and floating point remain unsupported. The host
compiler accepts typed function pointers in local and file-scope objects,
function-pointer parameters, address-of function designators and indirect calls
on both targets. Function-pointer/object-pointer conversions and mismatched
signatures are rejected. Returning function pointers and variadic function
pointers are unsupported. The host compiler's bob32 `--wide` target accepts `long` and
`long long` as 32-bit aliases of `int`, consistent with the word-addressed ABI;
`sizeof` reports addressable words (one byte per word). Enums support tagged/anonymous definitions, explicit constant
values, automatic increments, typedef aliases and block/loop tag shadowing.
Enumerators are scoped integer constants usable in bounds, case labels and
initializers. Enum objects use signed 16-bit int storage; distinct enum types
remain distinct in declaration checks and are compatible with this chosen int
representation. Automatic values exceeding 32767 reject. Enum tags must already
be defined when referenced; incomplete enum extensions are unsupported.
Variadics and most standard headers are unsupported; the host C workflow provides
`<stdbool.h>` and `<stddef.h>` with `_Bool`, `size_t`, `ptrdiff_t` and `NULL`.
`sizeof` has the unsigned `size_t` type and tracks array/pointer
expression types, including *&array and array decay in comma/conditional
expressions. Recursive object declarators support grouped names, pointers to
arrays such as `int (*rows)[3]`, and arrays of those pointers. Abstract declarators
@@ -340,6 +482,41 @@ pointee has no size for sizeof or arithmetic. Declarators have limits of 32
parenthesis levels and 64 derived types. Function pointer declarators, functions
returning pointers to arrays, and complete C type checking remain unsupported.
Host tools themselves use ordinary host C types.
The host compiler supports `_Bool` as a one-word type. Initializers, assignment,
casts, returns and arguments to boolean parameters convert zero to 0 and nonzero
to 1. Boolean arrays, typedef aliases and static objects use the same conversion;
increment/decrement and compound assignments preserve normalized storage. The
host workflow includes `<stdbool.h>` with `bool`, `true` and `false` definitions.
Unsigned 16-bit int is available as `unsigned` or `unsigned int`, with `u`/`U`
literal suffixes. Mixed int/unsigned arithmetic uses unsigned comparisons,
division and remainder; right shifts of unsigned values fill with zeros.
Arithmetic storage wraps modulo 65536. Unsigned helpers are included only when
explicit unsigned types/literals are used. Unsuffixed literal selection retains
the earlier compiler behavior; full C literal selection, unsigned char/short/long
and all declaration-specifier orderings remain incomplete.
Sizeof is accepted in constant initialization; local static initializers may
query automatic-object types without evaluating their values. Type/literal sizeof
works in bounds and case labels. Named-object sizeof in those contexts uses
parser type bindings with block/for scope and parameter array adjustment.
Objects must already be declared and complete; later or escaped bindings reject.
File-scope object declarations support `extern`, compatible repeated tentative
definitions and a single initialized definition. Incomplete array declarations
merge with known bounds; an uncompleted tentative array reserves one element.
Unused extern objects need no definition, while referenced ones must be defined
in this source unit. Block-scope extern object declarations refer to that same
storage without allocating stack slots. They can shadow an outer local, and
names introduced only in a block do not escape it. Block extern initializers
and conflicts with a local in the same scope reject. Block function declarations,
separate-unit linking remain unsupported. File-scope static objects/functions
use internal linkage within the current source unit. Later extern declarations
inherit prior internal linkage; conflicting external/internal declarations
reject. Function declarations without a storage class retain an earlier static
declaration's linkage. Internal tentative arrays need a complete bound.
Block-scope static objects have private persistent storage initialized once,
including arrays and pointers to other static objects. Initializers must use
supported constant expressions or static addresses; automatic-object addresses
and runtime calls are rejected. Equal names in different blocks/functions remain
independent, and a static object's name is scoped to its declaring block.
To compile another standalone guest source from the repository root: