diff --git a/BOB64_MIGRATION.md b/BOB64_MIGRATION.md new file mode 100644 index 0000000..81d2bee --- /dev/null +++ b/BOB64_MIGRATION.md @@ -0,0 +1,395 @@ +# bob64 migration status + +This document tracks the separate x86-64 OS target. `bob16` and `bob32` are +software-emulated custom instruction sets; the current `bob32` kernel is not an +x86 kernel and cannot be promoted to x86-64 by changing C integer widths. The +new target starts as an x64 UEFI application. Its opt-in handoff now takes +ownership of paging, early memory allocation, display output and a minimal shell; +the existing emulator/build outputs stay separate. + +## Implemented stages + +- `bob64/types.h` defines fixed-width scalar types and pointer/size types from + compiler-provided x86-64 definitions, with compile-time width checks. +- `bob64/boot.c` builds as a PE32+ AMD64 EFI application at the standard + removable-media path `EFI/BOOT/BOOTX64.EFI`. The image includes a PE base + relocation directory and `DYNAMIC_BASE`, so firmware may load it away from its + preferred `0x100000` image base. +- x64 UEFI transfers control in 64-bit long mode with its x64 ABI, stack and + page tables. The entry checks the maximum CPUID leaves before reading feature + bits, requires PAE and long-mode support, and confirms `EFER.LMA` before it + prints `bob64!` through UEFI text output. `bob64/cpu.c` also decodes NX + support and the CPU's physical-address width for paging setup. The safe probe + returns through firmware; the handoff variant switches to bob64-owned tables + and exits Boot Services. +- The boot entry reads the UEFI memory map through the x64 Boot Services table. + `bob64/memory.c` parses the firmware-provided descriptor stride and seeds a + sorted, coalesced first-fit allocator of 4 KiB conventional physical pages, + keeping physical addresses in `u64`, clipping ranges to the detected CPU + physical-address width, and reserving the first MiB. Allocation + records make invalid and double frees fail; the independent live-allocation + ledger supports up to 16,384 ranges, while free extents have a separate + 128-range limit. Boot reserves the replacement stack and table pool from this + allocator, and the kernel continues allocating from the preserved state. +- The x64 UEFI ABI is Microsoft's x64 ABI: integer/pointer arguments use + `RCX`, `RDX`, `R8`, and `R9`; integer/pointer returns use `RAX`; `RSP` is + 16-byte aligned at call sites with 32 bytes of caller-provided shadow space. + The compiler data model is LLP64 (`char` 8, `short` 16, `int` 32, `long` 32, + `long long` 64, pointer/`size_t` 64). bob64 code should use `u64`/`s64` and + `usize`/`isize` for explicit widths rather than assuming `long` is 64-bit. +- `bob64/paging.c` builds four-level x86-64 page tables with 4 KiB + leaves. Allocate/access callbacks keep physical page addresses distinct from + currently accessible pointers; the builder enforces the CPUID-reported + physical-address width. `bob64_page_map_range` validates canonical spans and + maps byte ranges while preserving partial-page offsets. `bob64_page_protect` + tightens leaf permissions and `bob64_page_unmap` returns the removed physical + frame and flags; callers invalidate the TLB for live edits. The host suite + walks low and upper canonical virtual addresses and physical/table addresses + above 4 GiB, and verifies writable pages can become read-only/NX, be unmapped, + and be mapped again. The handoff activates the root after enabling `EFER.NXE` + when supported; host tests cover mapping logic, while the privileged switch + still needs UEFI runtime verification. +- `bob64/bootstrap.c` composes that mapper into a bootstrap identity address + space for the loaded EFI image, a replacement stack, and a pre-reserved + contiguous page-table pool. It marks stack/pool pages NX when supported and + rejects overlapping ranges or an undersized pool. Tests verify translation + and permissions for all three regions. The EFI entry obtains the loaded-image + protocol and uses its full-width image base and size to prepare and verify + identity mappings for the actual image, an 8-page replacement stack, and a + 128-page table pool. The handoff also maps its memory-map buffer and supported + GOP framebuffer. It builds the kernel GDT and exception IDT while the image + is mapped. The default `--bob64` image still returns safely to firmware after + preparation. +- `bob64/descriptors.c` builds kernel and DPL3 user code/data GDT entries, a + full-width 64-bit TSS descriptor, the packed 10-byte GDTR/IDTR operand, and + 16-byte x86-64 IDT gates with split 64-bit handler addresses. Boot sets TSS + `RSP0` to the initial kernel stack, and the handoff loads the task register. + After heap startup, the kernel changes `RSP0` to a separate supervisor-only + privilege-transition stack so user interrupts will not overwrite the paused + kernel call stack. Each shell-launched application now gets its own zeroed + 16 KiB privilege stack; the previous TSS stack is restored before that + allocation is released. Tests verify selector values, TSS offsets/base/limit, + full-width stack replacement, alignment, DPL3 gates, IST, and gate type. +- `bob64/interrupts.S` contains 64-bit stubs for CPU exception vectors 0-31, + normalizing hardware error-code and no-error-code frames before saving all + general-purpose registers and calling the Microsoft x64 C dispatcher. The + common path restores registers and uses `iretq`. `interrupts.c` wires an IDT + to those stubs and a fatal fallback, and prints full 64-bit register values + over COM1 and the framebuffer before halting. The opt-in handoff loads the + IDT. The DPL3 vector `0x80` enters a dedicated syscall stub; runtime + exception and syscall delivery still need firmware/emulator testing. +- `bob64/kernel.c` is the first kernel-owned C entry point. It checks the + boot-information structure, active CR3, memory-map range, and stack, then + reports the 64-bit root and map details, checks the growable kernel heap, then + starts the polled shell. The filesystem and shell are still bring-up services, + not yet a general-purpose OS. +- `bob64/handoff.S` provides the Microsoft x64 ABI entry bridge: interrupts are + disabled, the kernel GDT is loaded and CS reloaded, the IDT is loaded, NXE + and CR0.WP are enabled when supported, the TSS is loaded, CR3 is switched, and execution moves + to the replacement stack before calling the kernel. The EFI boot path calls + `ExitBootServices` using a freshly acquired map key, retrying a stale key up + to three times. +- The handoff is opt-in so the original EFI probe stays available: + `build-tool --bob64-handoff` emits a distinct image and + `build-tool --bob64-handoff-test` runs host PE checks against it. Those checks + cannot prove the privileged transition works on real firmware. +- The handoff queries UEFI GOP and maps a supported RGB/BGR framebuffer into + the new address space as writable, non-executable, uncached memory. The + kernel's `bob64/console.c` draws a compact 5x7 text font, wraps and scrolls, + and mirrors output to COM1. Unsupported or invalid GOP modes retain the serial + console fallback. Host tests exercise format encoding, glyph output, and + invalid framebuffer bounds; actual display output still needs UEFI testing. +- `bob64/heap.c` provides a 16-byte-aligned, coalescing kernel heap with + `alloc`, `calloc`, and `free`. Kernel entry adopts the page allocator and + page-table pool seeded by boot, then grows the heap by mapping physical 4 KiB + pages into a 64 MiB high-half range at `0xffff900000000000`. New pages are + zeroed before use. Kernel entry smoke-tests multi-page allocations, alignment, + zeroing, writes, frees, and double-free rejection. Host tests cover splitting, + coalescing, overflow, and invalid frees. This early heap is single-core and + does not reclaim empty pages yet. +- `bob64/keyboard.c` decodes PS/2 set-1 input, including shift, caps lock, + editing keys, and Pause/extended sequences. IRQ1 now feeds a bounded 64-event + queue used by the shell and app event service after the kernel remaps the PIC; + the kernel keeps polling as a fallback if the controller is unavailable. + IRQ12 feeds a bounded mouse-event queue through the same app event service; + COM1 remains polled. Unit tests cover scan-code state, keyboard/mouse queue + behavior, and shell command/edit behavior. A 100 Hz PIT IRQ now supplies a + monotonic tick counter through the versioned syscall ABI. USB keyboards, + history and completion remain future work. +- `bob64/filesystem.c` adds a flat, volatile binary-safe filesystem backed by the + kernel heap. It supports 64-bit lengths, case-sensitive names, atomic file + replacement, listing, reads, and deletion; names reject path separators and + characters outside the safe filename set. The shell exposes `ls`, `cat NAME`, + `write NAME TEXT`, and `rm NAME`. Host tests cover replacement, invalid names, + binary NUL round-trips, and shell workflows. +- `bob64/snapshot.c` defines B64S version 1 as a pointer-free little-endian + format with 64-bit total/data lengths and a CRC-32. Restore validates version, + size, checksum, record bounds, names, and duplicate files before replacing + the live filesystem. The shell's `save` and `restore` commands keep one + checkpoint in the kernel heap for the current boot session; it is lost on + reboot. Host tests cover round-trip, empty files, replace-on-restore, + truncation, unsupported versions, checksum errors, and unchanged state after + rejected input. Disk persistence and directories remain future stages; the + app filesystem ABI supports bounded whole-file operations and ABI v10 streaming + handles with 64-bit seek positions and bounded reads/writes; hardware-backed + persistence remains outstanding. +- `bob64/exec.c` defines B64E version 1, a flat position-independent 64-bit + executable image with a versioned ABI, exact payload length, 64-bit memory + size and entry offset, page-aligned code/data boundary, payload CRC-32, and + zero-required reserved fields. The shared parser rejects malformed/truncated + images before returning a view; a contiguous copy helper preflights capacity + and address overflow, copies the image, clears the memory-only tail, and + preserves entry addresses above 4 GiB. Mapped application loading is provided + separately by `process.c`. A synthetic B64E app now runs at CPL3, writes + `bob!` through syscall v2, performs a bounded RAM-file round trip, and exits + back to the saved kernel stack. +- `bob64/abi.h` starts application ABI v1 on the same Microsoft x64 calling + convention used by the UEFI kernel: integer/pointer arguments in RCX, RDX, + R8, and R9; scalar status in RAX; 32-byte shadow space; 16-byte call-site + stack alignment; and no red zone. Entry receives one pointer to a fixed + 32-byte startup record containing a 64-bit argument count and argv pointer. + The record and its strings are app-space data, so the contract does not pass + kernel pointers. Tests check the record layout, entry call, nested calls, and + stack-passed arguments. Syscall ABI v10 defines an ABI query, character and + bounded buffer output, file reads and writes, pixel-display query/present, + blocking keyboard and PS/2 mouse events, and process exit through interrupt + vector `0x80`; user pointers are validated + against the active process root before buffer reads or writes. Display apps + submit a packed 0x00RRGGBB frame matching GOP dimensions; the kernel copies + bounded chunks into the device surface without exposing its address. Tests + cover the syscall and both GOP channel formats. + `apps/bob64_display.c` exercises the app-facing wrapper and is packaged as a + B64E image with a bounded 1024x768 static surface; runtime execution awaits + UEFI verification. +- `bob64/window.h` ports the reusable window-manager behavior to app-owned + fixed-capacity 64-bit state: nonzero 64-bit handles, full-width context + pointers, visibility, focus, z-order, hit testing, title-bar dragging, + clamping, dirty redraws, and keyboard/mouse event routing to window-local + coordinates. Host tests exercise overlap redraw, wheel routing, focus and + pointer values above 4 GiB. `apps/bob64_gui.c` is the first native desktop + on this manager. It opens a named RAM text file (or `notes.txt` by default), + lists RAM files in a separate window, supports selection/open/refresh and + confirmed deletion, plus insertion, line breaks, cursor movement, click + placement, scrolling, Ctrl+S save and an unsaved-exit prompt. It validates flat + filenames and protects an existing file over the current 4 KiB syscall limit + from accidental overwrite. The shell launches it with + `run desktop.b64e [filename]`; host tests cover the editor buffer, packaged + UI strings, file ABI and window manager. The full existing bob GUI, a file + picker and real UEFI interaction remain to be ported/verified. +- `bob64/ABI.md` records the register-preservation rules, stack alignment and + shadow-space contract, pointer ownership, and application entry shape. The + compiler's aggregate behavior follows the Microsoft x64 ABI; aggregate + returns are not part of the application-entry contract. `bob64/app.h` exposes + syscall wrappers for native C apps without kernel-internal types. The small + `bob64/libc.c` runtime provides memory and string operations with 64-bit sizes. +- `bob64/compiler.c` is the first resident x86-64 code-generation stage. The + shell exposes `cc bob.c [OUTPUT]`, which packages the accepted source directly + as B64E; `run app.b64e` launches it. The current syntax accepts `int` or + `long`, `long long`, or `int main(void)`, initialized `int`/`long`/`long long` + locals and assignments, + bounded `bob64_app_write` calls with string literals, and 64-bit integer + return expressions with parentheses, unary minus, addition, subtraction, and + multiplication. Its frame and entry wrapper follow the Microsoft x64 stack + contract; syscall ABI v10 provides exit, graphics output, whole-file and + streaming file I/O/list/delete, + and input. + The compiler recognizes `usize`/`uintptr_t` as unsigned 64-bit scalar types + and `isize`/`intptr_t` as signed 64-bit scalar types in declarations and + function signatures. These are built-in type names; typedefs and header + inclusion remain unsupported. `usize *`, `uintptr_t *`, `isize *`, + `intptr_t *`, and `long long *` map to signed/unsigned wide-pointer types with + eight-byte loads, stores, indexing and scaled pointer arithmetic. They work as local, + parameter, return, global, and struct-field types; global pointers may target + matching scalar objects. Fixed-size signed and unsigned 64-bit arrays now + support local and global storage, initialization, indexing, mutation, array + parameter decay, and eight-byte element addressing. Local arrays are limited + to 16 elements by the fixed function frame; global arrays share the 4 KiB data + page. + Function declarations and definitions can return `char *`, `short *`, `int *`, + and pointers to declared structs. Returned pointers keep all 64 bits; return + expressions must match the declared pointee type. Returning a pointer through + `long long`/`usize` remains accepted for the compiler's existing raw-address + tests. Host execution tests cover pointer identity through a prototype and a + returned string literal used by the caller. +- `bob64/process.c` adds a callback-backed B64E loader core. It reparses the + exact file before allocation, maps up to 16 MiB of app memory at + `0x0000004000000000`, keeps code user-readable/executable and read-only, and + maps data, BSS, and a 64 KiB stack writable/user/NX. It leaves an unmapped + guard page below the stack, builds a 64-bit argv array and startup record in + app memory, and prepares an ABI-aligned entry stack with shadow space. Failed + loads roll back mappings and frames; unload removes each mapping before + returning its physical frame. Host tests use physical frames above 4 GiB and + verify argument contents, permissions, zero-filled BSS, guard placement, and + rollback. The kernel wires these callbacks to its real page allocator and a + private cloned root with a 34 MiB isolated app arena. At boot, the synthetic + user app prints `bob!` and exits through the controlled syscall path. + The shell's `run NAME [ARG ...]` command now reads B64E files from the RAM + filesystem and launches them with app-owned arguments; `bob.b64e` is seeded + as an example. General app services and persistent storage remain ahead. +- `build-tool --bob64` builds only the new EFI image. `build-tool --bob64-test` + also validates the PE machine, PE32+ header, EFI application subsystem, + 64-bit type sizes, synthetic pointer arithmetic above 4 GiB, and the presence + of base relocations for firmware-selected load addresses. It also exercises + four-level mapping, translation, permissions, canonical-address checks, + physical-width limits in both allocator and page tables, multi-page range + mapping, protect/unmap/remap behavior, duplicate-map rejection, bootstrap identity mappings, synthetic + CPUID feature decoding, 64-bit GDT/IDT layouts, and exception-stub wiring. + +## Still required by the migration goal + +- [x] Boot the handoff image under x64 UEFI emulation. QEMU/OVMF verified the + long-mode entry, `ExitBootServices`, owned CR3, kernel heap, framebuffer + console, COM1 diagnostics, ring-3 smoke app, and shell. A runtime script + repeats the boot and checks its serial milestones. +- [x] Exercise ring-3 syscalls and user exception recovery after loading the + GDT/IDT and new CR3. A deliberate invalid opcode was diagnosed with the full + register frame and returned to the kernel; the corrected smoke app now exits + normally. The IDT now also contains PIT, PS/2 keyboard, and PS/2 mouse IRQ + handlers; runtime IRQ-path verification remains pending below. +- [x] Verify actual ring-3 text protection and data NX behavior. QEMU runtime + probes attempt to write the read-only executable page and execute the NX data + page; both receive the expected user page-fault error bits and return to the + kernel. The kernel also checks that the stack guard is unmapped. +- [ ] Add dynamic page-table-pool growth, heap locking, and reclamation of empty + heap pages. The bootstrap identity map favors bring-up simplicity. +- [x] Verify GOP, COM1, PS/2 keyboard, and mouse input under UEFI emulation. + QEMU showed mouse movement and a click selecting a file-list row; keyboard + input launched/closed the desktop and created a third window. +- [ ] Verify the new IRQ1 keyboard and IRQ12 mouse paths under UEFI emulation. + Host tests cover the IDT gates and bounded event queues; QEMU verification is + pending. +- [x] Add a 100 Hz PIT timer IRQ, tick counter, and user tick query. The timer + tick path is covered by host syscall tests; runtime QEMU verification remains + pending alongside keyboard/mouse IRQ checks. +- [ ] Add USB keyboard support and command history/completion. COM1 remains + polled. +- [ ] Add persistent storage for B64S snapshots. ABI v10 now supplies bounded + handle-based streaming reads/writes, 64-bit absolute seeks, create/truncate/ + append modes, and per-app handle cleanup; physical persistence remains open. +- [ ] Port remaining device services and add USB keyboard support. +- [x] Add typed pointer returns to the resident x86-64 compiler for + `char *`, `short *`, `int *`, and declared struct pointers. Tests cover + prototype calls, string literal and struct pointer returns, and rejection of + incompatible pointee types. +- [x] Add `void` helper functions and scalar `char` returns to the resident + compiler. Void helpers accept explicit `return;` or fall through, can be called + as statements, and are rejected in value contexts. Scalar `char` returns + sign-extend from eight bits; main remains required to return a value. +- [x] Add typed pointers to `usize`/`uintptr_t` and `isize`/`intptr_t` values. + Local/global/struct-field storage, parameters, returns, dereference, indexing, + assignment, and 8-byte-scaled arithmetic are covered, including synthetic + pointer values above 4 GiB. +- [x] Add fixed signed and unsigned 64-bit arrays with local/global storage, + initialization, indexed reads/writes, and array-parameter decay. Local arrays + are bounded to 16 elements and global data to the existing 4 KiB page. + File-scope `short`, `int`, `long`, `char`, and `long long` scalars plus bounded + fixed `short`/`int`/`char` arrays now use initialized writable B64E data and + RIP-relative x64 access across functions. Global `short *`/`int *`/`char *` + initializers may target + previously declared arrays or string literals. Named structs define aligned + scalar/pointer layouts and support local/global instances plus `.`/`->` field + loads/stores. Struct arrays, nested structs, typedefs, and multiple translation + units remain unsupported. Limits are 8 struct types, 16 fields per type, 16 + global objects, and the single 4 KiB data page. + Local fixed `short`/`int` arrays, `short *`/`int *` locals, + dereference/indexing, scaled pointer arithmetic and pointer differences, and + local brace initializers are + implemented. `short` (16-bit), `int`/`long` (32-bit), and `long long` + (64-bit) helper functions and matching prototypes before or after `main` + support nested/forward + calls with up to sixteen scalar, `short *`/array, `int *`/array, `char *`, + `usize *`, `isize *`, or struct-pointer parameters, following the Microsoft + x64 register and stack argument layout. + Compound blocks and `for` initializers now have lexical local scopes with + shadowing and stack-slot reuse after scope exit. + NUL-terminated string + literals, signed 8-bit `char` locals/parameters, escaped character constants, + byte-scaled `char *` indexing, stores, dereference, and arithmetic, plus local + `char` arrays with string or brace initializers, now support resident C string + traversal and mutable text buffers. Struct pointer parameters can be passed + through helper calls using the Microsoft x64 argument ABI; helpers can read + and write fields through `->`. + `if`/`else` and `while` support signed + relational/equality comparisons, and expressions support unary `!` plus + short-circuit `&&`/`||`. Basic `for` loops now emit initialization, condition, + body, and scalar assignment update code. `break` and `continue` patch to the + nearest loop; `for` continue enters its update clause. Early `return` + statements work inside branches and loops; the subset still requires a final + return at the end of each function. +- [x] Add a kernel-owned per-app window manager and port the desktop's file and + editor windows to its surfaces. Syscall ABI v10 creates, focuses, destroys, + validates and copies app surfaces, composites z-order, routes input with + 64-bit handles and local/screen coordinates, and releases the session on app + exit. Concurrent apps are still not displayed together. +- [x] Run the native desktop under QEMU/OVMF at 1280x800. Both managed windows + rendered; keyboard input created a third window, Escape returned to the + shell, and Ctrl+S saved editor text through the file syscall. The full screen + and B64S shell commands were also exercised in the same UEFI session. +- [ ] Port the remaining applications to the kernel window API. Syscall ABI v10 + also provides bounded file reads/writes/list/delete, console I/O, + full-screen presentation, blocking PS/2 keyboard/mouse events, ABI query, and + process exit. The host `bob64cc` + bridge continues to package the broader C subset supported by GCC. +- [ ] Port the remaining existing applications and full GUI/widget behavior; + the current native text editor is an initial, limited desktop milestone. +- [x] Run the kernel-generated ring-3 `bob!` app under x64 UEFI emulation. The + resident compiler also compiled and launched `bob.c`; B64S `save`/`restore` + recovered a deleted file, and the native GUI opened and saved an editor file. +- [ ] Complete the full acceptance flow and add runtime tests for broader + calling-convention/stack cases, hardware interrupts, mouse input, and + persistent B64S storage. The ring-3 app image runs at a virtual address above + 4 GiB; host tests also cover synthetic high addresses and broad ABI/memory + cases. +- [x] Verify bob64 boots in x64 UEFI emulation and performs its own kernel + initialization without executing 32-bit kernel or app code. The broader + migration remains active: the resident C subset, devices, persistence, and + existing application ports still need work. + +## Build and test + +```text +build-tool --bob64 +build-tool --bob64-test +build-tool --bob64-handoff +build-tool --bob64-handoff-test +tools/test_bob64_qemu.ps1 -QemuPath -OvmfCodePath +``` + +The safe output goes to `build/bob64/EFI/BOOT/BOOTX64.EFI`; the opt-in handoff + image goes to `build/bob64-handoff/EFI/BOOT/BOOTX64.EFI`. Host tests validate +the PE/COFF architecture and subsystem, 64-bit pointers, synthetic addresses + above 4 GiB, memory-map descriptor strides, page allocation/coalescing, + allocation-ledger capacity, invalid free handling and overflow checks. The + PowerShell QEMU test performs a real OVMF boot of the handoff image and checks + serial markers through the kernel shell; it needs the QEMU executable and + `edk2-x86_64-code.fd` paths supplied by the caller. The full script does not + replace testing on physical UEFI hardware. + +## Memory layout boundary + +The current owned paging stage uses four-level tables. The image, bootstrap +stack, table pool, memory map, and supported GOP framebuffer are mapped at +identity addresses in the lower canonical half. Physical addresses below 1 MiB +remain reserved. The early heap occupies a 64 MiB window beginning at +`0xffff900000000000`. The B64E loader reserves a lower-half user image arena of +16 MiB beginning at `0x0000004000000000`; its 64 KiB user stack begins at +`0x0000004002001000`, with an unmapped guard page at `0x0000004002000000`. +The kernel smoke test clones the active root, privately copies the page-table +branch covering a 34 MiB image-and-stack arena, clears stale mappings in that +arena, and switches CR3 before loading and unloading a synthetic app. Other +kernel mappings remain shared. The kernel enters the synthetic app at CPL3 +using an `iretq` frame. The app can query the syscall ABI, print characters +through `int 0x80`, and exit through a controlled return to the saved kernel +stack. The user-entry bridge enables interrupts for apps and restores the +caller's prior IF state when the app exits. The boot smoke app checks that the +keyboard IRQ path remains enabled after a user process returns. The versioned +syscall ABI also includes file handles and window services. +The fallback kernel privilege stack and each app's dedicated 16 KiB interrupt +stack are allocated from the supervisor-only heap. App runs also push a bounded +syscall context that preserves the parent's callbacks, user page table, scratch +buffers, and file handles; each app owns a separately allocated window-server +session. The user-entry return bridge still uses singleton state, so nested app +execution is not enabled yet. +The volatile +filesystem and B64S checkpoint live in the kernel heap; there is no full +physical direct map or filesystem mapping. diff --git a/C_IMPLEMENTATION.md b/C_IMPLEMENTATION.md index fe640c9..0eb066a 100644 --- a/C_IMPLEMENTATION.md +++ b/C_IMPLEMENTATION.md @@ -583,3 +583,55 @@ The bob32 resident compiler now accepts one-dimensional array parameters, adjust Started the app-side standard library with `kernel/bob_string.h`: basic string operations, whitespace detection, overflow-checked signed decimal/hex parsing, bounded integer formatting and quote-aware in-place tokenization. Runtime tests exercise edge cases in bob32, and a compiled app using the header is imported, launched, snapshotted, restored and run again from the bob32 filesystem. Full suites: CPU 203, OS/compiler 1,840, console 28. Native bob32 apps can now use `int main(int argc, char **argv)`. The OS shell accepts quoted arguments after an imported app name, preserves empty strings and backslash escapes, and supplies the guest filename as `argv[0]`. A compiled app checks its argument count and values—including a word with spaces and an empty argument—through the real import/run path. Full suites: CPU 203, OS/compiler 1,844, console 28. + +Added a version 1 native OS service through `bob_fs.h` for filesystem metadata and text operations, plus basic memory/filesystem system information. Added native `echo`, `ls`, `cat`, `sysinfo`, and `notes` examples. Integration tests exercise the utilities, create a note, save a B32S snapshot, restore it in a new emulator process, then read and delete it. Full suites: CPU 203, OS/compiler 1,874, console 28. + +Added a version 1 graphics and input boundary through `bob_gfx.h` and `bob_event.h`. The terminal backend provides an 80x25 double-buffered character-cell surface with colors, pixels, rectangles, lines, text and transparent bitmap-cell blits. Blocking event wait delivers typed characters and special key presses, with release/mouse event types reserved. The graphics demo draws, waits for a test key, leaves graphics mode and returns to the shell. Full suites: CPU 203, OS/compiler 1,880, console 28. + +## bob64 user pixel-surface milestone + +bob64 syscall ABI v3 adds a display query and a protected full-screen surface present call. Apps submit packed 0x00RRGGBB pixels; the kernel validates the entire range in the isolated user page table, then copies in 1024-pixel chunks and converts channels for GOP RGB/BGR modes without exposing the device pointer. bob64_app_get_display and bob64_app_present wrap the services. The new apps/bob64_display.c demo paints a bounded 1024x768 gradient and writes bob!; build/test parses its B64E image. Tests verify dimensions, both GOP channel layouts, invalid mappings and size mismatches. build-tool --bob64-test and --bob64-handoff-test both pass. Actual display presentation remains unverified until UEFI runtime testing. +## bob64 app input-event milestone + +Syscall ABI v5 defines a fixed 44-byte BOB64_EVENT and blocking app-owned input delivery. The PS/2 set-1 decoder emits key-down/up events, ASCII characters, Shift/Caps/Control/Alt state and extended key identities while preserving shell input. A bounded PS/2 mouse driver decodes movement, button transitions, IntelliMouse wheel packets and extended buttons, clamps coordinates to the framebuffer, and routes events through the same validated app buffer. apps/bob64_display.c stays on screen until Escape. Host tests cover keyboard modifiers, mouse packet signs/clamping/buttons/wheel, syscall delivery and invalid user pointers. Both bob64 host suites pass; UEFI device execution remains unverified. + +## bob64 user-space window-manager milestone + +Added bob64/window.h as a 64-bit-clean app-owned port of the existing fixed-capacity window manager. It stores 64-bit handles and context pointers, preserves focus/z-order/visibility and dirty-redraw behavior, hit-tests and clamps windows, supports title-bar dragging, and routes keyboard, mouse, and wheel events in local coordinates. Tests exercise overlapping redraws, hidden-window focus, drag/release behavior, wheel routing, stale handles, and synthetic app pointers/handles above 4 GiB. bob64 graphics and handoff test suites both pass and print bob!. The existing desktop application and widget drawing layer still need porting and UEFI runtime verification. + +## bob64 native desktop editor milestone + +Expanded `apps/bob64_gui.c` from a windowing demo into a small usable desktop app. It launches from the shell as `run desktop.b64e [filename]`, defaults to `notes.txt`, and supports mouse cursor placement, keyboard insertion, Backspace/Delete, arrow-key movement, newline insertion, viewport scrolling, Ctrl+S saves and a two-Escape unsaved-exit prompt through syscall ABI v5. Filenames are validated against the flat filesystem's allowed set. Raised the bounded whole-file console/file syscall buffer to 4 KiB and moved its transfer scratch into kernel static storage to keep the 16 KiB privilege stack clear. Added `bob64/editor.h` for a bounded 4 KiB editing buffer and host regression tests for 4 KiB syscall read/write across page boundaries, user-range validation, insertion, deletion, movement, wrapping and line handling. Files over the current syscall buffer limit cannot be overwritten by this app. The generated app is embedded in the UEFI image and installed as `desktop.b64e`; both `--bob64-test` and `--bob64-handoff-test` pass and print `bob!`. Actual UEFI input/display and the full existing GUI port remain unverified. + +The resident bob64 compiler now supports fixed local `int` arrays, `int *` +locals, array decay, address-of/dereference, indexed loads/stores, and scaled +pointer addition/subtraction. It rejects pointer multiplication and mismatched +pointer assignments/initializers. Runtime tests execute generated code for +array indexing, both pointer-addition operand orders, 4-byte element scaling, +pointer differences and a stack pointer above 4 GiB; negative tests check +invalid pointer arithmetic and assignment. Local arrays also accept scalar +brace initializers with trailing commas and zero-fill for omitted elements; +excess elements are rejected. Integer and `long long` helper functions may +appear before or after `main`, with forward and nested calls using up to eight +parameters. The first four use Microsoft x64 argument registers and later ones +use the caller's stack area; scalar and `int *`/array parameters are stored in +function-local stack slots, and array parameters support indexing. Tests cover +generated-code execution for pre-main definitions, 64-bit helper returns, array +parameters, nested calls, all four argument registers, stack-passed scalar and +pointer arguments, argument-count rejection, and the established `bob!` smoke +path. Function prototypes now contribute signatures during a top-level pass; +definitions must match their return type and parameter count/types, and calls +to declarations without definitions are rejected. Tests cover unnamed prototype +parameters, 64-bit prototype returns, and prototype/definition conflicts. The +statement parser now emits tested +`if`/`else` and `while` branches, and signed integer comparisons for `==`, `!=`, +`<`, `<=`, `>`, and `>=`; braced blocks share one function namespace. Unary +`!` and short-circuit `&&`/`||` are supported, with regression tests proving +skipped branches do not execute pointer-mutating calls. Lexical scopes and +return types other than `int` or `long long` remain unsupported. +C-style `for` loops now support optional +initialization/condition clauses and a scalar assignment update. Nested loop +contexts patch `break` to the nearest exit and `continue` to the while condition +or for-update block; tests exercise nested targets and reject either statement +outside a loop. Conditional early returns emit the function epilogue and +are tested with a signed absolute-value helper. diff --git a/C_OS.md b/C_OS.md index 13469f0..99b65cc 100644 --- a/C_OS.md +++ b/C_OS.md @@ -47,6 +47,85 @@ name and `argc` includes it. Pass arguments with `run myapp first "two words"`; quotes group spaces and backslash escapes the next character. Empty quoted arguments are preserved. This applies to imported guest files; direct host-path `run32` launches currently start without command-line arguments. + +Native applications can use `bob_fs.h` for guest RAM files. Its version 1 +service supports listing names/kinds/sizes, direct kind lookup by filename, +reading and writing text files and +raw bob16/bob32 program words, and deleting files. Text writes are bounded to +the text-file limit; binary writes accept only program kinds. Native B32K apps +must enter storage through validated import. The OS keeps filesystem tables +private to the kernel. See [the native app examples](apps/README.md) +for `echo`, `ls`, `cat`, `sysinfo`, and the snapshot-friendly `notes` app. +`launcher` lists stored native bob32 applications and runs one with arguments; +native apps can use `bob_process.h` to launch another stored app and receive its +exit code. The emulator preserves the suspended app's memory while a child runs. + +`bob_memory.h` provides a small caller-owned word arena for temporary app data. +Give it an integer buffer, allocate in target words, inspect used/remaining space, +and reset it for reuse. Allocation returns null for invalid requests or when the +buffer is full; it reserves no global OS heap. + +Native apps can include `bob_time.h` to read UTC seconds through the versioned +OS-service boundary. The result is returned as low and high 32-bit words. +`bob_system.h` reports the system-service version, cell-framebuffer presence +and size, and whether keyboard and mouse input are available. `sysinfo` displays +these device capabilities alongside the filesystem and application-memory +usage. +For convenience, `bob_native.h` includes the common string, memory, filesystem, +process, time, system-capability, and input-event APIs. Add `bob_gfx.h` and +`bob_gui.h` separately when building graphical apps. + +`bob_gfx.h` provides the first graphics abstraction: apps draw into an 80x25 +cell framebuffer, then present it through the emulator’s terminal backend. +The API includes resolution, pixels, rectangles, lines, text, transparent +bitmap cells with per-cell foreground colors, clear, present and leave. +`bob_font.h` adds a 5x7 bitmap text renderer for uppercase letters, digits, +space, and common punctuation. +`apps/graphics_demo.c` draws a sample +screen, waits for a key through `bob_event_wait`, and returns to the shell. +The GUI demo's Window B includes a keyboard- and mouse-driven native app +launcher; it runs stored apps through `bob_process.h` and shows their exit status. +Press `?` for a bitmap-font help panel; Escape or its Close button returns to +the desktop. +Event version 1 delivers character and special-key down/up events. On Windows +console input it also delivers mouse movement and button transitions with +screen-cell coordinates, plus signed mouse-wheel deltas. `bob_event_wait` +blocks; `bob_event_poll` checks the console queue without blocking. Redirected +input remains character based and is consumed by the blocking path. This +cell-based backend establishes the app boundary before adding a true pixel +surface. +`bob_event_queue.h` provides a caller-owned FIFO for buffering these events; +overflow is reported without overwriting queued input. +`bob_wm.h` provides the reusable bob32 window manager. Applications give it fixed +arrays for window records and stacking order; it owns allocation, visibility, +focus, z-order, hit testing, title-bar dragging, event routing, and dirty-window +tracking. `bob_wm_dispatch` returns the window ID for an event, routes keyboard +input only to the focused visible window, and rewrites mouse coordinates to be +relative to the recipient. `bob_wm_begin_draw` and `bob_wm_next_dirty` return +visible dirty windows in stacking order; moving, hiding, raising, or destroying +a window requests a safe full redraw, while content invalidation marks the +affected window and overlaps. `bob_gui.h` adds reusable window, button, +popup-menu, single-line text-field, and multiline text-area widgets. +`apps/gui_demo.c` uses the manager for its editor and file-browser windows and +draws only the dirty windows during normal interaction; modal help, launcher, +and menu panels use full redraws. It draws a desktop +with a multiline text editor and file browser. The editor starts with `new.txt` +and `bob!`, supports mouse caret placement, insertion, deletion, Enter for new +lines, arrow/Home/End navigation, vertical movement, mouse-wheel scrolling, +and horizontal scrolling for long lines. Tab cycles through the filename field, +text area, and file browser; Ctrl+S saves the current text file. Press `e` in +the file browser to load the selected text file into the editor, then Ctrl+S to +save changes. The browser immediately lists the saved file and can preview or +delete text files with confirmation. Clicking a window raises it, dragging its +title bar moves it, and Escape returns to the +shell. Dragging is clamped to +the screen edges. A clickable button in Window A focuses Window B. Window B lists guest filesystem entries and previews selected text files; use +`n`/`p` or the mouse to change selection and Up/Down or `u`/`d` to scroll the +preview. Press `x` to show Yes/Cancel controls; click one or press `y`/`n`. +Window B also has a File popup opened with `m` or by clicking its title area; +the menu supports keyboard and mouse selection to open or delete the selected +text file, or close the popup. It follows Window B when dragged and clamps to +the screen edges. 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 @@ -119,14 +198,15 @@ In a native Windows console, the shell supplies editing and redraw itself: | Ctrl+D / Ctrl+Z | End input | Completion operates on the word at the end of the line. Type more characters -when matches are ambiguous. History is session-only, includes failed commands, +when matches are ambiguous. The `history` builtin lists the same four recent +commands. History is session-only, includes failed commands, and skips consecutive duplicates. `edit` opens its own full-screen view in a 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 and names up to 23 characters. bob16 keeps -eight fixed 511-word slots. bob32 packs files into 4,096 words total; text and +eight fixed 511-word slots. bob32 packs files into 8,192 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 @@ -168,6 +248,8 @@ the parent directory must already exist. Messages mention this override. Restoring replaces **all** RAM files; use `save` first if current files matter. An invalid, truncated, corrupt or unreadable snapshot leaves RAM unchanged. The snapshot includes text and program files, not heap allocations or history. +Current bob32 snapshots use B32S v3 for the 8,192-word filesystem; B32S v1 +fixed-slot and v2 packed snapshots remain readable and migrate on restore. Native programs contain kernel helper addresses. If the kernel image differs from the one used to save, restore keeps text and omits binary programs. @@ -330,7 +412,7 @@ 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 +their output can use the remaining shared 8,192-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. @@ -376,8 +458,9 @@ what fits in a single command line; use the resident compiler for larger program | `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 | +| `0xF000..0xFFFF` | bob16 file contents; bob32 scratch space | +| `0x10000..0x1DFFF` | Native bob32 kernel code, globals and strings | +| `0x1E000..0x1FFFF` | Protected packed bob32 filesystem contents | | `0x20000..0xEFFFF` | Supervised native bob32 program entry/code region | | `0xF0000..0xFFFFF` | Native app data and compiler variables; stack starts at `0x100000` | diff --git a/Makefile b/Makefile index 44261cf..b4be13b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ CC ?= gcc +BOB64_CC ?= x86_64-w64-mingw32-gcc CFLAGS ?= -std=gnu11 -O2 -Wall -Wextra -Werror -.PHONY: all c-os test +.PHONY: all c-os test bob64 bob64-test bob64-handoff bob64-handoff-test bob64cc bob64-app-test all: $(CC) $(CFLAGS) tools/build.c -o build-tool @@ -11,3 +12,27 @@ c-os: all test: all ./build-tool --test + +# x86-64 UEFI build, isolated from the bob16/bob32 emulator targets. +bob64: + $(CC) $(CFLAGS) tools/build.c -o build-tool + BOB64_CC="$(BOB64_CC)" ./build-tool --bob64 + +bob64-test: bob64 + BOB64_CC="$(BOB64_CC)" ./build-tool --bob64-test + +# Opt-in destructive-to-firmware-services kernel handoff build. +bob64-handoff: + $(CC) $(CFLAGS) tools/build.c -o build-tool + BOB64_CC="$(BOB64_CC)" ./build-tool --bob64-handoff + +bob64-handoff-test: + $(CC) $(CFLAGS) tools/build.c -o build-tool + BOB64_CC="$(BOB64_CC)" ./build-tool --bob64-handoff-test + +bob64cc: + $(CC) $(CFLAGS) tools/bob64cc.c -o bob64cc + +bob64-app-test: bob64-test bob64cc + BOB64_CC="$(BOB64_CC)" ./bob64cc apps/bob64_smoke.c build/bob64-app/smoke.b64e + ./build/test_bob64 build/bob64/EFI/BOOT/BOOTX64.EFI build/bob64-app/smoke.b64e diff --git a/README.md b/README.md index 1a33a39..500932a 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ regenerate BASM after editing the C kernel, or build the binary boot workflow. The OS has a shell, RAM files, allocation, program loading, and a resident C compiler. Its tools are written in C; no Python is required. +An experimental x86-64 UEFI target is built separately with `build-tool --bob64`; +see [the bob64 migration status](BOB64_MIGRATION.md). It does not replace the +existing custom-CPU bob16/bob32 emulator. + extremely simple custom 16 bit cpu emulator and assembler as seen on youtube: https://youtu.be/tlIqosU75CQ?is=ZAVWsYRDMPrUKOej \ use at your own risk! code is thoroughly untested so if you find any bugs let me know asap so i can fix them asap diff --git a/apps/README.md b/apps/README.md new file mode 100644 index 0000000..8dc2c29 --- /dev/null +++ b/apps/README.md @@ -0,0 +1,111 @@ +# Native bob32 applications + +Build an application from the repository root: + +```text +gcc -E -P -nostdinc -undef -I kernel apps/notes.c -o build/notes.i +build/bobcc build/notes.i build/notes.basm build/notes.b32 --wide-app +``` + +Use the same two build commands with `apps/graphics_demo.c` and the +`build/graphics_demo` output names to build the interactive canvas example. +Import it once as `graphics`, then run `run graphics`; it waits for a key and +returns to the shell. + +Build `apps/gui_demo.c` the same way to try the desktop prototype. The larger +editor starts with `new.txt` and `bob!` in a filename field and multiline text +area. Click either field to place the caret, or use Tab to cycle through the +filename, text-area, and file-browser focus. In the browser, select a text file +and press `e` to load it; Ctrl+S saves the text back to the guest filesystem. +Enter inserts a newline. Escape returns to the shell. On a Windows console, +click a window to raise and focus it or drag its title bar to move it. +`kernel/bob_wm.h` is the shared window manager used by the GUI demo. It owns +fixed-capacity window records, focus, stacking, hit testing, title-bar drag +capture, event routing, screen clamping, and dirty redraw tracking. Apps provide +the manager's fixed storage arrays and use `bob_wm_dispatch` to route an event; +the returned window ID identifies its recipient, and mouse coordinates in the +routed event are window-local. Call `bob_wm_invalidate` when application content +changes, then draw IDs returned by `bob_wm_next_dirty` in stacking order. +`kernel/bob_gui.h` contains reusable window-frame, button, menu, single-line +text-field, and multiline text-area widgets. Drawn windows have framed borders +and a distinct title strip. +The `bob_gui_button_draw` and `bob_gui_button_event` helpers provide a reusable +clickable button with hover and pressed states. The demo button focuses Window +B on a left click, and the bob32 test suite exercises hit-testing, dragging, +left-button activation, and release-outside behavior with synthetic events. +Overlapping-window hit-testing and raising are also tested. +The text-field helpers support click-to-position, insertion, Backspace/Delete, +arrow/Home/End navigation, caret drawing, and horizontal scrolling. The text +area supports multiline insertion, vertical movement with column preservation, +click-to-position, caret visibility, and mouse-wheel scrolling. Native bob32 +fixtures check text and cursor state, including wheel-scroll bounds. +The popup menu has fixed-stride labels, keyboard selection, Enter/Escape, and +mouse hover/click activation. Window B opens it from the File title area or +with `m`; its actions open the selected text file, start delete confirmation, +or close the menu. Popup placement follows Window B when it is dragged and +clamps the menu inside the 80x25 screen; widget tests cover edge and invalid +screen placements. +Window B lists guest filesystem entries and previews the selected text file; +`n`/`p` and mouse clicks change the selection, while Up/Down or `u`/`d` scroll +the preview. On Windows, the mouse wheel scrolls the editor or preview and +changes file selection when over the list. Press `x` to open an +on-screen Yes/Cancel prompt; click a button +or press `y`/`n` to confirm or cancel. +The GUI integration test creates a long `gui.txt`, scrolls beyond the initial +preview, checks a unique trailing marker, confirms deletion, and verifies the +file can no longer be read. It also creates `new.txt` from the GUI, snapshots +the guest filesystem, restores it in a second emulator process, and reads the +saved contents with `cat`. A separate integration test loads a two-line text +file, edits and saves it through the GUI, then checks the saved newline and text +with `cat`. + +Start the bob32 OS, import the image, and use it from the guest filesystem: + +```text +import32 build/notes.b32 notes +run notes put journal "bob! a saved note" +run notes edit journal "bob! updated note" +run notes add journal "another line" +run notes show journal +ls +save +``` + +`notes edit NAME [TEXT]` creates or replaces a text note, while +`notes add NAME [TEXT]` appends a line (or prompts for one). `notes` protects +binary and executable files from note-specific commands. It also supports +`run notes delete journal`. The `echo` app prints its +arguments, `ls` lists guest files and their kinds/sizes, and `cat FILE` displays +a text file. `sysinfo` reports application memory, filesystem usage, display +dimensions, and keyboard/mouse availability. Import +each image once; the application and its data are preserved by B32S snapshots. +`cat FILE` preserves existing trailing newlines and only adds a line break when +nonempty file contents have no final newline. + +Build `apps/launcher.c` with the same commands to list stored native apps or +start one with arguments. For example, `run launcher echo "a saved note"` +starts `echo` as a child app and reports its exit code. Native apps can call +`bob_app_run(name, arguments, &exit_code)` from `bob_process.h` directly. +The GUI demo also has a small application-launcher panel: focus Window B and +press `a`, choose a stored app with `n`/`p` or the arrow keys, and press `r` or +click Launch. The desktop resumes and displays the child exit status. +Press `?` for a bitmap-font help overlay with the desktop shortcuts; Escape or +its Close button returns to the desktop. Launcher and help panels clear the +desktop canvas behind them so their contents remain readable. + +`graphics_demo` uses the version 1 `bob_gfx.h` canvas API. Its first backend is +an 80x25 character-cell framebuffer with colors, filled rectangles, lines, +text, transparent bitmap cells (including per-cell colors), and explicit presentation. The same app can +later target a pixel renderer without changing its draw calls. +Include `bob_font.h` when an app needs the opt-in 5x7 bitmap text renderer. +The demo waits through `bob_event.h`, a blocking event interface that currently +normalizes typed characters, special-key presses/releases, mouse movement, and +mouse-button transitions when the Windows console provides those records. + +Apps use `bob_fs.h` for guest file operations and `bob_string.h` for string and +number helpers. The filesystem service has a versioned request protocol and +keeps guest RAM tables private from application code. +`bob_event.h` provides blocking wait and nonblocking poll operations, while +`bob_event_queue.h` provides an optional caller-owned FIFO when an app needs to +buffer or defer events. A full queue reports overflow without dropping an +earlier event. diff --git a/apps/bob64_demo.c b/apps/bob64_demo.c new file mode 100644 index 0000000..09a8894 --- /dev/null +++ b/apps/bob64_demo.c @@ -0,0 +1,4 @@ +int main(void) { + bob64_app_write("bob!", 4); + return 0; +} diff --git a/apps/bob64_display.c b/apps/bob64_display.c new file mode 100644 index 0000000..7c60f9f --- /dev/null +++ b/apps/bob64_display.c @@ -0,0 +1,28 @@ +#include "../bob64/app.h" + +#define DISPLAY_LIMIT_WIDTH 1024u +#define DISPLAY_LIMIT_HEIGHT 768u + +static u32 pixels[DISPLAY_LIMIT_WIDTH*DISPLAY_LIMIT_HEIGHT]; + +s64 bob64_app_main(const BOB64_APP_STARTUP *startup) { + u32 width,height; + BOB64_EVENT event; + if(!startup||startup->AbiVersion!=BOB64_APP_ABI_VERSION|| + bob64_app_query_abi()!=BOB64_SYSCALL_ABI_VERSION|| + bob64_app_get_display(&width,&height))return -1; + if(!width||!height||width>DISPLAY_LIMIT_WIDTH||height>DISPLAY_LIMIT_HEIGHT) + return -2; + for(u32 y=0;y=BOB64_GUI_MAX_WINDOWS||surface_allocations[slot].Used||!width||!height|| + (u64)width*height>BOB64_GUI_SURFACE_PIXEL_CAPACITY)return 0; + bytes=(usize)width*height*sizeof(u32); + for(;;) { + usize next=sizeof(pixels); + int next_slot=-1; + for(u32 i=0;i=candidate&& + surface_allocations[i].Offset=sizeof(pixels))return 0; + } + if(candidate>sizeof(pixels)||bytes>sizeof(pixels)-candidate)return 0; + surface_allocations[slot].Offset=candidate; + surface_allocations[slot].Bytes=bytes; + surface_allocations[slot].Used=1; + return pixels+candidate/sizeof(u32); +} + +static void gui_surface_release(u32 slot) { + if(slot>=BOB64_GUI_MAX_WINDOWS)return; + surface_allocations[slot].Offset=0;surface_allocations[slot].Bytes=0; + surface_allocations[slot].Used=0; +} + +static BOB64_WINDOW_HANDLE gui_create_window(s32 x,s32 y,u32 width,u32 height, + const char *title) { + BOB64_WINDOW_HANDLE kernel_handle; + BOB64_WINDOW_HANDLE app_handle; + BOB64_WINDOW *window; + u32 slot=0; + u32 *surface; + while(slot=BOB64_GUI_MAX_WINDOWS||!(surface=gui_surface_allocate(slot,width,height))) + return 0; + kernel_handle=bob64_app_window_create(x,y,width,height); + if(!kernel_handle||(s64)kernel_handle<0) { + gui_surface_release(slot);return 0; + } + manager.NextHandle=kernel_handle; + app_handle=bob64_wm_create(&manager,x,y,width,height,(void *)title); + if(app_handle!=kernel_handle) { + if(app_handle)bob64_wm_destroy(&manager,app_handle); + bob64_app_window_destroy(kernel_handle);gui_surface_release(slot);return 0; + } + window=bob64_wm_find(&manager,app_handle); + slot=(u32)(window-windows); + graphics[slot].Pixels=surface;graphics[slot].Width=width; + graphics[slot].Height=height; + graphics[slot].Capacity=(usize)BOB64_GUI_MAX_WIDTH*BOB64_GUI_MAX_HEIGHT; + return app_handle; +} + +static int gui_destroy_window(BOB64_WINDOW_HANDLE handle) { + u32 slot=0; + while(slot=BOB64_GUI_MAX_WINDOWS)return -1; + if(bob64_app_window_destroy(handle))return -1; + if(bob64_wm_destroy(&manager,handle))return -1; + gui_surface_release(slot); + return 0; +} + +static void gui_focus_window(BOB64_WINDOW_HANDLE handle) { + if(bob64_wm_focus(&manager,handle)||bob64_app_window_focus(handle)) + gui_copy(editor_status,"FOCUS FAILED",sizeof("FOCUS FAILED")); +} + +static int gui_load_file(const BOB64_APP_STARTUP *startup) { + const char *requested="notes.txt"; + usize length=sizeof("notes.txt")-1; + s64 result; + if(startup->ArgumentCount>1) { + requested=startup->Arguments[1]; + length=gui_length(requested,BOB64_GUI_FILENAME_CAPACITY); + if(!length||length>=BOB64_GUI_FILENAME_CAPACITY)return -1; + } + for(usize i=0;i='a'&&value<='z')||(value>='A'&&value<='Z')|| + (value>='0'&&value<='9')||value=='.'||value=='_'||value=='-'))return -1; + } + gui_copy(filename,requested,length); + result=bob64_app_read_file(filename,length,editor.Text,BOB64_EDITOR_CAPACITY); + if(result==-2) { + bob64_editor_init(&editor,0,0); + gui_copy(editor_status,"NEW FILE",sizeof("NEW FILE")); + editor_save_allowed=1; + } else if(result==-28) { + bob64_editor_init(&editor,0,0); + gui_copy(editor_status,"FILE TOO LARGE",sizeof("FILE TOO LARGE")); + editor_save_allowed=0; + } else if(result<0) { + return -1; + } else { + bob64_editor_init(&editor,editor.Text,(u32)result); + gui_copy(editor_status,"LOADED",sizeof("LOADED")); + editor_save_allowed=1; + } + return 0; +} + +static void gui_refresh_files(void) { + s64 result=bob64_app_list_files(file_entries,BOB64_SYSCALL_MAX_FILES); + if(result<0) { + file_count=0; + gui_copy(editor_status,result==-28?"TOO MANY FILES":"LIST FAILED", + result==-28?sizeof("TOO MANY FILES"):sizeof("LIST FAILED")); + return; + } + file_count=(u32)result; + if(selected_file>=file_count)selected_file=file_count?file_count-1:0; + if(file_scroll>=file_count)file_scroll=file_count?file_count-1:0; +} + +static void gui_reveal_selected_file(void) { + BOB64_WINDOW *window=bob64_wm_find(&manager,files_window); + u32 rows=window&&window->Height>58?(window->Height-58)/14:1; + if(!rows)rows=1; + if(selected_file=file_scroll+rows)file_scroll=selected_file-rows+1; +} + +static int gui_name_equal(const char *left,const char *right) { + while(*left&&*right&&*left==*right){left++;right++;} + return !*left&&!*right; +} + +static void gui_open_selected_file(void) { + s64 result; + if(selected_file>=file_count) { + gui_copy(editor_status,"NO FILE SELECTED",sizeof("NO FILE SELECTED"));return; + } + const char *name=file_entries[selected_file].Name; + if(editor.Dirty&&!editor_open_armed) { + gui_copy(editor_status,"OPEN AGAIN TO DISCARD",sizeof("OPEN AGAIN TO DISCARD")); + editor_open_armed=1;return; + } + if(gui_name_equal(name,filename)) { + gui_focus_window(editor_window); + gui_copy(editor_status,"CURRENT FILE",sizeof("CURRENT FILE")); + editor_open_armed=0;return; + } + result=bob64_app_read_file(name,gui_length(name,BOB64_GUI_FILENAME_CAPACITY), + editor.Text,BOB64_EDITOR_CAPACITY); + if(result==-28) { + gui_copy(editor_status,"FILE TOO LARGE",sizeof("FILE TOO LARGE")); + editor_save_allowed=0;return; + } + if(result<0) { + gui_copy(editor_status,"OPEN FAILED",sizeof("OPEN FAILED"));return; + } + gui_copy(filename,name,gui_length(name,BOB64_GUI_FILENAME_CAPACITY)); + bob64_editor_init(&editor,editor.Text,(u32)result); + editor_save_allowed=1;editor_open_armed=0; + gui_copy(editor_status,"LOADED",sizeof("LOADED")); + gui_focus_window(editor_window); +} + +static void gui_delete_selected_file(void) { + const char *name; + s64 result; + if(selected_file>=file_count) { + gui_copy(editor_status,"NO FILE SELECTED",sizeof("NO FILE SELECTED"));return; + } + name=file_entries[selected_file].Name; + if(gui_name_equal(name,filename)) { + file_delete_armed=0; + gui_copy(editor_status,"SAVE OR OPEN OTHER FILE",sizeof("SAVE OR OPEN OTHER FILE")); + return; + } + if(!file_delete_armed) { + file_delete_armed=1; + gui_copy(editor_status,"D AGAIN TO DELETE",sizeof("D AGAIN TO DELETE")); + return; + } + result=bob64_app_delete_file(name,gui_length(name,BOB64_GUI_FILENAME_CAPACITY)); + file_delete_armed=0; + if(result)gui_copy(editor_status,"DELETE FAILED",sizeof("DELETE FAILED")); + else {gui_refresh_files();gui_copy(editor_status,"DELETED",sizeof("DELETED"));} +} + +static void gui_draw_window(const BOB64_WINDOW *window,int focused) { + BOB64_WINDOW local=*window; + BOB64_GFX *graphics; + local.X=0;local.Y=0;window=&local; + graphics=gui_graphics_for_handle(window->Handle); + if(!graphics)return; + const char *title=(const char *)window->Context; + u32 border=focused?0x00a4c8ffu:0x006d8095u; + u32 title_bar=focused?0x00335d8cu:0x00334050u; + bob64_gfx_fill_rect(graphics,window->X,window->Y,window->Width, + window->Height,0x0009111bu); + bob64_gfx_fill_rect(graphics,window->X+2,window->Y+2,window->Width-4, + window->Height-4,0x001a2a3cu); + bob64_gfx_fill_rect(graphics,window->X,window->Y,window->Width, + BOB64_WINDOW_TITLE_BAR_HEIGHT,title_bar); + bob64_gfx_line(graphics,window->X,window->Y, + window->X+(s32)window->Width-1,window->Y,border); + bob64_gfx_line(graphics,window->X,window->Y+(s32)window->Height-1, + window->X+(s32)window->Width-1, + window->Y+(s32)window->Height-1,border); + bob64_gfx_line(graphics,window->X,window->Y,window->X, + window->Y+(s32)window->Height-1,border); + bob64_gfx_line(graphics,window->X+(s32)window->Width-1,window->Y, + window->X+(s32)window->Width-1, + window->Y+(s32)window->Height-1,border); + bob64_gfx_text(graphics,window->X+12,window->Y+8,title,0x00ffffffu,1); + if(window->Handle==editor_window) { + u32 columns=(window->Width-24)/6; + u32 rows=(window->Height-76)/10; + u32 column=0,row=0; + u32 cursor_row,cursor_column; + s32 text_x=window->X+12,text_y=window->Y+46; + int caret_visible=0; + if(columns==0)columns=1; + bob64_editor_visual_position(&editor,columns,&cursor_row,&cursor_column); + (void)cursor_column; + if(cursor_row=editor.ScrollRow+rows) + editor.ScrollRow=cursor_row-rows+1; + bob64_gfx_text(graphics,window->X+12,window->Y+30,filename, + 0x009eb3c7u,1); + for(u32 i=0;i<=editor.Length;i++) { + if(column>=columns&&(i==editor.Length||editor.Text[i]!='\n')) { + row++;column=0; + } + if(i==editor.Cursor) { + s32 caret_x=text_x+(s32)(column*6); + s32 caret_y=text_y+(s32)((row-editor.ScrollRow)*10); + if(row>=editor.ScrollRow&&row=editor.ScrollRow&&row=editor.ScrollRow&&rowX+8, + window->Y+(s32)window->Height-22, + window->X+(s32)window->Width-8, + window->Y+(s32)window->Height-22,0x0044576au); + bob64_gfx_text(graphics,window->X+12, + window->Y+(s32)window->Height-16,editor_status,0x008fc8ffu,1); + bob64_gfx_text(graphics,window->X+(s32)window->Width/2, + window->Y+(s32)window->Height-16,"CTRL S SAVE",0x009eb3c7u,1); + } else if(window->Handle==files_window) { + u32 rows=window->Height>58?(window->Height-58)/14:0; + bob64_gfx_text(graphics,window->X+10,window->Y+31, + "UP DOWN OPEN R REFRESH",0x009eb3c7u,1); + bob64_gfx_text(graphics,window->X+10,window->Y+41, + "D TWICE DELETE",0x009eb3c7u,1); + bob64_gfx_text(graphics,window->X+10,window->Y+49,editor_status, + 0x008fc8ffu,1); + for(u32 row=0;rowY+56+(s32)(row*14); + if(index==selected_file) + bob64_gfx_fill_rect(graphics,window->X+6,y-2, + window->Width-12,12,0x00335d8cu); + bob64_gfx_text(graphics,window->X+10,y, + file_entries[index].Name,index==selected_file? + 0x00ffffffu:0x00dbe8f4u,1); + } + if(!file_count)bob64_gfx_text(graphics,window->X+10,window->Y+60, + "NO FILES",0x008fc8ffu,1); + } else if(window->Handle==manager.Focused) { + bob64_gfx_text(graphics,window->X+14,window->Y+46, + "BOB64 DESKTOP",0x007ed6ffu,1); + bob64_gfx_text(graphics,window->X+14,window->Y+66, + "RUN DESKTOP B64E FILE",0x00dbe8f4u,1); + bob64_gfx_text(graphics,window->X+14,window->Y+84, + "TAB SWITCH WINDOWS",0x00dbe8f4u,1); + bob64_gfx_text(graphics,window->X+14,window->Y+102, + "ESC RETURN TO SHELL",0x00dbe8f4u,1); + bob64_gfx_text(graphics,window->X+14,window->Y+120, + "N NEW X CLOSE OTHER",0x00dbe8f4u,1); + } else { + bob64_gfx_text(graphics,window->X+14,window->Y+46, + "DRAG WINDOW TITLE",0x00dbe8f4u,1); + } +} + +static int gui_draw(s32 cursor_x,s32 cursor_y) { + for(u32 i=0;iFlags&BOB64_WINDOW_VISIBLE))continue; + surface=gui_graphics_for_handle(window->Handle); + if(!surface)continue; + bob64_gfx_fill_rect(surface,0,0,surface->Width,surface->Height, + 0x000d1723u); + for(u32 y=0;yHeight;y+=4) + bob64_gfx_line(surface,0,(s32)y,(s32)surface->Width-1,(s32)y, + 0x00132130u); + gui_draw_window(window,window->Handle==manager.Focused); + if(cursor_x>=window->X&&cursor_y>=window->Y&& + (u32)(cursor_x-window->X)Width&& + (u32)(cursor_y-window->Y)Height) { + s32 x=cursor_x-window->X,y=cursor_y-window->Y; + bob64_gfx_line(surface,x-5,y,x+5,y,0x00000000u); + bob64_gfx_line(surface,x,y-5,x,y+5,0x00000000u); + bob64_gfx_line(surface,x-3,y,x+3,y,0x00ffffffu); + bob64_gfx_line(surface,x,y-3,x,y+3,0x00ffffffu); + } + if(bob64_app_window_present(window->Handle,surface->Pixels, + surface->Width,surface->Height)!=(s64)((u64)surface->Width*surface->Height)) + return -1; + } + return 0; +} + +static void gui_save_editor(void) { + if(!editor_save_allowed) { + gui_copy(editor_status,"FILE TOO LARGE",sizeof("FILE TOO LARGE")); + return; + } + s64 result=bob64_app_write_file(filename,gui_length(filename, + BOB64_GUI_FILENAME_CAPACITY),editor.Text,editor.Length); + if(result==(s64)editor.Length) { + editor.Dirty=0;gui_copy(editor_status,"SAVED",sizeof("SAVED")); + } else gui_copy(editor_status,"SAVE FAILED",sizeof("SAVE FAILED")); +} + +static void gui_editor_place_cursor(u32 target_row,u32 target_column,u32 columns) { + u32 row=0,column=0; + if(!columns)columns=1; + target_row+=editor.ScrollRow; + for(u32 i=0;i<=editor.Length;i++) { + if(column>=columns&&(i==editor.Length||editor.Text[i]!='\n')) { + row++;column=0; + } + if(row==target_row&&column>=target_column) { + editor.Cursor=i;return; + } + if(i==editor.Length)break; + if(editor.Text[i]=='\n') { + if(row==target_row){editor.Cursor=i;return;} + row++;column=0;continue; + } + column++; + } + editor.Cursor=editor.Length; +} + +static void gui_focus_next(void) { + if(!manager.Count)return; + u32 start=0; + for(u32 i=0;iFlags&BOB64_WINDOW_VISIBLE)) { + gui_focus_window(handle);return; + } + } +} + +static void gui_key(const BOB64_EVENT *event) { + if(event->Type!=BOB64_EVENT_KEY_DOWN)return; + if(event->Character=='\t')gui_focus_next(); + else if(manager.Focused==files_window) { + if(event->Key==(BOB64_EVENT_KEY_EXTENDED|0x48)) { + if(selected_file)selected_file--; + gui_reveal_selected_file(); + file_delete_armed=editor_open_armed=0; + } else if(event->Key==(BOB64_EVENT_KEY_EXTENDED|0x50)) { + if(selected_file+1Character=='r'||event->Character=='R') { + gui_refresh_files();file_delete_armed=editor_open_armed=0; + } else if(event->Character=='o'||event->Character=='O'|| + event->Character=='\n')gui_open_selected_file(); + else if(event->Character=='d'||event->Character=='D')gui_delete_selected_file(); + else file_delete_armed=editor_open_armed=0; + } + else if(event->Character=='n'&&manager.CountCharacter=='x'&&manager.Count>1&&manager.Focused!=editor_window) { + if(gui_destroy_window(manager.Focused)) + gui_copy(editor_status,"WINDOW CLOSE FAILED",sizeof("WINDOW CLOSE FAILED")); + } + else if(manager.Focused==editor_window) { + if((event->Modifiers&BOB64_EVENT_MOD_CONTROL)&& + (event->Character=='s'||event->Character=='S'))gui_save_editor(); + else bob64_editor_handle_key(&editor,event); + } +} + +s64 bob64_app_main(const BOB64_APP_STARTUP *startup) { + BOB64_EVENT event; + BOB64_EVENT routed; + BOB64_EVENT screen_event; + s32 cursor_x,cursor_y; + if(!startup||startup->AbiVersion!=BOB64_APP_ABI_VERSION|| + bob64_app_query_abi()!=BOB64_SYSCALL_ABI_VERSION)return -1; + if(bob64_app_write("bob!",4)!=4)return -3; + if(bob64_app_get_display(&screen_width,&screen_height))return -6; + if(screen_width<480||screen_height<300||screen_width>BOB64_GUI_MAX_WIDTH|| + screen_height>BOB64_GUI_MAX_HEIGHT)return -7; + if(bob64_wm_init(&manager,windows,BOB64_GUI_MAX_WINDOWS,order, + screen_width,screen_height))return -8; + if(gui_load_file(startup))return -9; + gui_refresh_files(); + cursor_x=(s32)(screen_width/2);cursor_y=(s32)(screen_height/2); + if(!gui_create_window(8,24,screen_width/3,screen_height-32,titles[0])|| + !gui_create_window((s32)(screen_width/3+16),24, + screen_width-screen_width/3-24,screen_height-32,titles[1]))return -2; + files_window=manager.ZOrder[0]; + editor_window=manager.Focused; + for(;;) { + if(gui_draw(cursor_x,cursor_y))return -4; + if(bob64_app_wait_event(&event))return -5; + if(event.Type==BOB64_EVENT_KEY_DOWN&&event.Character==0x1b) { + if(editor.Dirty&&!editor_exit_armed) { + gui_copy(editor_status,"ESC AGAIN TO QUIT",sizeof("ESC AGAIN TO QUIT")); + editor_exit_armed=1;continue; + } + break; + } + if(event.Type==BOB64_EVENT_KEY_DOWN)editor_exit_armed=0; + if(event.Type==BOB64_EVENT_MOUSE_MOVE||event.Type==BOB64_EVENT_MOUSE_BUTTON|| + event.Type==BOB64_EVENT_MOUSE_WHEEL) + cursor_x=event.ScreenX,cursor_y=event.ScreenY; + screen_event=event;screen_event.X=event.ScreenX;screen_event.Y=event.ScreenY; + bob64_wm_dispatch(&manager,&screen_event,&routed); + if(event.Type==BOB64_EVENT_MOUSE_BUTTON&&(event.Buttons&1u)&& + manager.Focused==files_window&&routed.X>=8&&routed.Y>=56) { + u32 row=(u32)(routed.Y-56)/14; + if(file_scroll+row=12&&routed.Y>=46) { + BOB64_WINDOW *window=bob64_wm_find(&manager,editor_window); + if(window)gui_editor_place_cursor((u32)(routed.Y-46)/10, + (u32)(routed.X-12)/6,(window->Width-24)/6); + } + gui_key(&event); + if(editor.Dirty)gui_copy(editor_status,"UNSAVED",sizeof("UNSAVED")); + } + return 0; +} diff --git a/apps/bob64_smoke.c b/apps/bob64_smoke.c new file mode 100644 index 0000000..9d3439b --- /dev/null +++ b/apps/bob64_smoke.c @@ -0,0 +1,33 @@ +#include "../bob64/app.h" +#include "../bob64/libc.h" + +s64 bob64_app_main(const BOB64_APP_STARTUP *startup) { + static const char message[]="bob!"; + static const char file_name[]="bob-app.txt"; + static const char stream_name[]="bob-stream.txt"; + static const char file_data[]="written by a C app"; + char file_copy[32]; + if(!startup||startup->AbiVersion!=BOB64_APP_ABI_VERSION)return -1; + if(bob64_app_query_abi()!=BOB64_SYSCALL_ABI_VERSION)return -2; + u64 ticks_before=bob64_app_ticks(); + if(bob64_app_write(message,sizeof(message)-1)!=(s64)(sizeof(message)-1))return -3; + if(bob64_app_write_file(file_name,sizeof(file_name)-1,file_data, + sizeof(file_data)-1)!=(s64)(sizeof(file_data)-1))return -4; + s64 copied=bob64_app_read_file(file_name,sizeof(file_name)-1,file_copy, + sizeof(file_copy)); + if(copied!=(s64)(sizeof(file_data)-1))return -5; + if(bob64_memcmp(file_copy,file_data,sizeof(file_data)-1))return -6; + s64 handle=bob64_app_file_open(stream_name,sizeof(stream_name)-1, + BOB64_FILE_OPEN_READ|BOB64_FILE_OPEN_WRITE|BOB64_FILE_OPEN_CREATE| + BOB64_FILE_OPEN_TRUNCATE); + if(handle<=0)return -7; + if(bob64_app_file_write(handle,file_data,sizeof(file_data)-1)!= + (s64)(sizeof(file_data)-1))return -8; + if(bob64_app_file_seek(handle,0)!=0)return -9; + copied=bob64_app_file_read(handle,file_copy,sizeof(file_copy)); + if(copied!=(s64)(sizeof(file_data)-1)|| + bob64_memcmp(file_copy,file_data,sizeof(file_data)-1))return -10; + if(bob64_app_file_close(handle))return -11; + if(bob64_app_ticks()0&&text[length-1]!='\n')bob_putc('\n'); + return 0; +} diff --git a/apps/echo.c b/apps/echo.c new file mode 100644 index 0000000..4974af5 --- /dev/null +++ b/apps/echo.c @@ -0,0 +1,15 @@ +#include "bob.h" + +static void write_text(const char *text) { + while (*text) bob_putc(*text++); +} + +int main(int argc, char **argv) { + int i; + for (i = 1; i < argc; i++) { + if (i > 1) bob_putc(' '); + write_text(argv[i]); + } + bob_putc('\n'); + return 0; +} diff --git a/apps/graphics_demo.c b/apps/graphics_demo.c new file mode 100644 index 0000000..0878598 --- /dev/null +++ b/apps/graphics_demo.c @@ -0,0 +1,31 @@ +#include "bob.h" +#include "bob_gfx.h" +#include "bob_event.h" + +int main(void) { + int resolution[2]; + int event[4]; + char bitmap[8] = {'/', '-', '\\', '|', '\\', '-', '/', '|'}; + if (bob_gfx_enter()) return 1; + if (bob_gfx_resolution(resolution) != 2 || resolution[0] != 80 || resolution[1] != 25) { + bob_gfx_leave(); + return 2; + } + bob_gfx_clear(' ', 0); + bob_gfx_fill_rect(1, 1, 78, 23, '.', 1); + bob_gfx_fill_rect(2, 2, 76, 3, ' ', 4); + bob_gfx_text(4, 3, "BOB32 GRAPHICS DEMO", 15); + bob_gfx_line(3, 7, 76, 7, '=', 14); + bob_gfx_pixel(40, 16, '*', 10); + bob_gfx_fill_rect(8, 10, 12, 5, '#', 2); + bob_gfx_blit(28, 10, 4, 2, bitmap, 12); + bob_gfx_text(4, 19, "Press any key to return to the shell", 15); + if (bob_gfx_present()) { bob_gfx_leave(); return 3; } + if (bob_event_wait(event) != 1 || event[0] != BOB_EVENT_CHAR || event[1] != 'x') { + bob_gfx_leave(); + return 4; + } + if (bob_gfx_leave()) return 5; + bob_puts("bob!"); + return 0; +} diff --git a/apps/gui_demo.c b/apps/gui_demo.c new file mode 100644 index 0000000..b3200be --- /dev/null +++ b/apps/gui_demo.c @@ -0,0 +1,462 @@ +#include "bob.h" +#include "bob_gfx.h" +#include "bob_font.h" +#include "bob_event.h" +#include "bob_gui.h" +#include "bob_fs.h" +#include "bob_process.h" +#include "bob_string.h" + +static void gui_select_file(int row,const int *slots,int count,int *selected, + char *status,char *preview,int *preview_length,int *preview_scroll) { + int size,kind;char name[24],size_text[12]; + if(row<0||row>=count)return; + *selected=row; + kind=bob_file_list(slots[row],name,24,&size); + bob_format_int(size,size_text,12); + bob_strcpy(status,name);bob_strcat(status," ");bob_strcat(status,size_text); + preview[0]=0;*preview_length=-1;*preview_scroll=0; + if(kind==0)*preview_length=bob_file_read(name,preview,512); +} + +static int gui_preview_offset(const char *preview,int length,int lines) { + int position=0,column; + while(lines>0&&position=count)return -1; + kind=bob_file_list(slots[row],name,24,&size); + if(kind!=0)return -1; + return bob_file_delete(name); +} + +static void gui_wm_sync_rects(int *rects,const int *managed) { + for(int id=0;id<2;id++)for(int i=0;i<4;i++) + rects[id*4+i]=managed[id*BOB_WM_WINDOW_WORDS+i]; +} + +static void gui_place_editor_widgets(int *windows,int *name_field,int *text_area,int *button) { + int *rect=windows; + name_field[0]=rect[0]+2;name_field[1]=rect[1]+5; + text_area[0]=rect[0]+2;text_area[1]=rect[1]+9; + button[0]=rect[0]+3;button[1]=rect[1]+16; +} + +static int gui_open_selected_text(int row,const int *slots,int count,char *name, + char *filename,char *text,int *text_state,const int *text_area, + int *wm_state,int *wm_windows,int *wm_order,char *status) { + int size,kind,length; + if(row<0||row>=count){bob_strcpy(status,"Select a text file.");return 0;} + kind=bob_file_list(slots[row],name,24,&size); + if(kind!=BOB_FILE_KIND_TEXT){bob_strcpy(status,"Text files only.");return 0;} + length=bob_file_read(name,text,512); + if(length<0){bob_strcpy(status,"Could not read file.");return 0;} + bob_strcpy(filename,name); + bob_gui_text_area_init(text,text_state,512); + bob_gui_text_area_reveal(text,text_state,text_area); + text_state[0]=1;bob_wm_focus(wm_state,wm_windows,wm_order,0); + bob_strcpy(status,"Editing selected file."); + return 1; +} + +static void gui_launch_app(int row,const char *names,int count,char *message) { + char number[12]; + int child_status=-1,status; + if(row<0||row>=count){bob_strcpy(message,"No app selected.");return;} + status=bob_app_run(names+row*24,"",&child_status); + if(status==-1)bob_strcpy(message,"App not found."); + else if(status==-2)bob_strcpy(message,"Not a native app."); + else if(status==-4)bob_strcpy(message,"Invalid app image."); + else if(status==-5)bob_strcpy(message,"Not enough memory."); + else if(status<0)bob_strcpy(message,"App launch failed."); + else { + bob_strcpy(message,"App exit ");bob_format_int(child_status,number,12); + bob_strcat(message,number); + } +} + +int main(void) { + int event[4]; + int mouse_x=-1; + int mouse_y=-1; + int wm_state[10]; + int wm_windows[14]; + int wm_order[2]; + int routed_event[4]; + int target_window=-1; + int redraw_full=0; + int overlay_was_open=0; + int draw_id=-1; + int windows[8]; + int button[4]={6,19,31,3}; + int button_state[2]={0,0}; + int delete_yes[4]={43,17,13,3}; + int delete_no[4]={59,17,13,3}; + int delete_yes_state[2]={0,0}; + int delete_no_state[2]={0,0}; + int name_field[4]={5,8,33,3}; + int text_area[4]={5,12,33,7}; + int name_state[3]; + int text_state[4]; + int length_b=0; + int file_slots[8]; + char app_names[192]; + int app_count=0; + int app_selected=0; + int launcher_open=0; + int help_open=0; + int help_close[4]={32,18,16,3}; + int help_close_state[2]={0,0}; + int launch_button[4]={42,18,16,3}; + int close_button[4]={22,18,14,3}; + int launch_button_state[2]={0,0}; + int close_button_state[2]={0,0}; + int file_count=0; + int selected_file=-1; + int selection_initialized=0; + int file_scroll=0; + int delete_confirm=0; + int menu_open=0; + int menu_rect[4]={43,7,30,5}; + int menu_state[2]={0,-1}; + int file_size; + int file_kind; + int preview_length=-1; + int preview_scroll=0; + int preview_row,preview_column,preview_position; + char preview[512]; + char preview_line[35]; + char file_name[24]; + char file_name_text[24]="new.txt"; + char file_text[512]="bob!"; + char message_b[32]=""; + char menu_items[72]; + int running=1; + bob_strcpy(message_b,"N/P select; E edit; X delete"); + bob_strcpy(menu_items,"Open selected text"); + bob_strcpy(menu_items+24,"Delete selected"); + bob_strcpy(menu_items+48,"Close menu"); + bob_gui_text_field_init(file_name_text,name_state,24); + bob_gui_text_area_init(file_text,text_state,512); + name_state[0]=1; + if(bob_wm_init(wm_state,wm_windows,wm_order,2,80,25))return 1; + if(bob_wm_create(wm_state,wm_windows,wm_order,3,3,37,20)!=0|| + bob_wm_create(wm_state,wm_windows,wm_order,41,3,37,20)!=1)return 1; + bob_wm_focus(wm_state,wm_windows,wm_order,0); + if(bob_gfx_enter())return 1; + while(running) { + gui_wm_sync_rects(windows,wm_windows); + gui_place_editor_widgets(windows,name_field,text_area,button); + bob_gui_menu_place(menu_rect,windows[4]+2,windows[5]+4,30,3,80,25); + file_count=0; + app_count=0; + for(int i=0;i<8;i++) { + file_kind=bob_file_list(i,file_name,24,&file_size); + if(file_kind>=0)file_slots[file_count++]=i; + if(file_kind==BOB_FILE_KIND_NATIVE_APP) { + bob_strcpy(app_names+app_count*24,file_name);app_count++; + } + } + if(app_selected>=app_count)app_selected=app_count?app_count-1:0; + if(!selection_initialized&&file_count>0) { + gui_select_file(0,file_slots,file_count,&selected_file,message_b,preview,&preview_length,&preview_scroll); + selection_initialized=1; + } + if(selected_file>=file_count) { + selected_file=-1;preview_length=-1;preview_scroll=0;delete_confirm=0; + bob_strcpy(message_b,"Selection changed."); + } + if(file_scroll>file_count-6)file_scroll=file_count>6?file_count-6:0; + if(selected_file>=0) { + if(selected_file=file_scroll+6)file_scroll=selected_file-5; + } + if(menu_open||launcher_open||help_open||overlay_was_open)wm_state[8]=1; + redraw_full=wm_state[8]; + bob_wm_begin_draw(wm_state,wm_windows,wm_order); + if(redraw_full) { + bob_gfx_clear('.',1); + bob_gfx_text(2,0,"BOB32 DESKTOP ?: HELP TAB: FOCUS CTRL+S: SAVE ESC: EXIT",15); + } + while((draw_id=bob_wm_next_dirty(wm_state,wm_windows,wm_order))>=0) { + int id=draw_id;int *rect=windows+id*4; + if(id==0)bob_gui_window(rect[0],rect[1],rect[2],rect[3],"Text editor", + "E opens text. Tab changes focus.","Ctrl+S saves; Enter starts a new line.",wm_state[2]==0); + else { + bob_gui_window(rect[0],rect[1],rect[2],rect[3],"Window B","File menu: M or click File",message_b,wm_state[2]==1); + for(int row=0;row<6&&file_scroll+row ":" ",wm_state[2]==1?15:8); + bob_gfx_text(rect[0]+4,rect[1]+4+row,file_name,wm_state[2]==1?15:7); + } + if(delete_confirm) { + bob_gfx_text(rect[0]+2,rect[1]+11,"Delete selected text file?",wm_state[2]==1?14:8); + delete_yes[0]=rect[0]+2;delete_yes[1]=rect[1]+14; + delete_no[0]=rect[0]+19;delete_no[1]=rect[1]+14; + bob_gui_button_draw(delete_yes[0],delete_yes[1],delete_yes[2],delete_yes[3],"Yes, delete",delete_yes_state[0],delete_yes_state[1]); + bob_gui_button_draw(delete_no[0],delete_no[1],delete_no[2],delete_no[3],"Cancel",delete_no_state[0],delete_no_state[1]); + } else { + bob_gfx_text(rect[0]+2,rect[1]+11,"Preview:",wm_state[2]==1?14:8); + if(preview_length<0)bob_gfx_text(rect[0]+2,rect[1]+12,"No text preview.",wm_state[2]==1?7:8); + preview_position=gui_preview_offset(preview,preview_length,preview_scroll); + for(preview_row=0;preview_row<6&&preview_position=0&&selected_file=21&&event[2]<59&&row>=0&&row0)app_selected--; + else if(event[1]==257&&app_selected+10)app_selected--; + else if(event[1]=='r'){gui_launch_app(app_selected,app_names,app_count,message_b);launcher_open=0;} + } + continue; + } + if(event[0]==BOB_EVENT_CHAR&&event[1]==27){running=0;break;} + target_window=bob_wm_dispatch(wm_state,wm_windows,wm_order,event,routed_event); + if(target_window<0)continue; + for(int i=0;i<4;i++)event[i]=routed_event[i]; + gui_wm_sync_rects(windows,wm_windows); + gui_place_editor_widgets(windows,name_field,text_area,button); + bob_wm_invalidate(wm_state,wm_windows,wm_order,target_window); + if(event[0]==BOB_EVENT_MOUSE_MOVE||event[0]==BOB_EVENT_MOUSE_BUTTON_DOWN|| + event[0]==BOB_EVENT_MOUSE_BUTTON_UP||event[0]==BOB_EVENT_MOUSE_WHEEL) { + event[2]+=windows[target_window*4];event[3]+=windows[target_window*4+1]; + } + if(event[0]==BOB_EVENT_MOUSE_MOVE) { + mouse_x=event[2];mouse_y=event[3]; + if(wm_state[2]==0)bob_gui_button_event(button,button_state,event); + else button_state[0]=0; + if(wm_state[2]==1&&delete_confirm) { + bob_gui_button_event(delete_yes,delete_yes_state,event); + bob_gui_button_event(delete_no,delete_no_state,event); + } else {delete_yes_state[0]=0;delete_no_state[0]=0;} + continue; + } + if(event[0]==BOB_EVENT_MOUSE_WHEEL) { + mouse_x=event[2];mouse_y=event[3]; + if(wm_state[2]==0&&bob_gui_window_hit(mouse_x,mouse_y,text_area)) { + name_state[0]=0;bob_wm_focus(wm_state,wm_windows,wm_order,0); + bob_gui_text_area_event(text_area,file_text,text_state,512,event); + } else if(wm_state[2]==1&&bob_gui_window_hit(mouse_x,mouse_y,windows+4)) { + if(mouse_y>=windows[5]+4&&mouse_y0?selected_file-1:selected_file+1; + if(row>=0&&row=windows[5]+11&&mouse_y0&&preview_scroll>0)preview_scroll--; + else if(event[1]<0&&gui_preview_offset(preview,preview_length,preview_scroll+1)=windows[4]+2&&mouse_x=windows[5]+4&&mouse_y=0)gui_select_file(selected_file,file_slots,file_count,&selected_file,message_b,preview,&preview_length,&preview_scroll); + } + if(wm_state[2]==0&&bob_gui_button_event(button,button_state,event)) { + if(bob_file_write(file_name_text,file_text,bob_strlen(file_text))==0) { + bob_strcpy(message_b,"Saved file.");selected_file=-1;selection_initialized=0; + } else bob_strcpy(message_b,"Save failed; check name."); + } + continue; + } + if(event[0]==BOB_EVENT_KEY_DOWN) { + if(wm_state[2]==0) { + if(name_state[0])bob_gui_text_field_event(name_field,file_name_text,name_state,24,event); + else if(text_state[0])bob_gui_text_area_event(text_area,file_text,text_state,512,event); + } + else if(event[1]==256&&preview_scroll>0)preview_scroll--; + else if(event[1]==257&&gui_preview_offset(preview,preview_length,preview_scroll+1)=0)gui_select_file(selected_file,file_slots,file_count,&selected_file,message_b,preview,&preview_length,&preview_scroll); + bob_strcpy(message_b,"Delete cancelled."); + } else if(wm_state[2]==1&&delete_confirm) { + } + else if(wm_state[2]==1&&event[1]=='n'&&selected_file+10) { + gui_select_file(selected_file-1,file_slots,file_count,&selected_file,message_b,preview,&preview_length,&preview_scroll); + } else if(wm_state[2]==1&&event[1]=='x'&&selected_file>=0) { + int selected_size,selected_kind; + selected_kind=bob_file_list(file_slots[selected_file],file_name,24,&selected_size); + if(selected_kind==0){delete_confirm=1;delete_yes_state[0]=0;delete_yes_state[1]=0;delete_no_state[0]=0;delete_no_state[1]=0;bob_strcpy(message_b,"Delete? Y/N");} + else bob_strcpy(message_b,"Text files only."); + } else if(wm_state[2]==1&&event[1]=='u'&&preview_scroll>0)preview_scroll--; + else if(wm_state[2]==1&&event[1]=='d'&&gui_preview_offset(preview,preview_length,preview_scroll+1)0)message_b[--length_b]=0; + } else if(event[1]>=32&&event[1]<127) { + if(wm_state[2]==1&&length_b<30) { + message_b[length_b++]=event[1];message_b[length_b]=0; + } + } + } + if(bob_gfx_leave())return 2; + bob_puts("bob!"); + return 0; +} diff --git a/apps/launcher.c b/apps/launcher.c new file mode 100644 index 0000000..2b20815 --- /dev/null +++ b/apps/launcher.c @@ -0,0 +1,51 @@ +#include "bob.h" +#include "bob_fs.h" +#include "bob_process.h" +#include "bob_string.h" + +static int append(char *buffer,int *length,char value) { + if(*length>=126)return 0; + buffer[(*length)++]=value;buffer[*length]=0;return 1; +} + +static void print_number(int value) { + char digits[12];int count=0; + if(value<0){bob_putc('-');value=-value;} + do {digits[count++]=(char)('0'+value%10);value/=10;} while(value&&count<11); + while(count)bob_putc(digits[--count]); + bob_putc('\n'); +} + +int main(int argc,char **argv) { + int i,size,kind,length=0,status,child_status=-1; + char name[24],arguments[128]; + arguments[0]=0; + if(argc<2) { + bob_puts("Native apps:"); + for(i=0;i<8;i++) { + kind=bob_file_list(i,name,24,&size); + if(kind==3){bob_puts(name);bob_putc('\n');} + } + bob_puts("Usage: run launcher APP [ARG ...]"); + return 0; + } + for(i=2;i2&&!append(arguments,&length,' '))return 1; + if(!append(arguments,&length,'"'))return 1; + for(j=0;argv[i][j];j++) { + if((argv[i][j]=='"'||argv[i][j]=='\\')&&!append(arguments,&length,'\\'))return 1; + if(!append(arguments,&length,argv[i][j]))return 1; + } + if(!append(arguments,&length,'"'))return 1; + } + status=bob_app_run(argv[1],arguments,&child_status); + if(status==-1)bob_puts("App not found."); + else if(status==-2)bob_puts("File is not a native bob32 app."); + else if(status==-4)bob_puts("Invalid app or arguments."); + else if(status==-5)bob_puts("Not enough emulator memory to launch app."); + else if(status==-3)bob_puts("App timed out."); + else if(status<-5)bob_puts("App could not be launched."); + else {bob_puts("Child exit:");print_number(child_status);} + return status<0?1:child_status; +} diff --git a/apps/ls.c b/apps/ls.c new file mode 100644 index 0000000..02d0bf4 --- /dev/null +++ b/apps/ls.c @@ -0,0 +1,29 @@ +#include "bob.h" +#include "bob_fs.h" +#include "bob_string.h" + +static void write_text(const char *text) { + while (*text) bob_putc(*text++); +} + +int main(void) { + char name[24]; + char number[12]; + int size; + int kind; + int i; + for (i = 0; i < 8; i++) { + kind = bob_file_list(i, name, 24, &size); + if (kind < 0) continue; + write_text(name); + bob_putc(' '); + bob_format_int(size, number, 12); + write_text(number); + bob_putc(' '); + if (kind == 0) write_text("text"); + else if (kind == 3) write_text("native app"); + else write_text("program"); + bob_putc('\n'); + } + return 0; +} diff --git a/apps/notes.c b/apps/notes.c new file mode 100644 index 0000000..e55c0ad --- /dev/null +++ b/apps/notes.c @@ -0,0 +1,103 @@ +#include "bob.h" +#include "bob_fs.h" + +static int same_text(const char *left,const char *right) { + int i=0;while(left[i]&&left[i]==right[i])i++; + return left[i]==right[i]; +} + +/* 1=text note, 0=missing, -1=name belongs to a non-text file. */ +static int note_kind(const char *wanted) { + int kind=bob_file_kind(wanted); + if(kind<0)return 0; + return kind==BOB_FILE_KIND_TEXT?1:-1; +} + +static int join_arguments(char *text,int *length,int argc,char **argv,int start) { + *length=0; + for(int i=start;istart) { + if(*length>=511)return 0; + text[(*length)++]=' '; + } + for(int j=0;argv[i][j];j++) { + if(*length>=511)return 0; + text[(*length)++]=argv[i][j]; + } + } + text[*length]=0; + return 1; +} + +int main(int argc, char **argv) { + char text[512]; + int length; + int i; + if (argc < 2) { + bob_puts("Usage: notes show NAME | put/edit NAME [TEXT] | add NAME [TEXT] | delete NAME"); + return 1; + } + if (same_text(argv[1], "show") && argc == 3) { + if(note_kind(argv[2])<0){bob_puts("Not a text note.");return 1;} + length = bob_file_read(argv[2], text, 512); + if (length < 0) { bob_puts("Note not found."); return 1; } + for (i = 0; i < length; i++) bob_putc(text[i]); + bob_putc('\n'); + return 0; + } + if ((same_text(argv[1], "put")||same_text(argv[1], "edit")) && argc >= 3) { + if(note_kind(argv[2])<0){bob_puts("Not a text note.");return 1;} + if (argc == 3) { + bob_puts("Note text:"); + bob_gets(text, 512); + length=0;while(text[length])length++; + } else if(!join_arguments(text,&length,argc,argv,3)) { + bob_puts("Note is too long (511 characters maximum).");return 1; + } + if (bob_file_write(argv[2], text, length)) { bob_puts("Cannot save note."); return 1; } + bob_puts("Saved."); + return 0; + } + if (same_text(argv[1], "add") && argc >= 3) { + int kind=note_kind(argv[2]); + if(kind<0){bob_puts("Not a text note.");return 1;} + if(kind) { + length=bob_file_read(argv[2],text,512); + if(length<0){bob_puts("Cannot read note.");return 1;} + } else {length=0;text[0]=0;} + if(argc==3) { + if(length&&text[length-1]!='\n') { + if(length>=511){bob_puts("Note is too long (511 characters maximum).");return 1;} + text[length++]='\n'; + } + bob_puts("Add text:");bob_gets(text+length,512-length); + while(text[length])length++; + } else { + if(length&&text[length-1]!='\n') { + if(length>=511){bob_puts("Note is too long (511 characters maximum).");return 1;} + text[length++]='\n'; + } + for(i=3;i3) { + if(length>=511){bob_puts("Note is too long (511 characters maximum).");return 1;} + text[length++]=' '; + } + for(int j=0;argv[i][j];j++) { + if(length>=511){bob_puts("Note is too long (511 characters maximum).");return 1;} + text[length++]=argv[i][j]; + } + } + text[length]=0; + } + if(bob_file_write(argv[2],text,length)){bob_puts("Cannot save note.");return 1;} + bob_puts("Saved.");return 0; + } + if (same_text(argv[1], "delete") && argc == 3) { + if(note_kind(argv[2])!=1){bob_puts("Not a text note.");return 1;} + if (bob_file_delete(argv[2])) { bob_puts("Note not found."); return 1; } + bob_puts("Deleted."); + return 0; + } + bob_puts("Usage: notes show NAME | put/edit NAME [TEXT] | add NAME [TEXT] | delete NAME"); + return 1; +} diff --git a/apps/sysinfo.c b/apps/sysinfo.c new file mode 100644 index 0000000..54db1fc --- /dev/null +++ b/apps/sysinfo.c @@ -0,0 +1,50 @@ +#include "bob.h" +#include "bob_fs.h" +#include "bob_system.h" +#include "bob_string.h" + +static void write_text(const char *text) { + while (*text) bob_putc(*text++); +} + +static void show_value(const char *label, int value) { + char number[12]; + write_text(label); + bob_format_int(value, number, 12); + write_text(number); + bob_putc('\n'); +} + +int main(void) { + int info[6]; + int capabilities[5]; + if (bob_system_info(info, 6) != 6 || info[0] != BOB_FS_API_VERSION) { + bob_puts("System information service unavailable."); + return 1; + } + if (bob_system_capabilities(capabilities, 4) != -1) { + bob_puts("System capability validation failed."); + return 2; + } + if (bob_system_capabilities(capabilities, 5) != 5 || + capabilities[0] != BOB_SYSTEM_API_VERSION) { + bob_puts("System capabilities unavailable."); + return 3; + } + bob_puts("bob32 system information"); + show_value("System API version: ", capabilities[0]); + bob_puts((capabilities[1] & BOB_SYSTEM_DEVICE_CELL_FRAMEBUFFER) ? + "Cell framebuffer: available" : "Cell framebuffer: unavailable"); + show_value("Display width (cells): ", capabilities[2]); + show_value("Display height (cells): ", capabilities[3]); + bob_puts((capabilities[4] & BOB_SYSTEM_INPUT_KEYBOARD) ? + "Keyboard input: available" : "Keyboard input: unavailable"); + bob_puts((capabilities[4] & BOB_SYSTEM_INPUT_MOUSE) ? + "Mouse input: available" : "Mouse input: unavailable"); + show_value("Application address space (words): ", info[1]); + show_value("Mapped application pages: ", info[2]); + show_value("Guest files: ", info[3]); + show_value("Filesystem words used: ", info[4]); + show_value("Filesystem words free: ", info[5]); + return 0; +} diff --git a/bob-files.b32 b/bob-files.b32 index 376dd66..e9166d9 100644 Binary files a/bob-files.b32 and b/bob-files.b32 differ diff --git a/bob.exe b/bob.exe index 2f0bca7..bb02149 100644 Binary files a/bob.exe and b/bob.exe differ diff --git a/bob32.exe b/bob32.exe index 39435b1..63144f3 100644 Binary files a/bob32.exe and b/bob32.exe differ diff --git a/bob64/ABI.md b/bob64/ABI.md new file mode 100644 index 0000000..81ff906 --- /dev/null +++ b/bob64/ABI.md @@ -0,0 +1,124 @@ +# bob64 application ABI v1 / syscall ABI v10 + +The kernel and first native applications use the Microsoft x64 ABI, matching +the x64 UEFI toolchain. `bob64/abi.h` is the source for the version and the +application-entry structure. B64E's ABI field must match +`BOB64_APP_ABI_VERSION`. + +## Calls + +- Integer and pointer arguments occupy positional slots in `RCX`, `RDX`, `R8`, + and `R9`; later arguments are passed on the stack. Floating-point arguments + use the corresponding `XMM0` through `XMM3` slots. +- Integer and pointer results use `RAX`; floating-point results use `XMM0`. +- Caller-saved registers are `RAX`, `RCX`, `RDX`, `R8`–`R11`, and `XMM0`–`XMM5`. + Callee-saved registers are `RBX`, `RBP`, `RSI`, `RDI`, `RSP`, `R12`–`R15`, + and `XMM6`–`XMM15`. +- The stack grows toward lower addresses. A caller aligns `RSP` to 16 bytes + before `call` and reserves 32 bytes of shadow space. On function entry, the + return address makes `RSP` 8 bytes off a 16-byte boundary. There is no red + zone; native code must not use memory below `RSP` without allocating it. +- The fifth and later integer arguments follow the 32-byte shadow area; the + fifth argument is at `[RSP+40]` on callee entry. +- Eligible plain C structs of 1, 2, 4, or 8 bytes return in `RAX`. Other + aggregate return sizes use caller-provided storage passed as a hidden first + argument. The app entry itself returns only a signed 64-bit status, so it + has no hidden return pointer. + +## Application entry + +The entry point has the type: + +```c +s64 bob64_app_main(const BOB64_APP_STARTUP *startup); +``` + +The pointer is passed in `RCX`; the signed exit status returns in `RAX`. The +32-byte startup record contains its size and ABI version, a 64-bit argument +count, a pointer to a null-terminated argv pointer array, and zeroed flags. +The record, pointer array, and strings belong to the application's address +space. The ABI never passes kernel pointers to an application. + +The loader validates the record size/version, creates the stack and argument +storage in the application's address space, aligns the entry stack, and +provides the shadow area. `bob64_enter_user` enters at CPL3 with the startup +record in `RCX`; it preserves the kernel's nonvolatile registers and restores +the caller's interrupt-enable state when the app exits. User entry enables +interrupts so configured devices can deliver input. Returning from the entry +function is not supported: apps must use the exit system call. + +## System calls + +System-call ABI v10 uses interrupt vector `0x80`. Put the service number in +`RAX`; a returning call writes its result to `RAX`. The available services are: + +| Number | Name | Argument | Result | +| --- | --- | --- | --- | +| 0 | Query ABI | ignored | `BOB64_SYSCALL_ABI_VERSION` | +| 1 | Write character | low byte of `RCX` | `0` on success | +| 2 | Write buffer | user pointer in `RCX`, byte length in `RDX` | bytes written or `-14` | +| 3 | Exit | signed status in `RCX` | returns to the kernel | +| 4 | Read file | name pointer in `RCX`, name length in `RDX`, writable app buffer in `R8`, capacity in `R9` | bytes read or negative error | +| 5 | Write file | name pointer in `RCX`, name length in `RDX`, app buffer in `R8`, byte length in `R9` | bytes written or negative error | +| 6 | Get display | ignored | pixel width in `RAX`, pixel height in `RDX`, or `-19` if unavailable | +| 7 | Present surface | packed pixel pointer in `RCX`, width in `RDX`, height in `R8` | number of pixels presented or negative error | +| 8 | Wait event | writable app pointer to `BOB64_EVENT` in `RCX` | `0` after keyboard or mouse input, negative error | +| 9 | List files | writable `BOB64_FILE_INFO` array pointer in `RCX`, entry capacity in `RDX` | entry count or negative error | +| 10 | Delete file | name pointer in `RCX`, name length in `RDX` | `0` or negative error | +| 11 | Create window | signed x in `RCX`, signed y in `RDX`, width in `R8`, height in `R9` | nonzero 64-bit handle or negative error | +| 12 | Destroy window | handle in `RCX` | `0` or negative error | +| 13 | Present window | handle in `RCX`, pixel pointer in `RDX`, width in `R8`, height in `R9` | number of pixels presented or negative error | +| 14 | Focus window | handle in `RCX` | `0` or negative error | +| 15 | Open file | name pointer in `RCX`, length in `RDX`, flags in `R8` | 64-bit handle or negative error | +| 16 | Read handle | handle in `RCX`, writable buffer in `RDX`, capacity in `R8` | bytes read, `0` at EOF, or negative error | +| 17 | Write handle | handle in `RCX`, buffer in `RDX`, length in `R8` | bytes written or negative error | +| 18 | Seek handle | handle in `RCX`, nonnegative signed 64-bit absolute offset in `RDX` | new offset or negative error | +| 19 | Close handle | handle in `RCX` | `0` or negative error | +| 20 | Get timer ticks | ignored | 64-bit count of 100 Hz PIT ticks since kernel initialization | + +The first kernel smoke app queries the ABI, prints `bob!` one character at a +time, and exits through this path. Console and per-call file buffers are +limited to 4096 bytes; names are limited to 63 bytes. The legacy whole-file +calls remain available. Streaming opens accept `BOB64_FILE_OPEN_READ`, +`WRITE`, `CREATE`, `TRUNCATE`, and `APPEND`; at least read or write is required, +and truncate/append require write. Create initializes a missing file. Handles +belong to the active foreground app and are invalidated when it exits or the +file is deleted. Reads and writes advance a per-handle 64-bit position; seek +sets a nonnegative signed 64-bit absolute position. Append-mode writes target +the current end of file. Reads can be short at EOF, writes past the end +zero-fill the gap, and each transfer is bounded to 4096 bytes. File enumeration accepts +capacity 1 through 32 and returns fixed 72-byte `BOB64_FILE_INFO` records +containing a 64-byte zero-terminated name and a 64-bit size; if the complete +directory does not fit, it returns `-28` without copying a partial result. +File deletion uses the same validated 1-to-63-byte safe filenames as reads and +writes and returns `-2` if the file does not exist. Display surfaces must match the current +GOP resolution and contain packed row-major `0x00RRGGBB` pixels; at most 16 MiB +may be presented per call. The kernel validates every covered user page before +copying pixels in small chunks, and converts channels to the firmware's GOP +format without exposing the framebuffer pointer. File reads require writable +user pages. `BOB64_EVENT` is a fixed 56-byte record with type, set-1 key code, +ASCII character, modifiers, window-local pointer position and movement, button +state, wheel delta, a 64-bit window handle, and screen coordinates. Whole-screen +events use a zero window handle. Extended set-1 keys set bit `0x100` in the key code; key-up events +have no character. Mouse buttons use the low three bits for standard buttons; +IntelliMouse IDs 3 and 4 add signed wheel input, with ID 4 adding buttons four +and five. `bob64_app_wait_event` blocks while the kernel polls PS/2 devices and +copies the event to writable app memory. +The current flat volatile filesystem stores arbitrary bytes, while names reject +path separators and characters outside its documented safe set. +`bob64/app.h` provides matching +C wrappers. A CPU exception from active user code returns an error status to the +kernel instead of halting the system. `bob64/window.h` provides a reusable +app-owned window manager using 64-bit handles and pointers; it routes the +versioned keyboard/mouse event records without kernel pointers. Syscalls 11-13 +create, destroy, and present kernel-owned windows for the foreground app. Each +window has an opaque 64-bit handle and a retained kernel surface; presentation +must match the dimensions used at creation. The kernel composites up to 16 +windows in z-order with an aggregate 16 MiB surface limit, routes input to the +focused window, and destroys the session when the app exits. Nonzero event +window handles identify the target; mouse coordinates are local to that window +and `ScreenX`/`ScreenY` retain absolute coordinates. +Only one app runs at a time, so cross-process desktop composition is still a +future step. Floating-point language types, +variadic calls across the kernel boundary, and aggregate application entry +results are not defined yet. diff --git a/bob64/README.md b/bob64/README.md new file mode 100644 index 0000000..d01ceba --- /dev/null +++ b/bob64/README.md @@ -0,0 +1,234 @@ +# bob64 boot milestone + +`make bob64` creates a standalone x86-64 UEFI application at +`build/bob64/EFI/BOOT/BOOTX64.EFI`. Copy the `EFI` directory to the root of a +FAT32 USB drive, boot a machine with x64 UEFI, and select the USB device. From a +UEFI shell, the same image can be started with: + +```text +fs0:\EFI\BOOT\BOOTX64.EFI +``` + +UEFI's x64 application contract transfers control in 64-bit long mode with the +Microsoft x64 calling convention, a valid stack, and firmware page tables. The +first bob64 entry checks CPUID long-mode support and `EFER.LMA`, then prints +`bob64!` through the firmware console. It reads the UEFI memory map and seeds a +64-bit first-fit allocator for conventional 4 KiB physical pages. The PE image +has a base-relocation directory, allowing firmware to load it away from its +preferred address. A tested bootstrap mapper can build identity mappings for +the image, a replacement stack, and its page-table pool. The EFI entry now +allocates those regions and verifies their mappings. The default build remains +a safe probe that returns to firmware. The opt-in `make bob64-handoff` build +exits Boot Services, maps a supported GOP framebuffer, installs the kernel +GDT/IDT and page-table root, switches to a replacement stack, and enters a tiny +C kernel. The kernel checks the boot information and active CR3, prints +`bob64!` and address-space details to the framebuffer and COM1, then checks its +heap and opens a command shell. Unsupported GOP modes fall back to COM1. The +handoff has been booted under QEMU with x64 OVMF firmware; the kernel reaches its +shell after switching to its own page tables, and the GOP framebuffer has been +visually checked at 1280x800. + +Kernel entry also adopts the seeded physical-page allocator and maps pages into +a small coalescing heap in the high canonical address range. Its boot smoke test +checks aligned allocation, zeroing, multi-page growth, writes, and freeing. The +early heap does not yet reclaim empty pages or provide SMP locking. + +After the memory checks, bob64 opens a shell. When an 8042 controller is +available, keyboard IRQ1 feeds its event queue; otherwise input falls back to +PS/2 polling. COM1 remains polled. The shell provides `help`, `clear`, `mem`, `heap`, `version`, and +`echo`. A heap-backed RAM filesystem adds `ls`, `cat NAME`, `write NAME TEXT`, +and `rm NAME`; it stores arbitrary file bytes, and its contents disappear on +reboot. A 100 Hz PIT IRQ supplies kernel and app tick counts. USB keyboards, +history, completion, directories, and persistent storage are still open. + +The shell also supports `save` and `restore` using B64S version 1. The format +stores fixed-width lengths and arbitrary file bytes with a CRC-32, never raw +pointers. The current checkpoint lives in the kernel heap and survives +filesystem edits until reboot; it is not written to disk yet. + +`bob64/exec.h` defines the B64E v1 flat, position-independent native image +format. It carries an explicit ABI version and 64-bit payload, memory, code, and +entry-offset fields. The host-tested parser validates exact lengths, reserved +fields, and a payload CRC before exposing the image; the loading primitive +preserves addresses above 4 GiB and zeroes the memory-only tail. `bob64/abi.h` +defines the matching Microsoft x64 app entry call and a 32-byte startup record +whose arguments live in app memory. `bob64/process.c` has a callback-backed +loader core that validates B64E again, prepares user code/data/stack mappings, +builds the app-owned argv/startup record, and rolls back mapped frames on +failure. Host tests use synthetic pages above 4 GiB. The kernel smoke test +clones its active page-table root, isolates a 34 MiB app image/stack arena, and +switches CR3 while it loads a synthetic app. The shell can run B64E files with +`run NAME [ARG ...]`; the kernel seeds `bob.b64e` as a ready-to-run example. +Each launch gets a fresh isolated root, and the kernel frees its app pages and +page tables after the exit. The example app prints `bob!` through the DPL3 +`int 0x80` gate and exits back to the kernel. +Syscall ABI v10 exposes an ABI query, character and bounded buffer output, +whole-file and handle-based streaming file read/write/list/delete, display dimensions, full-screen packed +`0x00RRGGBB` surface presentation, app-owned-window creation/destruction and +presentation through a kernel compositor, focus control, input events, and +process exit. Applications can use +`bob64_app_get_display` and `bob64_app_present` from `bob64/app.h`; the kernel +validates the whole user surface, copies it in bounded chunks and converts it +to GOP channel order. Surfaces must match the display resolution and are capped +at 16 MiB. User buffers are checked against the process page +tables; file reads require writable app pages. `bob64/app.h` provides C wrappers +without exposing kernel-internal types. The C smoke app writes and reads back a +small RAM file before it exits. +`apps/bob64_display.c` is an early native graphics app. It queries GOP +dimensions, draws a packed color surface, presents it, then prints `bob!`. +The bob64 build packages it as `build/bob64-app/display.b64e` and checks its +B64E metadata alongside the file-I/O smoke app. The native desktop runtime test +also exercises GOP-backed window presentation through the kernel compositor. +The demo stays on screen until Escape; `bob64_app_wait_event` receives typed +PS/2 key-down/up events, including Shift, Caps, Control, Alt and extended +arrow-key codes, plus mouse movement, buttons and IntelliMouse wheel events. +PIT IRQ0 supplies 100 Hz ticks; keyboard IRQ1 and mouse IRQ12 feed event queues +when the 8042 is available. Mouse position and packet decoding happen in the +IRQ handler. USB input remains future work. +`bob64/window.h` provides app-owned windows, 64-bit handles/context pointers, +focus, z-order, title-bar dragging, hit testing, dirty redraws and local event +routing. The v10 kernel API additionally creates, destroys and composites up to +16 kernel-owned window surfaces per foreground app, routes events with 64-bit +window handles, and releases surfaces when the app exits. The desktop now draws +its file browser and editor into separate kernel-managed surfaces while keeping +the app-side manager for widget layout and mouse hit testing. Concurrent apps +remain a future step. `apps/bob64_gui.c` is the first interactive desktop: +launch `run desktop.b64e [filename]` from the shell (the default file is +`notes.txt`), browse files in the left window, use Up/Down to select, `O` or +Enter to open, `R` to refresh, and `D` twice to delete a file. Type into the +editor, use arrow keys to move, Backspace to delete, +click in the text to place the cursor, Enter for a new line, and Ctrl+S to save. +The editor scrolls to keep the caret visible. +Tab changes focus and Escape returns to the shell; unsaved edits require a +second Escape. Filenames use letters, digits, period, underscore or hyphen. +Files up to 4096 bytes fit in the current app file ABI; a +larger existing file is protected from accidental overwrite. Under QEMU/OVMF at +1280x800, both windows rendered, PS/2 input created an additional window and +returned to the shell, a mouse click selected a file-list row, and Ctrl+S saved +editor text through the file syscall. +User-origin CPU exceptions return an error status to the kernel. User apps run +with interrupts enabled when the keyboard IRQ path is active, and the loader +restores the caller's interrupt-enable state on return. The desktop editor still uses whole-file calls and +is capped at 4096 bytes; larger files are protected from accidental overwrite. +Other apps can use ABI v10 streaming handles for bounded transfers at 64-bit +offsets. Interactive app management remains future work. QEMU/OVMF runtime +checks exercise the ring-3 smoke app, syscalls, +application loader, shell, and desktop. + +The bob64 build compiles this C smoke app and embeds its B64E file in the kernel +image. The shell's `run bob.b64e` command exercises the C compiler bridge, +executable loader, user syscall ABI, RAM-file read/write, and process exit path. +The smaller kernel-generated app remains a separate ring-3 boot smoke test. + +The shell also embeds `bob.c` and supports `cc bob.c` followed by +`run app.b64e`. The resident compiler emits a B64E image itself, with separate +read-only executable code and writable/NX data pages. Its initial C subset +accepts `int`, `short`, `long`, or `long long` main returns; initialized +`short`, `int`, `long`, and `long long` locals; local assignment; calls to +`bob64_app_write` with string literals and matching constant lengths; and +`return` expressions using 64-bit +integer literals, parentheses, unary minus, addition, subtraction, and +multiplication. The compiler follows LLP64: `short` is 16-bit; `int` and `long` +are 32-bit and sign-extend on return; `long long` is 64-bit and preserves its +full result. Short globals, locals, struct fields, function parameters and +returns are sign-extended on load and use 16-bit storage. The resident subset +supports `void` helper functions with explicit `return;` or fallthrough, and +scalar `char` returns with signed 8-bit extension. Void calls work as statements +and are rejected when used as values. The resident subset recognizes +`usize`/`uintptr_t` as unsigned 64-bit integers and +`isize`/`intptr_t` as signed 64-bit integers, including function parameters, +returns, and scalar storage. Function prototypes and definitions can also +return `char *`, `short *`, `int *`, or pointers to declared structs, with +matching pointee types enforced at return statements. The pointer-sized integer +names are compiler built-ins because typedefs and header inclusion are not +implemented. `usize *`, `uintptr_t *`, `isize *`, `intptr_t *`, and +`long long *` support dereference, indexing, assignment, function arguments and +returns, eight-byte scaled arithmetic, and matching global scalar pointers. +Signed and unsigned wide pointers have separate types; `isize *` and +`long long *` are equivalent in this subset. Fixed-size arrays of these wide +scalar types support local and global storage, brace initialization, +indexed reads and writes, and array-parameter decay. Local arrays are limited to +16 elements by the fixed stack frame; global arrays share the 4 KiB data page. +The generated entry shim follows the Microsoft x64 ABI and exits via syscall ABI +v4. There are at most 16 locals in one function. File-scope `short`, `int`, `long`, `char`, and +`long long` objects use the app's 64-bit-addressed writable data page; scalar +constants and fixed `short`/`int`/`char` arrays can be initialized; fixed +`long long`/`usize` arrays are also supported. Global +`short *`, `int *`, and `char *` values can point to +previously declared arrays or string literals, and global pointers to named +struct objects can use `&object`; `main` initializes them with position- +independent x64 code, without fixed-address relocations. Globals are shared by +all compiled functions. Named structs support aligned `short`, `int`, `long`, +`char`, `long long`, and scalar pointer fields, local/global instances, and +`.`/`->` field reads and writes. Nested structs, struct arrays, typedefs, and multiple translation units +remain unsupported. Limits are 8 struct types, 16 fields per type, 16 global +objects, and one 4 KiB data page. Struct pointers can be passed to helper +functions, which can access fields with `->`. The resident +compiler also supports fixed local `short` and `int` arrays (up to 64 short or +32 int elements within a 128-byte frame), `short *`/`int *` locals, +array-to-pointer decay, address-of and dereference, indexed loads/stores, and +scaled pointer addition and subtraction, including element-count pointer +differences. String literals +are NUL-terminated `char *` values; `char *` locals and parameters, byte-indexed +reads and stores, byte dereference, byte-scaled pointer arithmetic, signed +8-bit `char` locals/parameters, and escaped character constants including +`'\\0'` are supported. Local `char` arrays can be initialized from string +literals or scalar brace lists, decay to `char *` arguments, and be indexed or +updated byte by byte. Host tests execute string traversal and mutable text +buffers. It rejects +pointer multiplication and incompatible pointer initializers/assignments. Local +array brace initializers support scalar expressions, trailing commas, omitted +element zero-fill, and excess-element rejection. Integer helper functions may +follow `main`; calls can be forward or nested and pass up to sixteen `short`, +`int`, `long`, `char`, `short *`/array, `int *`/array, `char *`, or struct-pointer +arguments through the +Microsoft x64 ABI, using RCX/RDX/R8/R9 and the caller's stack argument area. +Function definitions may appear before or after `main`; matching prototypes +may declare or omit parameter names. Array parameters index as `int *`. Compound +blocks and `for` initializers have lexical scopes with local shadowing. Return +types other than `int`, `short`, `long`, or `long long` remain unsupported and +report a source offset. `if`/`else` and `while` +support nonzero conditions plus signed integer +`==`, `!=`, `<`, `<=`, `>`, and `>=` comparisons, and may use braces. Unary `!` and short-circuit +`&&`/`||` are supported. Basic `for` loops accept an optional initializer, +condition, and scalar-variable assignment update. `break` and `continue` target +the nearest enclosing loop, and `continue` in a `for` loop runs its update. +`return` is also valid inside conditional and loop statements, followed by the +function's required final return for the current subset. + +`make bob64cc` builds a host-side C-to-B64E bridge using the configured +x86-64 GCC toolchain. For example, `bob64cc apps/bob64_smoke.c +build/bob64-app/smoke.b64e` compiles C that uses `bob64/app.h`, links it at the +process image base, and packages the executable sections into a checksummed +B64E file. The entry wrapper converts a normal C return into the process-exit +syscall, and `bob64/libc.c` supplies 64-bit-length memory and string operations. +`make bob64-app-test` validates this generated file with the B64E parser. The +resident backend now exists for the small `bob.c` demo; the host bridge still +supports the broader C source accepted by GCC while the resident backend grows. + +Run `make bob64-handoff-test` for host-side PE checks. They validate the image +format and relocation directory, but do not execute privileged CPU +instructions or prove `ExitBootServices` succeeds on a given firmware. +To boot the interactive shell, copy `build/bob64-handoff/EFI` to the FAT32 +drive's root so firmware starts its `EFI/BOOT/BOOTX64.EFI` image. A PS/2 +keyboard or COM1 serial terminal can provide shell input. + +The bob64 build uses a separate header and target. It does not change `bob.exe`, +`bob32.exe`, B16K/B32K images, or the existing resident compiler. Remaining +migration work includes growing the resident C subset, persistent storage, +runtime verification of interrupt-driven devices, USB input, and porting the +rest of the applications. + +## UEFI runtime test + +Build the handoff image with `build-tool --bob64-handoff-test`, then run the +serial-checked QEMU/OVMF boot test: + +```powershell +.\tools\test_bob64_qemu.ps1 -QemuPath C:\path\to\qemu-system-x86_64.exe ` + -OvmfCodePath C:\path\to\edk2-x86_64-code.fd +``` + +The test waits for long-mode entry, `ExitBootServices`, the ring-3 `bob!` app, +heap checks, and the kernel shell. Manual QEMU testing has also exercised the +resident `cc`/`run` path, B64S save/restore, and the desktop editor. diff --git a/bob64/abi.h b/bob64/abi.h new file mode 100644 index 0000000..02dafef --- /dev/null +++ b/bob64/abi.h @@ -0,0 +1,79 @@ +#ifndef BOB64_ABI_H +#define BOB64_ABI_H + +#include "types.h" + +#define BOB64_APP_ABI_VERSION 1u +#define BOB64_SYSCALL_ABI_VERSION 10u +#define BOB64_SYSCALL_QUERY_ABI 0u +#define BOB64_SYSCALL_WRITE_CHAR 1u +#define BOB64_SYSCALL_WRITE_BUFFER 2u +#define BOB64_SYSCALL_EXIT 3u +#define BOB64_SYSCALL_READ_FILE 4u +#define BOB64_SYSCALL_WRITE_FILE 5u +#define BOB64_SYSCALL_GET_DISPLAY 6u +#define BOB64_SYSCALL_PRESENT 7u +#define BOB64_SYSCALL_WAIT_EVENT 8u +#define BOB64_SYSCALL_LIST_FILES 9u +#define BOB64_SYSCALL_DELETE_FILE 10u +#define BOB64_SYSCALL_CREATE_WINDOW 11u +#define BOB64_SYSCALL_DESTROY_WINDOW 12u +#define BOB64_SYSCALL_PRESENT_WINDOW 13u +#define BOB64_SYSCALL_FOCUS_WINDOW 14u +#define BOB64_SYSCALL_OPEN_FILE 15u +#define BOB64_SYSCALL_READ_HANDLE 16u +#define BOB64_SYSCALL_WRITE_HANDLE 17u +#define BOB64_SYSCALL_SEEK_HANDLE 18u +#define BOB64_SYSCALL_CLOSE_HANDLE 19u +#define BOB64_SYSCALL_GET_TICKS 20u +#define BOB64_FILE_OPEN_READ 0x01u +#define BOB64_FILE_OPEN_WRITE 0x02u +#define BOB64_FILE_OPEN_CREATE 0x04u +#define BOB64_FILE_OPEN_TRUNCATE 0x08u +#define BOB64_FILE_OPEN_APPEND 0x10u +#define BOB64_FILE_OPEN_FLAGS 0x1fu +#define BOB64_SYSCALL_MAX_BUFFER 4096u +#define BOB64_SYSCALL_MAX_FILES 32u +#define BOB64_SYSCALL_MAX_SURFACE_BYTES (16u*1024u*1024u) +#define BOB64_SYSCALL_COPY_CHUNK_BYTES 4096u +#define BOB64_SYSCALL_MAX_FILENAME 63u +_Static_assert(BOB64_SYSCALL_MAX_SURFACE_BYTES%sizeof(u32)==0, + "pixel-surface size is a whole number of pixels"); +_Static_assert(BOB64_SYSCALL_COPY_CHUNK_BYTES%sizeof(u32)==0, + "syscall copy chunk is a whole number of pixels"); + +typedef struct { + char Name[64]; + u64 Size; +} BOB64_FILE_INFO; + +_Static_assert(sizeof(BOB64_FILE_INFO)==72,"bob64 file-info ABI size"); + +/* The application startup block and argv strings live in the app address space. */ +typedef struct { + u32 StructSize; + u32 AbiVersion; + u64 ArgumentCount; + const char *const *Arguments; + u64 Flags; +} BOB64_APP_STARTUP; + +_Static_assert(sizeof(BOB64_APP_STARTUP)==32,"bob64 application startup ABI size"); +_Static_assert(__builtin_offsetof(BOB64_APP_STARTUP,ArgumentCount)==8, + "bob64 startup argument-count offset"); +_Static_assert(__builtin_offsetof(BOB64_APP_STARTUP,Arguments)==16, + "bob64 startup argv offset"); +_Static_assert(__builtin_offsetof(BOB64_APP_STARTUP,Flags)==24, + "bob64 startup flags offset"); + +/* GCC on non-Windows x86-64 hosts needs an explicit attribute to test the ABI. */ +#if defined(__x86_64__) && !defined(_WIN32) && defined(__GNUC__) +#define BOB64_MS_ABI __attribute__((ms_abi)) +#else +#define BOB64_MS_ABI +#endif + +/* Entry receives the app-owned startup block in RCX and returns status in RAX. */ +typedef s64 (BOB64_MS_ABI *BOB64_APP_ENTRY)(const BOB64_APP_STARTUP *startup); + +#endif diff --git a/bob64/app.h b/bob64/app.h new file mode 100644 index 0000000..c5bddd8 --- /dev/null +++ b/bob64/app.h @@ -0,0 +1,192 @@ +#ifndef BOB64_APP_H +#define BOB64_APP_H + +#include "abi.h" +#include "event.h" + +/* Native apps use int 0x80; only RAX is changed by a returning service. */ +static inline s64 bob64_app_query_abi(void) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_QUERY_ABI; + __asm__ volatile("int $0x80":"+a"(rax)::"memory","cc"); + return (s64)rax; +} + +/* Number of 100 Hz PIT ticks since kernel initialization. */ +static inline u64 bob64_app_ticks(void) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_GET_TICKS; + __asm__ volatile("int $0x80":"+a"(rax)::"memory","cc"); + return rax; +} + +/* Display size is returned as width in RAX and height in RDX. */ +static inline s64 bob64_app_get_display(u32 *width,u32 *height) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_GET_DISPLAY; + register u64 rdx __asm__("rdx"); + __asm__ volatile("int $0x80":"+a"(rax),"=d"(rdx)::"memory","cc"); + if((s64)rax<0)return (s64)rax; + if(!width||!height)return -22; + *width=(u32)rax;*height=(u32)rdx; + return 0; +} + +/* Present one packed 0x00RRGGBB pixel for every display pixel. */ +static inline s64 bob64_app_present(const u32 *pixels,u32 width,u32 height) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_PRESENT; + register u64 rcx __asm__("rcx")=(u64)(uintptr_t)pixels; + register u64 rdx __asm__("rdx")=width; + register u64 r8 __asm__("r8")=height; + __asm__ volatile("int $0x80":"+a"(rax):"c"(rcx),"d"(rdx),"r"(r8):"memory","cc"); + return (s64)rax; +} + +/* Wait for the next key press or release; the event is app-owned. */ +static inline s64 bob64_app_wait_event(BOB64_EVENT *event) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_WAIT_EVENT; + register u64 rcx __asm__("rcx")=(u64)(uintptr_t)event; + __asm__ volatile("int $0x80":"+a"(rax):"c"(rcx):"memory","cc"); + return (s64)rax; +} + +static inline s64 bob64_app_write_char(u8 character) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_WRITE_CHAR; + register u64 rcx __asm__("rcx")=character; + __asm__ volatile("int $0x80":"+a"(rax):"c"(rcx):"memory","cc"); + return (s64)rax; +} + +static inline s64 bob64_app_write(const void *buffer,usize length) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_WRITE_BUFFER; + register u64 rcx __asm__("rcx")=(u64)(uintptr_t)buffer; + register u64 rdx __asm__("rdx")=(u64)length; + __asm__ volatile("int $0x80":"+a"(rax):"c"(rcx),"d"(rdx):"memory","cc"); + return (s64)rax; +} + +/* File services use a bounded name (1..63 bytes) and at most 4096 data bytes. */ +static inline s64 bob64_app_read_file(const char *name,usize name_length, + void *buffer,usize capacity) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_READ_FILE; + register u64 rcx __asm__("rcx")=(u64)(uintptr_t)name; + register u64 rdx __asm__("rdx")=(u64)name_length; + register u64 r8 __asm__("r8")=(u64)(uintptr_t)buffer; + register u64 r9 __asm__("r9")=(u64)capacity; + __asm__ volatile("int $0x80":"+a"(rax):"c"(rcx),"d"(rdx),"r"(r8),"r"(r9):"memory","cc"); + return (s64)rax; +} + +static inline s64 bob64_app_write_file(const char *name,usize name_length, + const void *buffer,usize length) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_WRITE_FILE; + register u64 rcx __asm__("rcx")=(u64)(uintptr_t)name; + register u64 rdx __asm__("rdx")=(u64)name_length; + register u64 r8 __asm__("r8")=(u64)(uintptr_t)buffer; + register u64 r9 __asm__("r9")=(u64)length; + __asm__ volatile("int $0x80":"+a"(rax):"c"(rcx),"d"(rdx),"r"(r8),"r"(r9):"memory","cc"); + return (s64)rax; +} + +/* List at most 32 files into an app-owned array of fixed-width records. */ +static inline s64 bob64_app_list_files(BOB64_FILE_INFO *entries,usize capacity) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_LIST_FILES; + register u64 rcx __asm__("rcx")=(u64)(uintptr_t)entries; + register u64 rdx __asm__("rdx")=(u64)capacity; + __asm__ volatile("int $0x80":"+a"(rax):"c"(rcx),"d"(rdx):"memory","cc"); + return (s64)rax; +} + +static inline s64 bob64_app_delete_file(const char *name,usize name_length) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_DELETE_FILE; + register u64 rcx __asm__("rcx")=(u64)(uintptr_t)name; + register u64 rdx __asm__("rdx")=(u64)name_length; + __asm__ volatile("int $0x80":"+a"(rax):"c"(rcx),"d"(rdx):"memory","cc"); + return (s64)rax; +} + +/* Streaming file handles keep a 64-bit position and transfer at most 4096 bytes per call. */ +static inline s64 bob64_app_file_open(const char *name,usize name_length,u32 flags) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_OPEN_FILE; + register u64 rcx __asm__("rcx")=(u64)(uintptr_t)name; + register u64 rdx __asm__("rdx")=(u64)name_length; + register u64 r8 __asm__("r8")=flags; + __asm__ volatile("int $0x80":"+a"(rax):"c"(rcx),"d"(rdx),"r"(r8):"memory","cc"); + return (s64)rax; +} + +static inline s64 bob64_app_file_read(s64 handle,void *buffer,usize capacity) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_READ_HANDLE; + register u64 rcx __asm__("rcx")=(u64)handle; + register u64 rdx __asm__("rdx")=(u64)(uintptr_t)buffer; + register u64 r8 __asm__("r8")=(u64)capacity; + __asm__ volatile("int $0x80":"+a"(rax):"c"(rcx),"d"(rdx),"r"(r8):"memory","cc"); + return (s64)rax; +} + +static inline s64 bob64_app_file_write(s64 handle,const void *buffer,usize length) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_WRITE_HANDLE; + register u64 rcx __asm__("rcx")=(u64)handle; + register u64 rdx __asm__("rdx")=(u64)(uintptr_t)buffer; + register u64 r8 __asm__("r8")=(u64)length; + __asm__ volatile("int $0x80":"+a"(rax):"c"(rcx),"d"(rdx),"r"(r8):"memory","cc"); + return (s64)rax; +} + +static inline s64 bob64_app_file_seek(s64 handle,u64 offset) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_SEEK_HANDLE; + register u64 rcx __asm__("rcx")=(u64)handle; + register u64 rdx __asm__("rdx")=offset; + __asm__ volatile("int $0x80":"+a"(rax):"c"(rcx),"d"(rdx):"memory","cc"); + return (s64)rax; +} + +static inline s64 bob64_app_file_close(s64 handle) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_CLOSE_HANDLE; + register u64 rcx __asm__("rcx")=(u64)handle; + __asm__ volatile("int $0x80":"+a"(rax):"c"(rcx):"memory","cc"); + return (s64)rax; +} + +/* Kernel-owned windows composite app-owned packed RGB pixel surfaces. */ +static inline u64 bob64_app_window_create(s32 x,s32 y,u32 width,u32 height) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_CREATE_WINDOW; + register u64 rcx __asm__("rcx")=(u64)(s64)x; + register u64 rdx __asm__("rdx")=(u64)(s64)y; + register u64 r8 __asm__("r8")=width; + register u64 r9 __asm__("r9")=height; + __asm__ volatile("int $0x80":"+a"(rax):"c"(rcx),"d"(rdx),"r"(r8),"r"(r9):"memory","cc"); + return rax; +} + +static inline s64 bob64_app_window_destroy(u64 handle) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_DESTROY_WINDOW; + register u64 rcx __asm__("rcx")=handle; + __asm__ volatile("int $0x80":"+a"(rax):"c"(rcx):"memory","cc"); + return (s64)rax; +} + +static inline s64 bob64_app_window_focus(u64 handle) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_FOCUS_WINDOW; + register u64 rcx __asm__("rcx")=handle; + __asm__ volatile("int $0x80":"+a"(rax):"c"(rcx):"memory","cc"); + return (s64)rax; +} + +static inline s64 bob64_app_window_present(u64 handle,const u32 *pixels, + u32 width,u32 height) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_PRESENT_WINDOW; + register u64 rcx __asm__("rcx")=handle; + register u64 rdx __asm__("rdx")=(u64)(uintptr_t)pixels; + register u64 r8 __asm__("r8")=width; + register u64 r9 __asm__("r9")=height; + __asm__ volatile("int $0x80":"+a"(rax):"c"(rcx),"d"(rdx),"r"(r8),"r"(r9):"memory","cc"); + return (s64)rax; +} + +/* Exit transfers control to the kernel; it does not return to this caller. */ +static inline __attribute__((noreturn)) void bob64_app_exit(s64 status) { + register u64 rax __asm__("rax")=BOB64_SYSCALL_EXIT; + register u64 rcx __asm__("rcx")=(u64)status; + __asm__ volatile("int $0x80":"+a"(rax):"c"(rcx):"memory","cc"); + __builtin_unreachable(); +} + +#endif diff --git a/bob64/app_entry.S b/bob64/app_entry.S new file mode 100644 index 0000000..58fd268 --- /dev/null +++ b/bob64/app_entry.S @@ -0,0 +1,15 @@ +.intel_syntax noprefix +.text +.globl bob64_app_entry +bob64_app_entry: + /* RSP enters at 8 mod 16; reserve shadow space and align before the call. */ + sub rsp,40 + call bob64_app_main + mov rcx,rax + mov eax,3 /* BOB64_SYSCALL_EXIT in ABI v1 */ + int 0x80 + ud2 + +#ifndef __MINGW32__ +.section .note.GNU-stack,"",@progbits +#endif diff --git a/bob64/boot.c b/bob64/boot.c new file mode 100644 index 0000000..28d304e --- /dev/null +++ b/bob64/boot.c @@ -0,0 +1,213 @@ +#include "efi.h" +#include "memory.h" +#include "cpu.h" +#include "bootstrap.h" +#include "descriptors.h" +#include "interrupts.h" +#include "kernel.h" + +#define BOB64_MEMORY_MAP_CAPACITY 131072 +#define BOB64_BOOT_STACK_PAGES 8 +#define BOB64_TABLE_POOL_PAGES 128 +#define BOB64_FRAMEBUFFER_MAP_LIMIT (64ULL*1024ULL*1024ULL) + +static u8 memory_map[BOB64_MEMORY_MAP_CAPACITY] __attribute__((aligned(16))); +BOB64_PAGE_EXTENT bob64_boot_page_extents[BOB64_PAGE_EXTENT_LIMIT]; +BOB64_PAGE_ALLOCATOR bob64_boot_page_allocator; +BOB64_BOOTSTRAP_SPACE bob64_bootstrap_space; +static u64 kernel_gdt[BOB64_GDT_ENTRY_COUNT]; +BOB64_TSS bob64_kernel_tss; +static BOB64_IDT_GATE kernel_idt[BOB64_IDT_ENTRIES]; +static BOB64_DESCRIPTOR_TABLE_POINTER kernel_gdtr,kernel_idtr; +#ifdef BOB64_ENABLE_HANDOFF +static BOB64_KERNEL_BOOT_INFO kernel_boot_info; +#endif +static const EFI_GUID loaded_image_guid={0x5b1b31a1u,0x9562u,0x11d2u, + {0x8e,0x3f,0x00,0xa0,0xc9,0x69,0x72,0x3b}}; +#ifdef BOB64_ENABLE_HANDOFF +static const EFI_GUID graphics_output_guid={0x9042a9deu,0x23dcu,0x4a38u, + {0x96,0xfb,0x7a,0xde,0xd0,0x80,0x51,0x6a}}; +#endif + +static u64 *physical_identity_access(void *context,u64 physical_address) { + (void)context; + return (u64 *)(uintptr_t)physical_address; +} + +static EFI_STATUS efi_print(EFI_SYSTEM_TABLE *system,const CHAR16 *text) { + if(!system || !system->ConOut || !system->ConOut->OutputString) + return EFI_UNSUPPORTED; + return system->ConOut->OutputString(system->ConOut,text); +} + +EFI_STATUS EFIAPI efi_main(EFI_HANDLE image,EFI_SYSTEM_TABLE *system) { + static const CHAR16 active[]={'b','o','b','6','4',':',' ','l','o','n','g',' ' , + 'm','o','d','e',' ','a','c','t','i','v','e','\r','\n',0}; + static const CHAR16 unsupported[]={'b','o','b','6','4',':',' ','x','8','6','-','6','4', + ' ','l','o','n','g',' ','m','o','d','e',' ','r','e','q','u','i','r','e','d','\r','\n',0}; +#ifndef BOB64_ENABLE_HANDOFF + static const CHAR16 prepared[]={'b','o','b','6','4',':',' ','b','o','o','t','s','t','r','a','p', + ' ','p','a','g','i','n','g',' ','p','r','e','p','a','r','e','d','\r','\n',0}; +#endif +#ifdef BOB64_ENABLE_HANDOFF + static const CHAR16 handoff[]={'b','o','b','6','4',':',' ','e','x','i','t','i','n','g',' ' , + 'U','E','F','I',' ','b','o','o','t',' ','s','e','r','v','i','c','e','s','\r','\n',0}; +#endif + static const CHAR16 marker[]={'b','o','b','6','4','!','\r','\n',0}; + /* This image-base-relative pointer must be repaired if firmware relocates the PE image. */ + static const CHAR16 * volatile relocated_marker=marker; + UINTN map_capacity=sizeof(memory_map),map_size=sizeof(memory_map),map_key=0,descriptor_size=0; + u32 descriptor_version=0; + EFI_STATUS status; + EFI_MEMORY_DESCRIPTOR *map=(EFI_MEMORY_DESCRIPTOR *)memory_map; + BOB64_CPU_FEATURES cpu; + EFI_LOADED_IMAGE_PROTOCOL *loaded_image; + void *loaded_image_interface=0; +#ifdef BOB64_ENABLE_HANDOFF + EFI_GRAPHICS_OUTPUT_PROTOCOL *graphics=0; + EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *graphics_mode=0; + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *graphics_info=0; + int framebuffer_valid=0; + u64 framebuffer_map_size=0; +#endif + u64 stack_base,table_pool_base,translated; + u64 probe_page; + BOB64_PAGE_EXTENT *active_page_extents=bob64_boot_page_extents; + BOB64_PAGE_ALLOCATOR *active_page_allocator=&bob64_boot_page_allocator; + BOB64_BOOTSTRAP_SPACE *active_bootstrap_space=&bob64_bootstrap_space; + if(!system)return EFI_UNSUPPORTED; + if(bob64_cpu_detect(&cpu)||!cpu.PAE||!cpu.LongMode|| + !bob64_cpu_long_mode_active(&cpu)) { + efi_print(system,unsupported); + return EFI_UNSUPPORTED; + } +#ifdef BOB64_ENABLE_HANDOFF + if(!bob64_cpu_four_level_paging_active()) { + efi_print(system,unsupported); + return EFI_UNSUPPORTED; + } +#endif + if(EFI_ERROR(efi_print(system,active)))return EFI_UNSUPPORTED; + if(EFI_ERROR(efi_print(system,relocated_marker)))return EFI_UNSUPPORTED; + if(!system->BootServices||!system->BootServices->GetMemoryMap|| + !system->BootServices->HandleProtocol)return EFI_UNSUPPORTED; + status=system->BootServices->HandleProtocol(image,&loaded_image_guid,&loaded_image_interface); + if(EFI_ERROR(status))return status; + if(!loaded_image_interface)return EFI_UNSUPPORTED; + loaded_image=(EFI_LOADED_IMAGE_PROTOCOL *)loaded_image_interface; + if(!loaded_image->ImageBase||!loaded_image->ImageSize)return EFI_UNSUPPORTED; +#ifdef BOB64_ENABLE_HANDOFF + if(system->BootServices->LocateProtocol&& + !EFI_ERROR(system->BootServices->LocateProtocol(&graphics_output_guid,0, + (void **)&graphics))&& + graphics&&graphics->Mode&&(graphics_mode=graphics->Mode)&& + graphics_mode->Info&&(graphics_info=graphics_mode->Info)&& + (graphics_info->PixelFormat==0||graphics_info->PixelFormat==1)&& + graphics_mode->FrameBufferBase&&graphics_mode->FrameBufferSize&& + graphics_info->HorizontalResolution>=6&&graphics_info->VerticalResolution>=8&& + graphics_info->PixelsPerScanLine>=graphics_info->HorizontalResolution&& + (u64)graphics_info->PixelsPerScanLine<=~(u64)0/graphics_info->VerticalResolution) { + u64 pixels=(u64)graphics_info->PixelsPerScanLine*graphics_info->VerticalResolution; + if(pixels<=~(u64)0/4) { + framebuffer_map_size=pixels*4; + framebuffer_valid=framebuffer_map_size<=graphics_mode->FrameBufferSize&& + framebuffer_map_size<=BOB64_FRAMEBUFFER_MAP_LIMIT; + } + } +#endif + status=system->BootServices->GetMemoryMap(&map_size,map,&map_key,&descriptor_size,&descriptor_version); + if(status==EFI_BUFFER_TOO_SMALL) { + if(!system->BootServices->AllocatePool)return status; + UINTN slack=(descriptor_size?descriptor_size:sizeof(EFI_MEMORY_DESCRIPTOR))*2; + if(map_size>(~(UINTN)0)-slack)return EFI_UNSUPPORTED; + UINTN required=map_size+slack; + status=system->BootServices->AllocatePool(EFI_MEMORY_LOADER_DATA,required,(void **)&map); + if(EFI_ERROR(status))return status; + map_capacity=required;map_size=required; + status=system->BootServices->GetMemoryMap(&map_size,map,&map_key,&descriptor_size,&descriptor_version); + } + if(EFI_ERROR(status))return status; + if(descriptor_version!=1||bob64_page_allocator_init(active_page_allocator,active_page_extents, + BOB64_PAGE_EXTENT_LIMIT,cpu.PhysicalAddressBits,map,(usize)map_size, + (usize)descriptor_size)<0) + return EFI_UNSUPPORTED; + probe_page=bob64_page_alloc(active_page_allocator,1); + if(!probe_page||bob64_page_free(active_page_allocator,probe_page,1))return EFI_UNSUPPORTED; + stack_base=bob64_page_alloc(active_page_allocator,BOB64_BOOT_STACK_PAGES); + table_pool_base=bob64_page_alloc(active_page_allocator,BOB64_TABLE_POOL_PAGES); + if(!stack_base||!table_pool_base)return EFI_UNSUPPORTED; + volatile u64 *stack_words=(volatile u64 *)(uintptr_t)stack_base; + for(usize i=0;iImageBase,loaded_image->ImageSize, + stack_base,BOB64_BOOT_STACK_PAGES*EFI_PAGE_SIZE,cpu.NX)<0) + return EFI_UNSUPPORTED; + u64 image_base=(u64)(uintptr_t)loaded_image->ImageBase; + u64 map_base=(u64)(uintptr_t)map; + int map_is_in_image=map_base>=image_base&&map_base-image_base<=loaded_image->ImageSize&& + (u64)map_capacity<=loaded_image->ImageSize-(map_base-image_base); + if(!map_is_in_image&&bob64_page_map_range(&active_bootstrap_space->PageTable,map_base,map_base, + (u64)map_capacity,BOB64_PAGE_WRITE|(cpu.NX?BOB64_PAGE_NX:0))) + return EFI_UNSUPPORTED; +#ifdef BOB64_ENABLE_HANDOFF + if(framebuffer_valid&&bob64_page_map_range(&active_bootstrap_space->PageTable, + graphics_mode->FrameBufferBase,graphics_mode->FrameBufferBase, + framebuffer_map_size,BOB64_PAGE_WRITE|BOB64_PAGE_PCD|BOB64_PAGE_PWT| + (cpu.NX?BOB64_PAGE_NX:0)))framebuffer_valid=0; +#endif + if(bob64_page_translate(&active_bootstrap_space->PageTable, + (u64)(uintptr_t)loaded_image->ImageBase,&translated,0)!=1|| + translated!=(u64)(uintptr_t)loaded_image->ImageBase|| + bob64_page_translate(&active_bootstrap_space->PageTable, + stack_base+BOB64_BOOT_STACK_PAGES*EFI_PAGE_SIZE-1,&translated,0)!=1|| + translated!=stack_base+BOB64_BOOT_STACK_PAGES*EFI_PAGE_SIZE-1) + return EFI_UNSUPPORTED; +#ifdef BOB64_ENABLE_HANDOFF + if(!system->BootServices->ExitBootServices)return EFI_UNSUPPORTED; + if(EFI_ERROR(efi_print(system,handoff)))return EFI_UNSUPPORTED; + kernel_boot_info.PageTableRoot=active_bootstrap_space->PageTable.RootPhysical; + kernel_boot_info.MemoryMapAddress=map_base; + kernel_boot_info.MemoryDescriptorSize=descriptor_size; + kernel_boot_info.StackBase=stack_base; + kernel_boot_info.StackSize=BOB64_BOOT_STACK_PAGES*EFI_PAGE_SIZE; + kernel_boot_info.PhysicalAddressBits=cpu.PhysicalAddressBits; + kernel_boot_info.NxSupported=cpu.NX; + if(framebuffer_valid) { + kernel_boot_info.FramebufferBase=graphics_mode->FrameBufferBase; + kernel_boot_info.FramebufferSize=framebuffer_map_size; + kernel_boot_info.FramebufferWidth=graphics_info->HorizontalResolution; + kernel_boot_info.FramebufferHeight=graphics_info->VerticalResolution; + kernel_boot_info.FramebufferPixelsPerScanLine=graphics_info->PixelsPerScanLine; + kernel_boot_info.FramebufferPixelFormat=graphics_info->PixelFormat; + kernel_boot_info.HasFramebuffer=1; + } + for(u32 attempt=0;attempt<3;attempt++) { + map_size=map_capacity; + status=system->BootServices->GetMemoryMap(&map_size,map,&map_key,&descriptor_size, + &descriptor_version); + if(EFI_ERROR(status))return status; + if(descriptor_version!=1||!descriptor_size||map_size>map_capacity)return EFI_UNSUPPORTED; + kernel_boot_info.MemoryMapSize=map_size; + kernel_boot_info.MemoryDescriptorSize=descriptor_size; + status=system->BootServices->ExitBootServices(image,map_key); + if(!EFI_ERROR(status)) + bob64_enter_kernel(kernel_boot_info.PageTableRoot, + stack_base+BOB64_BOOT_STACK_PAGES*EFI_PAGE_SIZE,&kernel_gdtr,&kernel_idtr, + &kernel_boot_info); + if(status!=EFI_INVALID_PARAMETER)return status; + } + return status; +#else + if(EFI_ERROR(efi_print(system,prepared)))return EFI_UNSUPPORTED; + return EFI_SUCCESS; +#endif +} diff --git a/bob64/bootstrap.c b/bob64/bootstrap.c new file mode 100644 index 0000000..a891e13 --- /dev/null +++ b/bob64/bootstrap.c @@ -0,0 +1,47 @@ +#include "bootstrap.h" + +static u64 table_pool_allocate(void *context) { + BOB64_BOOTSTRAP_SPACE *space=(BOB64_BOOTSTRAP_SPACE *)context; + if(!space||space->TablePoolUsed>=space->TablePoolPages)return 0; + return space->TablePoolBase+(space->TablePoolUsed++)*BOB64_PAGE_SIZE; +} + +static u64 *table_pool_access(void *context,u64 physical_address) { + BOB64_BOOTSTRAP_SPACE *space=(BOB64_BOOTSTRAP_SPACE *)context; + if(!space||physical_addressTablePoolBase|| + (physical_address-space->TablePoolBase)%BOB64_PAGE_SIZE|| + (physical_address-space->TablePoolBase)/BOB64_PAGE_SIZE>=space->TablePoolUsed) + return 0; + return space->Access(space->AccessContext,physical_address); +} + +int bob64_bootstrap_space_init(BOB64_BOOTSTRAP_SPACE *space,u8 physical_address_bits, + BOB64_TABLE_ACCESS access,void *access_context, + u64 table_pool_base,u64 table_pool_pages, + u64 image_base,u64 image_size, + u64 stack_base,u64 stack_size,u8 nx_supported) { + u64 pool_bytes; + u64 writable_nx=BOB64_PAGE_WRITE|(nx_supported?BOB64_PAGE_NX:0); + int result; + if(!space||!access||!table_pool_pages|| + table_pool_base&(BOB64_PAGE_SIZE-1)|| + table_pool_pages>(~(u64)0)/BOB64_PAGE_SIZE|| + !image_size||!stack_size||nx_supported>1)return BOB64_PAGING_INVALID; + pool_bytes=table_pool_pages*BOB64_PAGE_SIZE; + if(table_pool_base>(~(u64)0)-pool_bytes)return BOB64_PAGING_INVALID; + space->TablePoolBase=table_pool_base;space->TablePoolPages=table_pool_pages; + space->TablePoolUsed=0;space->Access=access;space->AccessContext=access_context; + space->NxSupported=nx_supported; + if(bob64_page_table_init(&space->PageTable,physical_address_bits,table_pool_allocate, + table_pool_access,space))return BOB64_PAGING_NO_MEMORY; + result=bob64_page_map_range(&space->PageTable,image_base,image_base,image_size, + BOB64_PAGE_WRITE); + if(result)return result; + result=bob64_page_map_range(&space->PageTable,stack_base,stack_base,stack_size, + writable_nx); + if(result)return result; + result=bob64_page_map_range(&space->PageTable,table_pool_base,table_pool_base, + pool_bytes,writable_nx); + if(result)return result; + return 0; +} diff --git a/bob64/bootstrap.h b/bob64/bootstrap.h new file mode 100644 index 0000000..46b7bc0 --- /dev/null +++ b/bob64/bootstrap.h @@ -0,0 +1,23 @@ +#ifndef BOB64_BOOTSTRAP_H +#define BOB64_BOOTSTRAP_H + +#include "paging.h" + +typedef struct { + BOB64_PAGE_TABLE PageTable; + u64 TablePoolBase; + u64 TablePoolPages; + u64 TablePoolUsed; + BOB64_TABLE_ACCESS Access; + void *AccessContext; + u8 NxSupported; +} BOB64_BOOTSTRAP_SPACE; + +/* Builds identity mappings for the EFI image, replacement stack and table pool. */ +int bob64_bootstrap_space_init(BOB64_BOOTSTRAP_SPACE *space,u8 physical_address_bits, + BOB64_TABLE_ACCESS access,void *access_context, + u64 table_pool_base,u64 table_pool_pages, + u64 image_base,u64 image_size, + u64 stack_base,u64 stack_size,u8 nx_supported); + +#endif diff --git a/bob64/compiler.c b/bob64/compiler.c new file mode 100644 index 0000000..da29d7f --- /dev/null +++ b/bob64/compiler.c @@ -0,0 +1,2255 @@ +#include "compiler.h" + +#define COMPILER_FUNCTION_LIMIT 16u +#define COMPILER_CALL_LIMIT 64u +#define COMPILER_ARGUMENT_LIMIT 16u +#define COMPILER_GLOBAL_LIMIT 16u +#define COMPILER_STRUCT_LIMIT 8u +#define COMPILER_FIELD_LIMIT 16u + +typedef struct { + char Name[32]; + u16 CodeOffset; + u8 ReturnType,ArgumentCount,ArgumentTypes[COMPILER_ARGUMENT_LIMIT],Defined; +} BOB64_C_FUNCTION; + +typedef struct { + char Name[32]; + u16 DisplacementOffset; + u8 ArgumentCount,ArgumentTypes[COMPILER_ARGUMENT_LIMIT]; +} BOB64_C_CALL; + +typedef struct { + u16 ContinueTarget,BreakBranches[32],ContinueBranches[32]; + u8 BreakCount,ContinueCount; +} BOB64_C_LOOP; + +typedef struct { + u16 LocalBytes; + u8 VariableCount; +} BOB64_C_SCOPE; + +typedef struct { + char Name[32]; + u16 DataOffset,ArrayLength,InitTarget; + u8 Type,InitKind; +} BOB64_C_GLOBAL; + +typedef struct { + char Name[32]; + u16 Offset; + u8 Type; +} BOB64_C_FIELD; + +typedef struct { + char Name[32]; + u16 Size; + u8 Alignment,FieldCount; + BOB64_C_FIELD Fields[COMPILER_FIELD_LIMIT]; +} BOB64_C_STRUCT; + +typedef struct { + const char *Source; + usize Length,Position,ErrorOffset; + u8 Code[BOB64_PAGE_SIZE]; + u8 Data[BOB64_PAGE_SIZE]; + usize CodePosition,DataLength; + char VariableNames[16][32]; + s16 VariableDisplacement[16]; + u8 VariableType[16],VariableArrayLength[16],VariableCount; + u16 LocalBytes,StackBytes; + BOB64_C_FUNCTION Functions[COMPILER_FUNCTION_LIMIT]; + BOB64_C_GLOBAL Globals[COMPILER_GLOBAL_LIMIT]; + BOB64_C_STRUCT Structs[COMPILER_STRUCT_LIMIT]; + BOB64_C_CALL Calls[COMPILER_CALL_LIMIT]; + BOB64_C_LOOP Loops[16]; + BOB64_C_SCOPE Scopes[32]; + u16 FunctionSourceStart[COMPILER_FUNCTION_LIMIT]; + u16 FunctionSourceEnd[COMPILER_FUNCTION_LIMIT]; + u8 FunctionCount,GlobalCount,StructCount,CallCount,LoopDepth; + u8 FunctionSourceCount,ScopeDepth; + u64 IntegerValue; + u8 ExpressionType,IntegerType; + u8 ReturnType,Return64,Failed,ControlDepth; +} BOB64_C_COMPILER; + +static int compiler_emit(BOB64_C_COMPILER *compiler,u8 value); +static int compiler_emit_u32(BOB64_C_COMPILER *compiler,u32 value); + +#define COMPILER_TYPE_INT 1u +#define COMPILER_TYPE_LONG_LONG 2u +#define COMPILER_TYPE_INT_POINTER 3u +#define COMPILER_TYPE_INT_ARRAY 4u +#define COMPILER_TYPE_CHAR 5u +#define COMPILER_TYPE_CHAR_POINTER 6u +#define COMPILER_TYPE_CHAR_ARRAY 7u +#define COMPILER_TYPE_SHORT 8u +#define COMPILER_TYPE_SHORT_POINTER 9u +#define COMPILER_TYPE_SHORT_ARRAY 10u +#define COMPILER_TYPE_USIZE 11u +#define COMPILER_TYPE_VOID 12u +#define COMPILER_TYPE_ISIZE_POINTER 13u +#define COMPILER_TYPE_USIZE_POINTER 14u +#define COMPILER_TYPE_LONG_LONG_ARRAY 15u +#define COMPILER_TYPE_STRUCT_BASE 16u +#define COMPILER_TYPE_USIZE_ARRAY 24u +#define COMPILER_TYPE_STRUCT_POINTER_BASE 64u + +static int compiler_is_pointer(u8 type) { + return type==COMPILER_TYPE_INT_POINTER||type==COMPILER_TYPE_CHAR_POINTER|| + type==COMPILER_TYPE_SHORT_POINTER||type==COMPILER_TYPE_ISIZE_POINTER|| + type==COMPILER_TYPE_USIZE_POINTER|| + (type>=COMPILER_TYPE_STRUCT_POINTER_BASE&& + type=COMPILER_TYPE_STRUCT_POINTER_BASE&& + typeStructs[type-COMPILER_TYPE_STRUCT_POINTER_BASE].Size; + return 4u; +} + +static u8 compiler_pointer_type(u8 value_type) { + if(value_type==COMPILER_TYPE_CHAR||value_type==COMPILER_TYPE_CHAR_ARRAY) + return COMPILER_TYPE_CHAR_POINTER; + if(value_type==COMPILER_TYPE_SHORT||value_type==COMPILER_TYPE_SHORT_ARRAY) + return COMPILER_TYPE_SHORT_POINTER; + if(value_type==COMPILER_TYPE_LONG_LONG||value_type==COMPILER_TYPE_LONG_LONG_ARRAY) + return COMPILER_TYPE_ISIZE_POINTER; + if(value_type==COMPILER_TYPE_USIZE||value_type==COMPILER_TYPE_USIZE_ARRAY) + return COMPILER_TYPE_USIZE_POINTER; + return COMPILER_TYPE_INT_POINTER; +} + +static int compiler_emit_scale_register(BOB64_C_COMPILER *compiler,u32 scale, + u8 register_id) { + if(scale==1)return 1; + if(scale==2||scale==4||scale==8) { + u8 shift=scale==2?1:(scale==4?2:3); + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0xc1)&& + compiler_emit(compiler,register_id?0xe1:0xe0)&& + compiler_emit(compiler,shift); + } + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x69)&& + compiler_emit(compiler,register_id?0xc9:0xc0)&& + compiler_emit_u32(compiler,scale); +} + +static void compiler_skip(BOB64_C_COMPILER *compiler) { + for(;;) { + while(compiler->PositionLength&& + (compiler->Source[compiler->Position]==' '|| + compiler->Source[compiler->Position]=='\t'|| + compiler->Source[compiler->Position]=='\r'|| + compiler->Source[compiler->Position]=='\n'))compiler->Position++; + if(compiler->Position+1Length&& + compiler->Source[compiler->Position]=='/'&& + compiler->Source[compiler->Position+1]=='/') { + while(compiler->PositionLength&& + compiler->Source[compiler->Position]!='\n')compiler->Position++; + } else if(compiler->Position+1Length&& + compiler->Source[compiler->Position]=='/'&& + compiler->Source[compiler->Position+1]=='*') { + compiler->Position+=2; + while(compiler->Position+1Length&& + !(compiler->Source[compiler->Position]=='*'&& + compiler->Source[compiler->Position+1]=='/'))compiler->Position++; + if(compiler->Position+1>=compiler->Length) { + compiler->Failed=1;compiler->ErrorOffset=compiler->Position;return; + } + compiler->Position+=2; + } else return; + } +} + +static int compiler_take(BOB64_C_COMPILER *compiler,char value) { + compiler_skip(compiler); + if(compiler->Failed||compiler->Position>=compiler->Length|| + compiler->Source[compiler->Position]!=value)return 0; + compiler->Position++;return 1; +} + +static int compiler_word(BOB64_C_COMPILER *compiler,const char *word) { + usize start,length=0; + compiler_skip(compiler);start=compiler->Position; + while(word[length])length++; + if(compiler->Failed||length>compiler->Length-start)return 0; + for(usize i=0;iSource[start+i]!=word[i])return 0; + if(start+lengthLength) { + char next=compiler->Source[start+length]; + if((next>='a'&&next<='z')||(next>='A'&&next<='Z')|| + (next>='0'&&next<='9')||next=='_')return 0; + } + compiler->Position+=length;return 1; +} + +static u8 compiler_long_type(BOB64_C_COMPILER *compiler) { + if(!compiler_word(compiler,"long"))return 0; + /* bob64 follows LLP64: long is 32-bit; long long is 64-bit. */ + return compiler_word(compiler,"long")?COMPILER_TYPE_LONG_LONG:COMPILER_TYPE_INT; +} + +static u8 compiler_integer_type(BOB64_C_COMPILER *compiler) { + if(compiler_word(compiler,"int"))return COMPILER_TYPE_INT; + if(compiler_word(compiler,"short"))return COMPILER_TYPE_SHORT; + if(compiler_word(compiler,"usize")||compiler_word(compiler,"uintptr_t")) + return COMPILER_TYPE_USIZE; + if(compiler_word(compiler,"isize")||compiler_word(compiler,"intptr_t")) + return COMPILER_TYPE_LONG_LONG; + return compiler_long_type(compiler); +} + +static int compiler_identifier(BOB64_C_COMPILER *compiler,char *name,usize capacity) { + usize length=0; + compiler_skip(compiler); + if(compiler->Position>=compiler->Length)return 0; + char first=compiler->Source[compiler->Position]; + if(!((first>='a'&&first<='z')||(first>='A'&&first<='Z')||first=='_'))return 0; + while(compiler->PositionLength) { + char next=compiler->Source[compiler->Position]; + if(!((next>='a'&&next<='z')||(next>='A'&&next<='Z')|| + (next>='0'&&next<='9')||next=='_'))break; + if(length+1>=capacity)return 0; + name[length++]=next;compiler->Position++; + } + name[length]=0;return 1; +} + +static int compiler_struct_find(BOB64_C_COMPILER *compiler,const char *name); + +static int compiler_function_signature(BOB64_C_COMPILER *compiler,char *name, + usize name_capacity,u8 *return_type,u8 *argument_count, + u8 argument_types[COMPILER_ARGUMENT_LIMIT], + char parameter_names[COMPILER_ARGUMENT_LIMIT][32],int require_names) { + u32 count=0; + int void_type=compiler_word(compiler,"void"); + int character_type=!void_type&&compiler_word(compiler,"char"); + int struct_type=-1; + u8 value_type=void_type?COMPILER_TYPE_VOID: + (character_type?COMPILER_TYPE_CHAR:compiler_integer_type(compiler)); + if(!void_type&&!character_type&&!value_type) { + if(!compiler_word(compiler,"struct"))return 0; + char struct_name[32]; + if(!compiler_identifier(compiler,struct_name,sizeof(struct_name)))return 0; + struct_type=compiler_struct_find(compiler,struct_name); + if(struct_type<0)return 0; + } + int return_pointer=compiler_take(compiler,'*'); + if((struct_type>=0&&!return_pointer)||(void_type&&return_pointer))return 0; + *return_type=struct_type>=0? + (u8)(COMPILER_TYPE_STRUCT_POINTER_BASE+(u32)struct_type): + (return_pointer?compiler_pointer_type(value_type):value_type); + if(!*return_type)return 0; + if(!compiler_identifier(compiler,name,name_capacity)||!compiler_take(compiler,'('))return 0; + if(!compiler_take(compiler,')')) { + if(compiler_word(compiler,"void")) { + if(!compiler_take(compiler,')'))return 0; + } else { + for(;;) { + int pointer,has_name; + if(count>=COMPILER_ARGUMENT_LIMIT)return 0; + int character_type=compiler_word(compiler,"char"); + u8 value_type=character_type?COMPILER_TYPE_CHAR: + compiler_integer_type(compiler); + int struct_type=-1; + if(!character_type&&!value_type) { + if(!compiler_word(compiler,"struct"))return 0; + char struct_name[32]; + if(!compiler_identifier(compiler,struct_name,sizeof(struct_name)))return 0; + struct_type=compiler_struct_find(compiler,struct_name); + if(struct_type<0)return 0; + } + pointer=compiler_take(compiler,'*'); + if(struct_type>=0&&!pointer)return 0; + compiler_skip(compiler); + has_name=compiler_identifier(compiler,parameter_names[count], + sizeof(parameter_names[count])); + if(require_names&&!has_name)return 0; + if(!has_name)parameter_names[count][0]=0; + if(compiler_take(compiler,'[')) { + if(pointer||!compiler_take(compiler,']'))return 0; + pointer=1; + } + argument_types[count++]=struct_type>=0? + (u8)(COMPILER_TYPE_STRUCT_POINTER_BASE+(u32)struct_type): + (pointer?compiler_pointer_type(value_type):value_type); + if(compiler_take(compiler,')'))break; + if(!compiler_take(compiler,','))return 0; + } + } + } + *argument_count=(u8)count; + return 1; +} + +static int compiler_variable_find(BOB64_C_COMPILER *compiler,const char *name) { + for(u32 i=compiler->VariableCount;i>0;i--) { + usize position=0; + u32 variable=i-1; + while(compiler->VariableNames[variable][position]&& + compiler->VariableNames[variable][position]==name[position])position++; + if(!compiler->VariableNames[variable][position]&&!name[position]) + return (int)variable; + } + for(u32 i=0;iGlobalCount;i++) { + usize position=0; + while(compiler->Globals[i].Name[position]&& + compiler->Globals[i].Name[position]==name[position])position++; + if(!compiler->Globals[i].Name[position]&&!name[position])return (int)(0x8000u|i); + } + return -1; +} + +static int compiler_scope_push(BOB64_C_COMPILER *compiler) { + if(compiler->ScopeDepth>=sizeof(compiler->Scopes)/sizeof(compiler->Scopes[0])) + return 0; + BOB64_C_SCOPE *scope=&compiler->Scopes[compiler->ScopeDepth++]; + scope->VariableCount=compiler->VariableCount; + scope->LocalBytes=compiler->LocalBytes; + return 1; +} + +static void compiler_scope_pop(BOB64_C_COMPILER *compiler) { + if(!compiler->ScopeDepth)return; + BOB64_C_SCOPE *scope=&compiler->Scopes[--compiler->ScopeDepth]; + compiler->VariableCount=scope->VariableCount; + compiler->LocalBytes=scope->LocalBytes; +} + +static int compiler_struct_find(BOB64_C_COMPILER *compiler,const char *name) { + for(u32 i=0;iStructCount;i++) { + usize position=0; + while(compiler->Structs[i].Name[position]&& + compiler->Structs[i].Name[position]==name[position])position++; + if(!compiler->Structs[i].Name[position]&&!name[position])return (int)i; + } + return -1; +} + +static int compiler_type_is_struct(u8 type) { + return type>=COMPILER_TYPE_STRUCT_BASE&& + typeStructs[type-COMPILER_TYPE_STRUCT_BASE].Size; + if(type==COMPILER_TYPE_CHAR)return 1; + if(type==COMPILER_TYPE_SHORT)return 2; + if(type==COMPILER_TYPE_SHORT_ARRAY)return 2; + if(type==COMPILER_TYPE_INT||type==COMPILER_TYPE_INT_ARRAY)return 4; + if(type==COMPILER_TYPE_LONG_LONG_ARRAY||type==COMPILER_TYPE_USIZE_ARRAY)return 8; + return 8; +} + +static u32 compiler_type_alignment(BOB64_C_COMPILER *compiler,u8 type) { + if(compiler_type_is_struct(type)) + return compiler->Structs[type-COMPILER_TYPE_STRUCT_BASE].Alignment; + u32 size=compiler_type_size(compiler,type); + return size>=8?8:(size>=4?4:(size>=2?2:1)); +} + +static int compiler_field_find(BOB64_C_COMPILER *compiler,u8 struct_type, + const char *name) { + if(!compiler_type_is_struct(struct_type))return -1; + BOB64_C_STRUCT *structure=&compiler->Structs[struct_type-COMPILER_TYPE_STRUCT_BASE]; + for(u32 i=0;iFieldCount;i++) { + usize position=0; + while(structure->Fields[i].Name[position]&& + structure->Fields[i].Name[position]==name[position])position++; + if(!structure->Fields[i].Name[position]&&!name[position])return (int)i; + } + return -1; +} + +static int compiler_variable_is_global(u32 variable) { + return (variable&0x8000u)!=0; +} + +static u8 compiler_variable_type(BOB64_C_COMPILER *compiler,u32 variable) { + return compiler_variable_is_global(variable)? + compiler->Globals[variable&0x7fffu].Type:compiler->VariableType[variable]; +} + +static u32 compiler_variable_array_length(BOB64_C_COMPILER *compiler,u32 variable) { + return compiler_variable_is_global(variable)? + compiler->Globals[variable&0x7fffu].ArrayLength: + compiler->VariableArrayLength[variable]; +} + +static int compiler_emit_global_displacement(BOB64_C_COMPILER *compiler,u32 variable) { + BOB64_C_GLOBAL *global=&compiler->Globals[variable&0x7fffu]; + s64 displacement=(s64)(BOB64_PAGE_SIZE+global->DataOffset)- + (s64)(compiler->CodePosition+4u); + if(displacement<(-2147483647LL-1)||displacement>2147483647)return 0; + return compiler_emit_u32(compiler,(u32)(s32)displacement); +} + +static int compiler_emit_data_displacement(BOB64_C_COMPILER *compiler,u16 data_offset) { + s64 displacement=(s64)(BOB64_PAGE_SIZE+data_offset)- + (s64)(compiler->CodePosition+4u); + if(displacement<(-2147483647LL-1)||displacement>2147483647)return 0; + return compiler_emit_u32(compiler,(u32)(s32)displacement); +} + +static int compiler_emit_global_initializers(BOB64_C_COMPILER *compiler) { + for(u32 i=0;iGlobalCount;i++) { + BOB64_C_GLOBAL *global=&compiler->Globals[i]; + if(!global->InitKind)continue; + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x8d)|| + !compiler_emit(compiler,0x05)|| + !compiler_emit_data_displacement(compiler,global->InitTarget)|| + !compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x89)|| + !compiler_emit(compiler,0x05)|| + !compiler_emit_global_displacement(compiler,0x8000u|i))return 0; + } + return 1; +} + +static int compiler_function_find(BOB64_C_COMPILER *compiler,const char *name) { + for(u32 i=0;iFunctionCount;i++) { + usize position=0; + while(compiler->Functions[i].Name[position]&& + compiler->Functions[i].Name[position]==name[position])position++; + if(!compiler->Functions[i].Name[position]&&!name[position])return (int)i; + } + return -1; +} + +static int compiler_function_declare(BOB64_C_COMPILER *compiler,const char *name, + u16 code_offset,u8 return_type,u8 argument_count, + const u8 *argument_types,int defined) { + if(argument_count>COMPILER_ARGUMENT_LIMIT)return 0; + int existing=compiler_function_find(compiler,name); + if(existing>=0) { + BOB64_C_FUNCTION *function=&compiler->Functions[existing]; + if(function->ReturnType!=return_type||function->ArgumentCount!=argument_count|| + (defined&&function->Defined))return 0; + for(u32 i=0;iArgumentTypes[i]!=argument_types[i])return 0; + if(defined) { + function->CodeOffset=code_offset; + function->Defined=1; + } + return 1; + } + if(compiler->FunctionCount>=COMPILER_FUNCTION_LIMIT)return 0; + u32 index=compiler->FunctionCount++; + BOB64_C_FUNCTION *function=&compiler->Functions[index]; + usize position=0; + while(name[position]&&position+1Name)) { + function->Name[position]=name[position];position++; + } + if(name[position])return 0; + function->Name[position]=0; + function->CodeOffset=code_offset; + function->ReturnType=return_type; + function->ArgumentCount=argument_count; + function->Defined=(u8)defined; + for(u32 i=0;iArgumentTypes[i]=argument_types[i]; + return 1; +} + +static int compiler_variable_load(BOB64_C_COMPILER *compiler,u32 variable) { + if(compiler_variable_is_global(variable)) { + u8 type=compiler_variable_type(compiler,variable); + if(type==COMPILER_TYPE_CHAR) + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x0f)&& + compiler_emit(compiler,0xbe)&&compiler_emit(compiler,0x05)&& + compiler_emit_global_displacement(compiler,variable); + if(type==COMPILER_TYPE_SHORT) + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x0f)&& + compiler_emit(compiler,0xbf)&&compiler_emit(compiler,0x05)&& + compiler_emit_global_displacement(compiler,variable); + if(type==COMPILER_TYPE_LONG_LONG||type==COMPILER_TYPE_USIZE|| + compiler_is_pointer(type)) + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x8b)&& + compiler_emit(compiler,0x05)&& + compiler_emit_global_displacement(compiler,variable); + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x63)&& + compiler_emit(compiler,0x05)&& + compiler_emit_global_displacement(compiler,variable); + } + s8 displacement=(s8)compiler->VariableDisplacement[variable]; + if(compiler->VariableType[variable]==COMPILER_TYPE_CHAR) + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x0f)&& + compiler_emit(compiler,0xbe)&&compiler_emit(compiler,0x45)&& + compiler_emit(compiler,(u8)displacement); + if(compiler->VariableType[variable]==COMPILER_TYPE_SHORT) + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x0f)&& + compiler_emit(compiler,0xbf)&&compiler_emit(compiler,0x45)&& + compiler_emit(compiler,(u8)displacement); + if(compiler->VariableType[variable]==COMPILER_TYPE_LONG_LONG|| + compiler->VariableType[variable]==COMPILER_TYPE_USIZE|| + compiler_is_pointer(compiler->VariableType[variable])) + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x8b)&& + compiler_emit(compiler,0x45)&&compiler_emit(compiler,(u8)displacement); + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x63)&& + compiler_emit(compiler,0x45)&&compiler_emit(compiler,(u8)displacement); +} + +static int compiler_variable_store(BOB64_C_COMPILER *compiler,u32 variable) { + if(compiler_variable_is_global(variable)) { + u8 type=compiler_variable_type(compiler,variable); + if(type==COMPILER_TYPE_CHAR) + return compiler_emit(compiler,0x88)&&compiler_emit(compiler,0x05)&& + compiler_emit_global_displacement(compiler,variable); + if(type==COMPILER_TYPE_SHORT) + return compiler_emit(compiler,0x66)&&compiler_emit(compiler,0x89)&& + compiler_emit(compiler,0x05)&& + compiler_emit_global_displacement(compiler,variable); + if(type==COMPILER_TYPE_LONG_LONG||type==COMPILER_TYPE_USIZE|| + compiler_is_pointer(type)) + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x89)&& + compiler_emit(compiler,0x05)&& + compiler_emit_global_displacement(compiler,variable); + return compiler_emit(compiler,0x89)&&compiler_emit(compiler,0x05)&& + compiler_emit_global_displacement(compiler,variable); + } + s8 displacement=(s8)compiler->VariableDisplacement[variable]; + if(compiler->VariableType[variable]==COMPILER_TYPE_CHAR) + return compiler_emit(compiler,0x88)&&compiler_emit(compiler,0x45)&& + compiler_emit(compiler,(u8)displacement); + if(compiler->VariableType[variable]==COMPILER_TYPE_SHORT) + return compiler_emit(compiler,0x66)&&compiler_emit(compiler,0x89)&& + compiler_emit(compiler,0x45)&&compiler_emit(compiler,(u8)displacement); + if(compiler->VariableType[variable]==COMPILER_TYPE_LONG_LONG|| + compiler->VariableType[variable]==COMPILER_TYPE_USIZE|| + compiler_is_pointer(compiler->VariableType[variable])) + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x89)&& + compiler_emit(compiler,0x45)&&compiler_emit(compiler,(u8)displacement); + return compiler_emit(compiler,0x89)&&compiler_emit(compiler,0x45)&& + compiler_emit(compiler,(u8)displacement); +} + +static int compiler_variable_address(BOB64_C_COMPILER *compiler,u32 variable, + u8 destination_register) { + if(compiler_variable_is_global(variable)) + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x8d)&& + compiler_emit(compiler,(u8)(0x05u|(destination_register<<3)))&& + compiler_emit_global_displacement(compiler,variable); + s8 displacement=(s8)compiler->VariableDisplacement[variable]; + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x8d)&& + compiler_emit(compiler,(u8)(0x45u|(destination_register<<3)))&& + compiler_emit(compiler,(u8)displacement); +} + +static int compiler_member_address(BOB64_C_COMPILER *compiler,u32 variable, + const BOB64_C_FIELD *field) { + if(!compiler_variable_address(compiler,variable,0))return 0; + if(!field->Offset)return 1; + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x05)&& + compiler_emit_u32(compiler,field->Offset); +} + +static int compiler_member_load(BOB64_C_COMPILER *compiler,u8 type) { + if(type==COMPILER_TYPE_CHAR) + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x0f)&& + compiler_emit(compiler,0xbe)&&compiler_emit(compiler,0x00); + if(type==COMPILER_TYPE_SHORT) + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x0f)&& + compiler_emit(compiler,0xbf)&&compiler_emit(compiler,0x00); + if(type==COMPILER_TYPE_INT) + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x63)&& + compiler_emit(compiler,0x00); + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x8b)&& + compiler_emit(compiler,0x00); +} + +static int compiler_member_store(BOB64_C_COMPILER *compiler,u8 type) { + if(type==COMPILER_TYPE_CHAR) + return compiler_emit(compiler,0x88)&&compiler_emit(compiler,0x01); + if(type==COMPILER_TYPE_SHORT) + return compiler_emit(compiler,0x66)&&compiler_emit(compiler,0x89)&& + compiler_emit(compiler,0x01); + if(type==COMPILER_TYPE_INT) + return compiler_emit(compiler,0x89)&&compiler_emit(compiler,0x01); + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x89)&& + compiler_emit(compiler,0x01); +} + +static int compiler_add_variable(BOB64_C_COMPILER *compiler,const char *name, + u8 type,u32 array_length,u32 *variable_out) { + usize length=0; + u32 bytes; + u32 scope_start=compiler->ScopeDepth? + compiler->Scopes[compiler->ScopeDepth-1].VariableCount:0; + for(u32 i=scope_start;iVariableCount;i++) { + usize position=0; + while(compiler->VariableNames[i][position]&& + compiler->VariableNames[i][position]==name[position])position++; + if(!compiler->VariableNames[i][position]&&!name[position])return 0; + } + if(compiler->VariableCount>=16)return 0; + if(type==COMPILER_TYPE_INT_ARRAY) { + if(!array_length||array_length>32)return 0; + bytes=array_length*4; + compiler->LocalBytes=(u16)((compiler->LocalBytes+3u)&~3u); + } else if(type==COMPILER_TYPE_SHORT_ARRAY) { + if(!array_length||array_length>64)return 0; + bytes=array_length*2; + compiler->LocalBytes=(u16)((compiler->LocalBytes+1u)&~1u); + } else if(type==COMPILER_TYPE_CHAR_ARRAY) { + if(!array_length||array_length>128)return 0; + bytes=array_length; + } else if(type==COMPILER_TYPE_LONG_LONG_ARRAY||type==COMPILER_TYPE_USIZE_ARRAY) { + if(!array_length||array_length>16)return 0; + bytes=array_length*8u; + compiler->LocalBytes=(u16)((compiler->LocalBytes+7u)&~7u); + } else if(compiler_type_is_struct(type)) { + u32 alignment=compiler_type_alignment(compiler,type); + compiler->LocalBytes=(u16)((compiler->LocalBytes+alignment-1u)&~(alignment-1u)); + bytes=compiler_type_size(compiler,type); + } else { + bytes=8; + compiler->LocalBytes=(u16)((compiler->LocalBytes+7u)&~7u); + } + if(bytes>128u-compiler->LocalBytes)return 0; + compiler->LocalBytes=(u16)(compiler->LocalBytes+bytes); + u32 variable=compiler->VariableCount++; + while(name[length])length++; + for(usize i=0;i<=length;i++)compiler->VariableNames[variable][i]=name[i]; + compiler->VariableType[variable]=type; + compiler->VariableArrayLength[variable]=(u8)array_length; + compiler->VariableDisplacement[variable]=-(s16)compiler->LocalBytes; + if(variable_out)*variable_out=variable; + return 1; +} + +static int compiler_integer(BOB64_C_COMPILER *compiler,u64 *value) { + u64 number=0;u32 base=10;usize digits=0; + int has_unsigned=0,long_count=0,unsigned_after_long=0; + compiler_skip(compiler); + if(compiler->Position+1Length&&compiler->Source[compiler->Position]=='0'&& + (compiler->Source[compiler->Position+1]=='x'|| + compiler->Source[compiler->Position+1]=='X')) { + base=16;compiler->Position+=2; + } + while(compiler->PositionLength) { + char character=compiler->Source[compiler->Position]; + u32 digit; + if(character>='0'&&character<='9')digit=(u32)(character-'0'); + else if(base==16&&character>='a'&&character<='f')digit=(u32)(character-'a'+10); + else if(base==16&&character>='A'&&character<='F')digit=(u32)(character-'A'+10); + else break; + if(digit>=base||number>(~(u64)0-digit)/base)return 0; + number=number*base+digit;digits++;compiler->Position++; + } + if(!digits)return 0; + while(compiler->PositionLength) { + char suffix=compiler->Source[compiler->Position]; + if((suffix=='u'||suffix=='U')&&!has_unsigned) { + has_unsigned=1;if(long_count)unsigned_after_long=1;compiler->Position++; + } else if((suffix=='l'||suffix=='L')&&long_count<2) { + if(unsigned_after_long)return 0; + long_count++;compiler->Position++; + } else break; + } + if(compiler->PositionLength) { + char next=compiler->Source[compiler->Position]; + if((next>='a'&&next<='z')||(next>='A'&&next<='Z')||next=='_')return 0; + } + *value=number; + compiler->IntegerType=has_unsigned?COMPILER_TYPE_USIZE: + ((long_count||number>0x7fffffffu)?COMPILER_TYPE_LONG_LONG:COMPILER_TYPE_INT); + return 1; +} + +static int compiler_string(BOB64_C_COMPILER *compiler,usize *offset,usize *length) { + compiler_skip(compiler); + if(compiler->Position>=compiler->Length||compiler->Source[compiler->Position]!='"')return 0; + compiler->Position++;*offset=compiler->DataLength;*length=0; + while(compiler->PositionLength&&compiler->Source[compiler->Position]!='"') { + u8 value=(u8)compiler->Source[compiler->Position++]; + if(value=='\\') { + if(compiler->Position>=compiler->Length)return 0; + value=(u8)compiler->Source[compiler->Position++]; + if(value=='n')value='\n';else if(value=='r')value='\r'; + else if(value=='t')value='\t'; + else if(value!='\\'&&value!='"'&&value!='\'')return 0; + } + if(!value||*length>=BOB64_SYSCALL_MAX_BUFFER|| + compiler->DataLength>=sizeof(compiler->Data))return 0; + compiler->Data[compiler->DataLength++]=value;(*length)++; + } + if(compiler->Position>=compiler->Length)return 0; + compiler->Position++; + if(compiler->DataLength>=sizeof(compiler->Data))return 0; + compiler->Data[compiler->DataLength++]=0; + return 1; +} + +static int compiler_character(BOB64_C_COMPILER *compiler,u64 *value) { + compiler_skip(compiler); + if(compiler->Position>=compiler->Length||compiler->Source[compiler->Position]!='\'') + return 0; + compiler->Position++; + if(compiler->Position>=compiler->Length)return 0; + u8 character=(u8)compiler->Source[compiler->Position++]; + if(character=='\\') { + if(compiler->Position>=compiler->Length)return 0; + character=(u8)compiler->Source[compiler->Position++]; + if(character=='n')character='\n';else if(character=='r')character='\r'; + else if(character=='t')character='\t';else if(character=='0')character=0; + else if(character!='\\'&&character!='\''&&character!='"')return 0; + } + if(compiler->Position>=compiler->Length|| + compiler->Source[compiler->Position++]!='\'')return 0; + *value=(u64)(s64)(s8)character; + return 1; +} + +static int compiler_emit(BOB64_C_COMPILER *compiler,u8 value) { + if(compiler->CodePosition>=sizeof(compiler->Code))return 0; + compiler->Code[compiler->CodePosition++]=value;return 1; +} + +static int compiler_emit_u32(BOB64_C_COMPILER *compiler,u32 value) { + for(u32 i=0;i<4;i++)if(!compiler_emit(compiler,(u8)(value>>(i*8))))return 0; + return 1; +} + +static int compiler_emit_u64(BOB64_C_COMPILER *compiler,u64 value) { + for(u32 i=0;i<8;i++)if(!compiler_emit(compiler,(u8)(value>>(i*8))))return 0; + return 1; +} + +static int compiler_emit_integer(BOB64_C_COMPILER *compiler,u64 value) { + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0xb8)&& + compiler_emit_u64(compiler,value); +} + +static int compiler_expression(BOB64_C_COMPILER *compiler); +static int compiler_emit_branch(BOB64_C_COMPILER *compiler,u8 opcode, + u16 *displacement_offset); +static int compiler_patch_branch(BOB64_C_COMPILER *compiler,u16 displacement_offset, + usize target); +static int compiler_for_post(BOB64_C_COMPILER *compiler); + +static int compiler_emit_call(BOB64_C_COMPILER *compiler,const char *name) { + u8 argument_types[COMPILER_ARGUMENT_LIMIT]; + u32 argument_count=0; + u16 saved_stack_bytes=compiler->StackBytes; + if(!compiler_take(compiler,'('))return 0; + if(!compiler_take(compiler,')')) { + for(;;) { + if(argument_count>=COMPILER_ARGUMENT_LIMIT|| + !compiler_expression(compiler)|| + compiler->ExpressionType==COMPILER_TYPE_VOID)return 0; + argument_types[argument_count++]=compiler->ExpressionType; + if(!compiler_emit(compiler,0x50))return 0; + compiler->StackBytes+=8; + if(compiler_take(compiler,')'))break; + if(!compiler_take(compiler,','))return 0; + } + } + if(compiler->CallCount>=COMPILER_CALL_LIMIT)return 0; + u32 stack_argument_bytes=argument_count>4?(argument_count-4u)*8u:0u; + u32 outgoing_bytes=32u+stack_argument_bytes; + u32 allocation=outgoing_bytes+ + ((16u-((compiler->StackBytes+outgoing_bytes)&15u))&15u); + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x83)|| + !compiler_emit(compiler,0xec)||!compiler_emit(compiler,(u8)allocation))return 0; + compiler->StackBytes=(u16)(compiler->StackBytes+allocation); + for(u32 i=0;iCalls[compiler->CallCount++]; + usize name_length=0; + while(name[name_length]&&name_length+1Name)) { + call->Name[name_length]=name[name_length];name_length++; + } + if(name[name_length])return 0; + call->Name[name_length]=0; + call->ArgumentCount=(u8)argument_count; + for(u32 i=0;iArgumentTypes[i]=argument_types[i]; + if(!compiler_emit(compiler,0xe8))return 0; + call->DisplacementOffset=(u16)compiler->CodePosition; + if(!compiler_emit_u32(compiler,0))return 0; + u32 cleanup=allocation+argument_count*8u; + if(cleanup<=127u) { + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x83)|| + !compiler_emit(compiler,0xc4)||!compiler_emit(compiler,(u8)cleanup))return 0; + } else if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x81)|| + !compiler_emit(compiler,0xc4)|| + !compiler_emit_u32(compiler,cleanup))return 0; + /* Argument evaluation and the outgoing call frame are both temporary. + Restore the depth that was present before evaluating the arguments; + subtracting cleanup from the tracked depth underflows for ordinary calls. */ + compiler->StackBytes=saved_stack_bytes; + return 1; +} + +static int compiler_index_address(BOB64_C_COMPILER *compiler,u32 variable) { + u8 type=compiler_variable_type(compiler,variable); + if(compiler_type_is_struct_pointer(type))return 0; + if(compiler_type_is_array(type)) { + if(!compiler_variable_address(compiler,variable,2))return 0; + } else if(compiler_is_pointer(type)) { + if(!compiler_variable_load(compiler,variable)|| + !compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x89)|| + !compiler_emit(compiler,0xc2))return 0; + } else return 0; + if(!compiler_expression(compiler)||!compiler_take(compiler,']'))return 0; + if(compiler_is_pointer(compiler->ExpressionType))return 0; + /* Scale pointer offsets by the pointed-to element width. */ + u8 pointer_type=compiler_type_is_array(type)?compiler_pointer_type(type):type; + u32 scale=compiler_pointer_scale(compiler,pointer_type); + if(scale==4) { + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x8d)|| + !compiler_emit(compiler,0x04)||!compiler_emit(compiler,0x82))return 0; + } else { + if(!compiler_emit_scale_register(compiler,scale,0)|| + !compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x01)|| + !compiler_emit(compiler,0xc2)||!compiler_emit(compiler,0x48)|| + !compiler_emit(compiler,0x89)||!compiler_emit(compiler,0xd0))return 0; + } + compiler->ExpressionType=pointer_type; + return 1; +} + +static int compiler_primary(BOB64_C_COMPILER *compiler) { + u64 value; + char name[32]; + if(compiler_take(compiler,'(')) { + if(!compiler_expression(compiler)||!compiler_take(compiler,')'))return 0; + return 1; + } + if(compiler_integer(compiler,&value)) { + compiler->ExpressionType=compiler->IntegerType; + return compiler_emit_integer(compiler,value); + } + if(compiler_character(compiler,&value)) { + compiler->ExpressionType=COMPILER_TYPE_INT; + return compiler_emit_integer(compiler,value); + } + usize string_offset,string_length; + if(compiler_string(compiler,&string_offset,&string_length)) { + (void)string_length; + s64 displacement=(s64)(BOB64_PAGE_SIZE+string_offset)- + (s64)(compiler->CodePosition+7); + if(displacement<(-2147483647LL-1)||displacement>2147483647|| + !compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x8d)|| + !compiler_emit(compiler,0x05)|| + !compiler_emit_u32(compiler,(u32)(s32)displacement))return 0; + compiler->ExpressionType=COMPILER_TYPE_CHAR_POINTER; + return 1; + } + if(!compiler_identifier(compiler,name,sizeof(name)))return 0; + compiler_skip(compiler); + if(compiler->PositionLength&&compiler->Source[compiler->Position]=='(') { + int function=compiler_function_find(compiler,name); + if(compiler_variable_find(compiler,name)>=0|| + !compiler_emit_call(compiler,name))return 0; + compiler->ExpressionType=function>=0? + compiler->Functions[function].ReturnType:COMPILER_TYPE_INT; + if(compiler->ExpressionType==COMPILER_TYPE_VOID)return 0; + return 1; + } + int variable=compiler_variable_find(compiler,name); + if(variable<0)return 0; + u8 variable_type=compiler_variable_type(compiler,(u32)variable); + int pointer_member=compiler_type_is_struct_pointer(variable_type); + if(compiler_type_is_struct(variable_type)|| + (pointer_member&&compiler->Position+1Length&& + compiler->Source[compiler->Position]=='-'&& + compiler->Source[compiler->Position+1]=='>')) { + char field_name[32]; + if((pointer_member?(!compiler_take(compiler,'-')||!compiler_take(compiler,'>')): + !compiler_take(compiler,'.'))|| + !compiler_identifier(compiler,field_name,sizeof(field_name)))return 0; + u8 struct_type=pointer_member? + (u8)(COMPILER_TYPE_STRUCT_BASE+variable_type-COMPILER_TYPE_STRUCT_POINTER_BASE): + variable_type; + int field_index=compiler_field_find(compiler,struct_type,field_name); + if(field_index<0)return 0; + BOB64_C_FIELD *field=&compiler->Structs[struct_type-COMPILER_TYPE_STRUCT_BASE].Fields[field_index]; + int address_ok=pointer_member? + (compiler_variable_load(compiler,(u32)variable)&& + (!field->Offset||(compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x05)&& + compiler_emit_u32(compiler,field->Offset)))): + compiler_member_address(compiler,(u32)variable,field); + if(!address_ok|| + !compiler_member_load(compiler,field->Type))return 0; + compiler->ExpressionType=field->Type; + return 1; + } + if(compiler_take(compiler,'[')) { + if(!compiler_index_address(compiler,(u32)variable))return 0; + if(compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_CHAR_POINTER|| + compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_CHAR_ARRAY) { + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x0f)|| + !compiler_emit(compiler,0xbe)||!compiler_emit(compiler,0x00))return 0; + compiler->ExpressionType=COMPILER_TYPE_CHAR; + } else if(compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_SHORT_POINTER|| + compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_SHORT_ARRAY) { + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x0f)|| + !compiler_emit(compiler,0xbf)||!compiler_emit(compiler,0x00))return 0; + compiler->ExpressionType=COMPILER_TYPE_SHORT; + } else if(compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_USIZE_POINTER|| + compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_ISIZE_POINTER|| + compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_USIZE_ARRAY|| + compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_LONG_LONG_ARRAY) { + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x8b)|| + !compiler_emit(compiler,0x00))return 0; + compiler->ExpressionType= + (compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_USIZE_POINTER|| + compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_USIZE_ARRAY)? + COMPILER_TYPE_USIZE:COMPILER_TYPE_LONG_LONG; + } else { + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x63)|| + !compiler_emit(compiler,0x00))return 0; + compiler->ExpressionType=COMPILER_TYPE_INT; + } + return 1; + } + if(compiler_type_is_array(compiler_variable_type(compiler,(u32)variable))) { + compiler->ExpressionType=compiler_pointer_type( + compiler_variable_type(compiler,(u32)variable)); + return compiler_variable_address(compiler,(u32)variable,0); + } + compiler->ExpressionType=compiler_variable_type(compiler,(u32)variable); + return compiler_variable_load(compiler,(u32)variable); +} + +static int compiler_unary(BOB64_C_COMPILER *compiler) { + if(compiler_take(compiler,'&')) { + char name[32]; + if(!compiler_identifier(compiler,name,sizeof(name)))return 0; + int variable=compiler_variable_find(compiler,name); + u8 type=variable>=0?compiler_variable_type(compiler,(u32)variable):0; + if(variable<0||(type!=COMPILER_TYPE_INT&&type!=COMPILER_TYPE_CHAR&& + type!=COMPILER_TYPE_SHORT&&type!=COMPILER_TYPE_LONG_LONG&& + type!=COMPILER_TYPE_USIZE&&type!=COMPILER_TYPE_INT_ARRAY&& + type!=COMPILER_TYPE_CHAR_ARRAY&&type!=COMPILER_TYPE_SHORT_ARRAY&& + type!=COMPILER_TYPE_LONG_LONG_ARRAY&&type!=COMPILER_TYPE_USIZE_ARRAY&& + !compiler_type_is_struct(type)))return 0; + compiler->ExpressionType=compiler_type_is_struct(type)? + (u8)(COMPILER_TYPE_STRUCT_POINTER_BASE+type-COMPILER_TYPE_STRUCT_BASE): + compiler_pointer_type(type==COMPILER_TYPE_CHAR_ARRAY?COMPILER_TYPE_CHAR: + (type==COMPILER_TYPE_SHORT_ARRAY?COMPILER_TYPE_SHORT:type)); + return compiler_variable_address(compiler,(u32)variable,0); + } + if(compiler_take(compiler,'*')) { + if(!compiler_unary(compiler)||!compiler_is_pointer(compiler->ExpressionType)|| + compiler_type_is_struct_pointer(compiler->ExpressionType)) + return 0; + if(compiler->ExpressionType==COMPILER_TYPE_CHAR_POINTER) { + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x0f)|| + !compiler_emit(compiler,0xbe)||!compiler_emit(compiler,0x00))return 0; + compiler->ExpressionType=COMPILER_TYPE_CHAR; + } else if(compiler->ExpressionType==COMPILER_TYPE_SHORT_POINTER) { + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x0f)|| + !compiler_emit(compiler,0xbf)||!compiler_emit(compiler,0x00))return 0; + compiler->ExpressionType=COMPILER_TYPE_SHORT; + } else if(compiler->ExpressionType==COMPILER_TYPE_USIZE_POINTER|| + compiler->ExpressionType==COMPILER_TYPE_ISIZE_POINTER) { + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x8b)|| + !compiler_emit(compiler,0x00))return 0; + compiler->ExpressionType=compiler->ExpressionType==COMPILER_TYPE_USIZE_POINTER? + COMPILER_TYPE_USIZE:COMPILER_TYPE_LONG_LONG; + } else { + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x63)|| + !compiler_emit(compiler,0x00))return 0; + compiler->ExpressionType=COMPILER_TYPE_INT; + } + return 1; + } + if(compiler_take(compiler,'!')) { + if(!compiler_unary(compiler)||!compiler_emit(compiler,0x48)|| + !compiler_emit(compiler,0x85)||!compiler_emit(compiler,0xc0)|| + !compiler_emit(compiler,0x0f)||!compiler_emit(compiler,0x94)|| + !compiler_emit(compiler,0xc0)||!compiler_emit(compiler,0x0f)|| + !compiler_emit(compiler,0xb6)||!compiler_emit(compiler,0xc0))return 0; + compiler->ExpressionType=COMPILER_TYPE_INT; + return 1; + } + if(compiler_take(compiler,'-')) { + if(!compiler_unary(compiler)||compiler_is_pointer(compiler->ExpressionType)|| + !compiler_emit(compiler,0x48)||!compiler_emit(compiler,0xf7)|| + !compiler_emit(compiler,0xd8))return 0; + if(compiler->ExpressionType!=COMPILER_TYPE_USIZE) + compiler->ExpressionType=COMPILER_TYPE_INT; + return 1; + } + return compiler_primary(compiler); +} + +static int compiler_term(BOB64_C_COMPILER *compiler) { + if(!compiler_unary(compiler))return 0; + for(;;) { + u8 left_type=compiler->ExpressionType; + compiler_skip(compiler); + if(compiler->Position>=compiler->Length||compiler->Source[compiler->Position]!='*')return 1; + compiler->Position++; + if(compiler_is_pointer(compiler->ExpressionType)|| + !compiler_emit(compiler,0x50))return 0; + compiler->StackBytes+=8; + if(!compiler_unary(compiler)|| + compiler_is_pointer(compiler->ExpressionType)|| + !compiler_emit(compiler,0x59)||!compiler_emit(compiler,0x48)|| + !compiler_emit(compiler,0x0f)||!compiler_emit(compiler,0xaf)|| + !compiler_emit(compiler,0xc1))return 0; + compiler->StackBytes-=8; + compiler->ExpressionType=left_type==COMPILER_TYPE_USIZE|| + compiler->ExpressionType==COMPILER_TYPE_USIZE? + COMPILER_TYPE_USIZE: + (left_type==COMPILER_TYPE_LONG_LONG|| + compiler->ExpressionType==COMPILER_TYPE_LONG_LONG? + COMPILER_TYPE_LONG_LONG:COMPILER_TYPE_INT); + } +} + +static int compiler_additive(BOB64_C_COMPILER *compiler) { + if(!compiler_term(compiler))return 0; + for(;;) { + char operation; + u8 left_type=compiler->ExpressionType,right_type; + compiler_skip(compiler); + if(compiler->Position>=compiler->Length)return 1; + operation=compiler->Source[compiler->Position]; + if(operation!='+'&&operation!='-')return 1; + compiler->Position++; + if(!compiler_emit(compiler,0x50))return 0; + compiler->StackBytes+=8; + if(!compiler_term(compiler))return 0; + right_type=compiler->ExpressionType; + if(compiler_is_pointer(left_type)&&compiler_is_pointer(right_type)) { + if(left_type!=right_type)return 0; + if(operation!='-'||!compiler_emit(compiler,0x59)|| + !compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x29)|| + !compiler_emit(compiler,0xc1)||!compiler_emit(compiler,0x48)|| + !compiler_emit(compiler,0x89)||!compiler_emit(compiler,0xc8))return 0; + u32 scale=compiler_pointer_scale(compiler,left_type); + if(scale==2||scale==4||scale==8) { + u8 shift=scale==2?1:(scale==4?2:3); + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0xc1)|| + !compiler_emit(compiler,0xf8)||!compiler_emit(compiler,shift))return 0; + } else if(scale!=1&& + (!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x99)|| + !compiler_emit(compiler,0x48)||!compiler_emit(compiler,0xb9)|| + !compiler_emit_u64(compiler,scale)||!compiler_emit(compiler,0x48)|| + !compiler_emit(compiler,0xf7)||!compiler_emit(compiler,0xf9)))return 0; + compiler->StackBytes-=8; + compiler->ExpressionType=COMPILER_TYPE_LONG_LONG; + continue; + } + if(compiler_is_pointer(left_type)) { + if(!compiler_emit_scale_register(compiler, + compiler_pointer_scale(compiler,left_type),0))return 0; + } else if(compiler_is_pointer(right_type)) { + if(operation!='+'||!compiler_emit(compiler,0x59)|| + !compiler_emit_scale_register(compiler, + compiler_pointer_scale(compiler,right_type),1)|| + !compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x01)|| + !compiler_emit(compiler,0xc8))return 0; + compiler->StackBytes-=8; + compiler->ExpressionType=right_type; + continue; + } + if(!compiler_emit(compiler,0x59))return 0; + compiler->StackBytes-=8; + if(operation=='+') { + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x01)|| + !compiler_emit(compiler,0xc8))return 0; + } else if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x29)|| + !compiler_emit(compiler,0xc1)||!compiler_emit(compiler,0x48)|| + !compiler_emit(compiler,0x89)||!compiler_emit(compiler,0xc8))return 0; + compiler->ExpressionType=compiler_is_pointer(left_type)?left_type: + (left_type==COMPILER_TYPE_USIZE||right_type==COMPILER_TYPE_USIZE? + COMPILER_TYPE_USIZE: + (left_type==COMPILER_TYPE_LONG_LONG||right_type==COMPILER_TYPE_LONG_LONG? + COMPILER_TYPE_LONG_LONG:COMPILER_TYPE_INT)); + } +} + +static int compiler_comparison(BOB64_C_COMPILER *compiler) { + typedef struct { char First,Second;u8 Length,SetCondition; } COMPILER_COMPARISON; + static const COMPILER_COMPARISON operations[]={ + {'=', '=',2,0x94},{'!', '=',2,0x95}, + {'<', '=',2,0x9e},{'>', '=',2,0x9d}, + {'<', 0,1,0x9c},{'>', 0,1,0x9f} + }; + if(!compiler_additive(compiler))return 0; + for(;;) { + compiler_skip(compiler); + if(compiler->Position>=compiler->Length)return 1; + int operation=-1; + for(u32 i=0;iSource[compiler->Position]!=candidate->First)continue; + if(candidate->Length==2) { + if(compiler->Position+1>=compiler->Length|| + compiler->Source[compiler->Position+1]!=candidate->Second)continue; + } else if(compiler->Position+1Length&& + compiler->Source[compiler->Position+1]=='=')continue; + operation=(int)i;break; + } + if(operation<0)return 1; + u8 left_type=compiler->ExpressionType; + compiler->Position+=operations[operation].Length; + if(!compiler_emit(compiler,0x50))return 0; + compiler->StackBytes+=8; + if(!compiler_additive(compiler))return 0; + u8 right_type=compiler->ExpressionType; + int pointer_comparison=compiler_is_pointer(left_type)|| + compiler_is_pointer(right_type); + if(pointer_comparison&& + (left_type!=right_type||!compiler_is_pointer(left_type)|| + operation>1))return 0; + u8 condition=operations[operation].SetCondition; + if(left_type==COMPILER_TYPE_USIZE||right_type==COMPILER_TYPE_USIZE) { + static const u8 unsigned_conditions[6]={0x94,0x95,0x96,0x93,0x92,0x97}; + condition=unsigned_conditions[operation]; + } + if(!compiler_emit(compiler,0x59)||!compiler_emit(compiler,0x48)|| + !compiler_emit(compiler,0x39)||!compiler_emit(compiler,0xc1)|| + !compiler_emit(compiler,0x0f)|| + !compiler_emit(compiler,condition)|| + !compiler_emit(compiler,0xc0)||!compiler_emit(compiler,0x0f)|| + !compiler_emit(compiler,0xb6)||!compiler_emit(compiler,0xc0))return 0; + compiler->StackBytes-=8; + compiler->ExpressionType=COMPILER_TYPE_INT; + } +} + +static int compiler_logical_and(BOB64_C_COMPILER *compiler) { + if(!compiler_comparison(compiler))return 0; + for(;;) { + u16 false_branch,end_branch; + compiler_skip(compiler); + if(compiler->Position+1>=compiler->Length|| + compiler->Source[compiler->Position]!='&'|| + compiler->Source[compiler->Position+1]!='&')return 1; + compiler->Position+=2; + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x85)|| + !compiler_emit(compiler,0xc0)||!compiler_emit(compiler,0x0f)|| + !compiler_emit_branch(compiler,0x84,&false_branch)|| + !compiler_comparison(compiler)|| + !compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x85)|| + !compiler_emit(compiler,0xc0)||!compiler_emit(compiler,0x0f)|| + !compiler_emit(compiler,0x95)||!compiler_emit(compiler,0xc0)|| + !compiler_emit(compiler,0x0f)||!compiler_emit(compiler,0xb6)|| + !compiler_emit(compiler,0xc0)|| + !compiler_emit_branch(compiler,0xe9,&end_branch)|| + !compiler_patch_branch(compiler,false_branch,compiler->CodePosition)|| + !compiler_emit(compiler,0x31)||!compiler_emit(compiler,0xc0)|| + !compiler_patch_branch(compiler,end_branch,compiler->CodePosition))return 0; + compiler->ExpressionType=COMPILER_TYPE_INT; + } +} + +static int compiler_expression(BOB64_C_COMPILER *compiler) { + if(!compiler_logical_and(compiler))return 0; + for(;;) { + u16 true_branch,end_branch; + compiler_skip(compiler); + if(compiler->Position+1>=compiler->Length|| + compiler->Source[compiler->Position]!='|'|| + compiler->Source[compiler->Position+1]!='|')return 1; + compiler->Position+=2; + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x85)|| + !compiler_emit(compiler,0xc0)||!compiler_emit(compiler,0x0f)|| + !compiler_emit_branch(compiler,0x85,&true_branch)|| + !compiler_logical_and(compiler)|| + !compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x85)|| + !compiler_emit(compiler,0xc0)||!compiler_emit(compiler,0x0f)|| + !compiler_emit(compiler,0x95)||!compiler_emit(compiler,0xc0)|| + !compiler_emit(compiler,0x0f)||!compiler_emit(compiler,0xb6)|| + !compiler_emit(compiler,0xc0)|| + !compiler_emit_branch(compiler,0xe9,&end_branch)|| + !compiler_patch_branch(compiler,true_branch,compiler->CodePosition)|| + !compiler_emit(compiler,0xb8)||!compiler_emit_u32(compiler,1)|| + !compiler_patch_branch(compiler,end_branch,compiler->CodePosition))return 0; + compiler->ExpressionType=COMPILER_TYPE_INT; + } +} + +static int compiler_array_element_address(BOB64_C_COMPILER *compiler, + u32 variable,u32 element) { + u32 type=compiler->VariableType[variable]; + u32 scale=compiler_array_element_size((u8)type); + s16 displacement=(s16)(compiler->VariableDisplacement[variable]+(s16)(element*scale)); + if(element>=compiler->VariableArrayLength[variable]|| + displacement< -128||displacement>127)return 0; + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x8d)&& + compiler_emit(compiler,0x45)&&compiler_emit(compiler,(u8)(s8)displacement); +} + +static int compiler_array_initializer(BOB64_C_COMPILER *compiler,u32 variable) { + u32 element=0; + if(compiler->VariableType[variable]==COMPILER_TYPE_CHAR_ARRAY) { + usize offset,length; + if(compiler_string(compiler,&offset,&length)) { + u32 array_length=compiler_variable_array_length(compiler,variable); + if(length>array_length)return 0; + for(u32 i=0;iData[offset+i]:0; + if(!compiler_array_element_address(compiler,variable,i)|| + !compiler_emit(compiler,0xc6)||!compiler_emit(compiler,0x45)|| + !compiler_emit(compiler,(u8)(s8)(compiler->VariableDisplacement[variable]+(s16)i))|| + !compiler_emit(compiler,value))return 0; + } + return compiler_take(compiler,';'); + } + } + if(!compiler_take(compiler,'{'))return 0; + for(;;) { + if(compiler_take(compiler,'}'))break; + if(element>=compiler_variable_array_length(compiler,variable)|| + !compiler_array_element_address(compiler,variable,element)|| + !compiler_emit(compiler,0x50))return 0; + compiler->StackBytes+=8; + if(!compiler_expression(compiler)|| + compiler_is_pointer(compiler->ExpressionType)|| + !compiler_emit(compiler,0x59))return 0; + if(compiler->VariableType[variable]==COMPILER_TYPE_CHAR_ARRAY) { + if(!compiler_emit(compiler,0x88)||!compiler_emit(compiler,0x01))return 0; + } else if(compiler->VariableType[variable]==COMPILER_TYPE_SHORT_ARRAY) { + if(!compiler_emit(compiler,0x66)||!compiler_emit(compiler,0x89)|| + !compiler_emit(compiler,0x01))return 0; + } else if(compiler->VariableType[variable]==COMPILER_TYPE_LONG_LONG_ARRAY|| + compiler->VariableType[variable]==COMPILER_TYPE_USIZE_ARRAY) { + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x89)|| + !compiler_emit(compiler,0x01))return 0; + } else if(!compiler_emit(compiler,0x89)||!compiler_emit(compiler,0x01))return 0; + compiler->StackBytes-=8; + element++; + if(compiler_take(compiler,'}'))break; + if(!compiler_take(compiler,','))return 0; + } + while(elementStackBytes+=8; + if(!compiler_emit(compiler,0x31)|| + !compiler_emit(compiler,0xc0)||!compiler_emit(compiler,0x59))return 0; + if(compiler->VariableType[variable]==COMPILER_TYPE_CHAR_ARRAY) { + if(!compiler_emit(compiler,0x88)||!compiler_emit(compiler,0x01))return 0; + } else if(compiler->VariableType[variable]==COMPILER_TYPE_SHORT_ARRAY) { + if(!compiler_emit(compiler,0x66)||!compiler_emit(compiler,0x89)|| + !compiler_emit(compiler,0x01))return 0; + } else if(compiler->VariableType[variable]==COMPILER_TYPE_LONG_LONG_ARRAY|| + compiler->VariableType[variable]==COMPILER_TYPE_USIZE_ARRAY) { + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x89)|| + !compiler_emit(compiler,0x01))return 0; + } else if(!compiler_emit(compiler,0x89)||!compiler_emit(compiler,0x01))return 0; + compiler->StackBytes-=8; + } + return compiler_take(compiler,';'); +} + +/* Return 1 for a consumed local declaration/assignment, 0 for another statement. */ +static int compiler_local_statement(BOB64_C_COMPILER *compiler) { + usize saved=compiler->Position; + char name[32]; + u8 long_type=0; + int is_char=0,is_short=0,is_pointer=0,is_struct=0,is_struct_pointer=0,variable; + u8 declared_type=0; + if(compiler_word(compiler,"struct")) { + char struct_name[32]; + if(!compiler_identifier(compiler,struct_name,sizeof(struct_name)))return -1; + int structure=compiler_struct_find(compiler,struct_name); + if(structure<0)return -1; + declared_type=(u8)(COMPILER_TYPE_STRUCT_BASE+(u32)structure); + is_struct=1; + } else if(compiler_word(compiler,"char"))is_char=1; + else if((long_type=compiler_integer_type(compiler))!=0) { + is_short=long_type==COMPILER_TYPE_SHORT; + } else { + compiler->Position=saved; + if(compiler_take(compiler,'*')) { + if(!compiler_identifier(compiler,name,sizeof(name))) { + compiler->Position=saved;return 0; + } + variable=compiler_variable_find(compiler,name); + if(variable<0||!compiler_is_pointer(compiler_variable_type(compiler,(u32)variable))|| + !compiler_take(compiler,'=')) { + compiler->Position=saved;return 0; + } + if(!compiler_variable_load(compiler,(u32)variable)|| + !compiler_emit(compiler,0x50))return -1; + compiler->StackBytes+=8; + if(!compiler_expression(compiler)|| + compiler_is_pointer(compiler->ExpressionType)|| + !compiler_take(compiler,';')||!compiler_emit(compiler,0x59)|| + (compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_CHAR_POINTER? + (!compiler_emit(compiler,0x88)||!compiler_emit(compiler,0x01)): + (compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_SHORT_POINTER? + (!compiler_emit(compiler,0x66)||!compiler_emit(compiler,0x89)|| + !compiler_emit(compiler,0x01)): + ((compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_USIZE_POINTER|| + compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_ISIZE_POINTER)? + (!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x89)|| + !compiler_emit(compiler,0x01)): + (!compiler_emit(compiler,0x89)||!compiler_emit(compiler,0x01))))))return -1; + compiler->StackBytes-=8; + return 1; + } + if(!compiler_identifier(compiler,name,sizeof(name))) { + compiler->Position=saved;return 0; + } + variable=compiler_variable_find(compiler,name); + if(variable<0) { + compiler->Position=saved;return 0; + } + u8 variable_type=compiler_variable_type(compiler,(u32)variable); + int pointer_member=compiler_type_is_struct_pointer(variable_type); + if(compiler_type_is_struct(variable_type)||pointer_member) { + char field_name[32]; + if((pointer_member?(!compiler_take(compiler,'-')||!compiler_take(compiler,'>')): + !compiler_take(compiler,'.'))|| + !compiler_identifier(compiler,field_name,sizeof(field_name)))return -1; + u8 struct_type=pointer_member? + (u8)(COMPILER_TYPE_STRUCT_BASE+variable_type-COMPILER_TYPE_STRUCT_POINTER_BASE): + variable_type; + int field_index=compiler_field_find(compiler,struct_type,field_name); + if(field_index<0)return -1; + BOB64_C_FIELD *field=&compiler->Structs[ + struct_type-COMPILER_TYPE_STRUCT_BASE].Fields[field_index]; + int address_ok=pointer_member? + (compiler_variable_load(compiler,(u32)variable)&& + (!field->Offset||(compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x05)&& + compiler_emit_u32(compiler,field->Offset)))): + compiler_member_address(compiler,(u32)variable,field); + if(!compiler_take(compiler,'=')||!address_ok|| + !compiler_emit(compiler,0x50))return -1; + compiler->StackBytes+=8; + if(!compiler_expression(compiler)|| + (compiler_is_pointer(field->Type)!=compiler_is_pointer(compiler->ExpressionType))|| + (compiler_is_pointer(field->Type)&&field->Type!=compiler->ExpressionType)|| + !compiler_take(compiler,';')||!compiler_emit(compiler,0x59)|| + !compiler_member_store(compiler,field->Type))return -1; + compiler->StackBytes-=8; + return 1; + } + if(compiler_take(compiler,'[')) { + if((!compiler_type_is_array(compiler_variable_type(compiler,(u32)variable))&& + !compiler_is_pointer(compiler_variable_type(compiler,(u32)variable)))|| + !compiler_index_address(compiler,(u32)variable)|| + !compiler_take(compiler,'=')||!compiler_emit(compiler,0x50))return -1; + compiler->StackBytes+=8; + if(!compiler_expression(compiler)|| + compiler_is_pointer(compiler->ExpressionType)|| + !compiler_take(compiler,';')||!compiler_emit(compiler,0x59))return -1; + if(compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_CHAR_POINTER|| + compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_CHAR_ARRAY) { + if(!compiler_emit(compiler,0x88)||!compiler_emit(compiler,0x01))return -1; + } else if(compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_SHORT_POINTER|| + compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_SHORT_ARRAY) { + if(!compiler_emit(compiler,0x66)||!compiler_emit(compiler,0x89)|| + !compiler_emit(compiler,0x01))return -1; + } else if(compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_USIZE_POINTER|| + compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_ISIZE_POINTER|| + compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_USIZE_ARRAY|| + compiler_variable_type(compiler,(u32)variable)==COMPILER_TYPE_LONG_LONG_ARRAY) { + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x89)|| + !compiler_emit(compiler,0x01))return -1; + } else if(!compiler_emit(compiler,0x89)||!compiler_emit(compiler,0x01))return -1; + compiler->StackBytes-=8; + return 1; + } + if(compiler_type_is_array(compiler_variable_type(compiler,(u32)variable))|| + !compiler_take(compiler,'=')) { + compiler->Position=saved;return 0; + } + if(!compiler_expression(compiler)|| + (compiler_is_pointer(compiler_variable_type(compiler,(u32)variable))!= + compiler_is_pointer(compiler->ExpressionType)|| + (compiler_is_pointer(compiler_variable_type(compiler,(u32)variable))&& + compiler_variable_type(compiler,(u32)variable)!=compiler->ExpressionType))|| + !compiler_take(compiler,';')|| + !compiler_variable_store(compiler,(u32)variable))return -1; + return 1; + } + is_pointer=compiler_take(compiler,'*'); + if(is_struct&&is_pointer) { + declared_type=(u8)(COMPILER_TYPE_STRUCT_POINTER_BASE+ + declared_type-COMPILER_TYPE_STRUCT_BASE); + is_struct=0;is_struct_pointer=1; + } + if(!compiler_identifier(compiler,name,sizeof(name)))return -1; + if(is_struct) { + if(!compiler_take(compiler,';')|| + !compiler_add_variable(compiler,name,declared_type,0,0))return -1; + return 1; + } + if(compiler_take(compiler,'[')) { + u64 array_length; + u8 array_type=long_type==COMPILER_TYPE_USIZE?COMPILER_TYPE_USIZE_ARRAY: + (long_type==COMPILER_TYPE_LONG_LONG?COMPILER_TYPE_LONG_LONG_ARRAY: + (is_char?COMPILER_TYPE_CHAR_ARRAY: + (is_short?COMPILER_TYPE_SHORT_ARRAY:COMPILER_TYPE_INT_ARRAY))); + u32 array_limit=(array_type==COMPILER_TYPE_LONG_LONG_ARRAY|| + array_type==COMPILER_TYPE_USIZE_ARRAY)?16u: + (is_char?128u:(is_short?64u:32u)); + if(is_pointer||!compiler_integer(compiler,&array_length)|| + array_length>array_limit||!compiler_take(compiler,']')|| + !compiler_add_variable(compiler,name,array_type, + (u32)array_length,0))return -1; + variable=compiler_variable_find(compiler,name); + if(compiler_take(compiler,';'))return 1; + if(!compiler_take(compiler,'=')|| + !compiler_array_initializer(compiler,(u32)variable))return -1; + return 1; + } + if(!compiler_take(compiler,'='))return -1; + u8 type=is_struct_pointer?declared_type: + (is_pointer?compiler_pointer_type(is_char?COMPILER_TYPE_CHAR:long_type): + (is_char?COMPILER_TYPE_CHAR:long_type)); + if(!compiler_add_variable(compiler,name,type,0,0))return -1; + variable=compiler_variable_find(compiler,name); + if(!compiler_expression(compiler)|| + (compiler_is_pointer(type)!=compiler_is_pointer(compiler->ExpressionType)|| + (compiler_is_pointer(type)&&type!=compiler->ExpressionType))|| + !compiler_take(compiler,';')|| + !compiler_variable_store(compiler,(u32)variable))return -1; + return 1; +} + +static int compiler_emit_write(BOB64_C_COMPILER *compiler,usize data_offset, + usize data_length) { + s64 displacement=(s64)(BOB64_PAGE_SIZE+data_offset)- + (s64)(compiler->CodePosition+7); + if(displacement<(-2147483647LL-1)||displacement>2147483647)return 0; + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x8d)&& + compiler_emit(compiler,0x0d)&&compiler_emit_u32(compiler,(u32)(s32)displacement)&& + compiler_emit(compiler,0xba)&&compiler_emit_u32(compiler,(u32)data_length)&& + compiler_emit(compiler,0xb8)&&compiler_emit_u32(compiler,BOB64_SYSCALL_WRITE_BUFFER)&& + compiler_emit(compiler,0xcd)&&compiler_emit(compiler,0x80); +} + +static int compiler_function_prologue(BOB64_C_COMPILER *compiler) { + return compiler_emit(compiler,0x55)&&compiler_emit(compiler,0x48)&& + compiler_emit(compiler,0x89)&&compiler_emit(compiler,0xe5)&& + compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x81)&& + compiler_emit(compiler,0xec)&&compiler_emit_u32(compiler,128); +} + +static int compiler_function_epilogue(BOB64_C_COMPILER *compiler) { + if(compiler->ReturnType==COMPILER_TYPE_CHAR) { + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x0f)|| + !compiler_emit(compiler,0xbe)||!compiler_emit(compiler,0xc0))return 0; + } else if(compiler->ReturnType==COMPILER_TYPE_SHORT) { + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x0f)|| + !compiler_emit(compiler,0xbf)||!compiler_emit(compiler,0xc0))return 0; + } else if(compiler->ReturnType!=COMPILER_TYPE_VOID&&!compiler->Return64&& + (!compiler_emit(compiler,0x48)|| + !compiler_emit(compiler,0x63)||!compiler_emit(compiler,0xc0)))return 0; + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x89)&& + compiler_emit(compiler,0xec)&&compiler_emit(compiler,0x5d)&& + compiler_emit(compiler,0xc3); +} + +static int compiler_return_type_matches(BOB64_C_COMPILER *compiler) { + if(compiler->ReturnType==COMPILER_TYPE_VOID|| + compiler->ExpressionType==COMPILER_TYPE_VOID)return 0; + int result_pointer=compiler_is_pointer(compiler->ReturnType); + int expression_pointer=compiler_is_pointer(compiler->ExpressionType); + if(result_pointer)return expression_pointer&& + compiler->ReturnType==compiler->ExpressionType; + return !expression_pointer||compiler->Return64; +} + +static int compiler_statement(BOB64_C_COMPILER *compiler); + +static int compiler_emit_branch(BOB64_C_COMPILER *compiler,u8 opcode, + u16 *displacement_offset) { + if(!compiler_emit(compiler,opcode))return 0; + *displacement_offset=(u16)compiler->CodePosition; + return compiler_emit_u32(compiler,0); +} + +static int compiler_patch_branch(BOB64_C_COMPILER *compiler,u16 displacement_offset, + usize target) { + s64 displacement=(s64)target-(s64)(displacement_offset+4u); + if(displacement<(-2147483647LL-1)||displacement>2147483647|| + displacement_offset+4u>compiler->CodePosition)return 0; + u32 encoded=(u32)(s32)displacement; + for(u32 byte=0;byte<4;byte++) + compiler->Code[displacement_offset+byte]=(u8)(encoded>>(byte*8)); + return 1; +} + +static int compiler_loop_push(BOB64_C_COMPILER *compiler,usize continue_target) { + if(compiler->LoopDepth>=sizeof(compiler->Loops)/sizeof(compiler->Loops[0])|| + continue_target>0xffffu)return 0; + BOB64_C_LOOP *loop=&compiler->Loops[compiler->LoopDepth++]; + loop->ContinueTarget=(u16)continue_target; + loop->BreakCount=0;loop->ContinueCount=0; + return 1; +} + +static int compiler_loop_finish(BOB64_C_COMPILER *compiler,usize break_target) { + if(!compiler->LoopDepth)return 0; + BOB64_C_LOOP *loop=&compiler->Loops[--compiler->LoopDepth]; + for(u32 i=0;iBreakCount;i++) + if(!compiler_patch_branch(compiler,loop->BreakBranches[i],break_target))return 0; + for(u32 i=0;iContinueCount;i++) + if(!compiler_patch_branch(compiler,loop->ContinueBranches[i],loop->ContinueTarget))return 0; + return 1; +} + +static int compiler_statement(BOB64_C_COMPILER *compiler) { + usize saved=compiler->Position; + if(compiler_word(compiler,"return")) { + if(compiler->ReturnType==COMPILER_TYPE_VOID) { + if(compiler->StackBytes||!compiler_take(compiler,';')|| + !compiler_function_epilogue(compiler))return -1; + return 1; + } + if(compiler->StackBytes||!compiler_expression(compiler)|| + !compiler_return_type_matches(compiler)|| + !compiler_take(compiler,';')||!compiler_function_epilogue(compiler))return -1; + return 1; + } + compiler->Position=saved; + if(compiler_word(compiler,"break")) { + if(!compiler->LoopDepth||!compiler_take(compiler,';'))return -1; + BOB64_C_LOOP *loop=&compiler->Loops[compiler->LoopDepth-1]; + if(loop->BreakCount>=sizeof(loop->BreakBranches)/sizeof(loop->BreakBranches[0])|| + !compiler_emit_branch(compiler,0xe9,&loop->BreakBranches[loop->BreakCount]))return -1; + loop->BreakCount++; + return 1; + } + compiler->Position=saved; + if(compiler_word(compiler,"continue")) { + if(!compiler->LoopDepth||!compiler_take(compiler,';'))return -1; + BOB64_C_LOOP *loop=&compiler->Loops[compiler->LoopDepth-1]; + if(loop->ContinueCount>=sizeof(loop->ContinueBranches)/sizeof(loop->ContinueBranches[0])|| + !compiler_emit_branch(compiler,0xe9, + &loop->ContinueBranches[loop->ContinueCount]))return -1; + loop->ContinueCount++; + return 1; + } + compiler->Position=saved; + if(compiler_word(compiler,"if")) { + u16 false_branch,end_branch; + if(compiler->ControlDepth>=32||!compiler_take(compiler,'(')|| + !compiler_expression(compiler)||!compiler_take(compiler,')')|| + !compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x85)|| + !compiler_emit(compiler,0xc0)||!compiler_emit(compiler,0x0f)|| + !compiler_emit_branch(compiler,0x84,&false_branch))return -1; + compiler->ControlDepth++; + if(compiler_statement(compiler)<=0)return -1; + compiler->ControlDepth--; + if(compiler_word(compiler,"else")) { + if(!compiler_emit_branch(compiler,0xe9,&end_branch)|| + !compiler_patch_branch(compiler,false_branch,compiler->CodePosition))return -1; + compiler->ControlDepth++; + if(compiler_statement(compiler)<=0)return -1; + compiler->ControlDepth--; + if(!compiler_patch_branch(compiler,end_branch,compiler->CodePosition))return -1; + } else if(!compiler_patch_branch(compiler,false_branch,compiler->CodePosition))return -1; + return 1; + } + compiler->Position=saved; + if(compiler_word(compiler,"for")) { + u16 loop_exit,body_branch,loop_back; + usize loop_start,post_start,body_start; + if(compiler->ControlDepth>=32||!compiler_take(compiler,'(')|| + !compiler_scope_push(compiler))return -1; + if(!compiler_take(compiler,';')) { + int init=compiler_local_statement(compiler); + if(init<=0)return -1; + } + loop_start=compiler->CodePosition; + if(compiler_take(compiler,';')) { + if(!compiler_emit_integer(compiler,1))return -1; + } else if(!compiler_expression(compiler)||!compiler_take(compiler,';'))return -1; + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x85)|| + !compiler_emit(compiler,0xc0)||!compiler_emit(compiler,0x0f)|| + !compiler_emit_branch(compiler,0x84,&loop_exit)|| + !compiler_emit_branch(compiler,0xe9,&body_branch))return -1; + post_start=compiler->CodePosition; + if(!compiler_take(compiler,')')&& + (!compiler_for_post(compiler)||!compiler_take(compiler,')')))return -1; + if(!compiler_emit_branch(compiler,0xe9,&loop_back)|| + !compiler_patch_branch(compiler,loop_back,loop_start))return -1; + body_start=compiler->CodePosition; + if(!compiler_patch_branch(compiler,body_branch,body_start))return -1; + if(!compiler_loop_push(compiler,post_start))return -1; + compiler->ControlDepth++; + if(compiler_statement(compiler)<=0)return -1; + compiler->ControlDepth--; + u16 body_back; + if(!compiler_emit_branch(compiler,0xe9,&body_back)|| + !compiler_patch_branch(compiler,body_back,post_start)|| + !compiler_patch_branch(compiler,loop_exit,compiler->CodePosition)|| + !compiler_loop_finish(compiler,compiler->CodePosition))return -1; + compiler_scope_pop(compiler); + return 1; + } + compiler->Position=saved; + if(compiler_word(compiler,"while")) { + usize loop_start=compiler->CodePosition; + u16 loop_exit,loop_back; + if(compiler->ControlDepth>=32||!compiler_take(compiler,'(')|| + !compiler_expression(compiler)||!compiler_take(compiler,')')|| + !compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x85)|| + !compiler_emit(compiler,0xc0)||!compiler_emit(compiler,0x0f)|| + !compiler_emit_branch(compiler,0x84,&loop_exit))return -1; + if(!compiler_loop_push(compiler,loop_start))return -1; + compiler->ControlDepth++; + if(compiler_statement(compiler)<=0)return -1; + compiler->ControlDepth--; + if(!compiler_emit_branch(compiler,0xe9,&loop_back)|| + !compiler_patch_branch(compiler,loop_back,loop_start)|| + !compiler_patch_branch(compiler,loop_exit,compiler->CodePosition)|| + !compiler_loop_finish(compiler,compiler->CodePosition))return -1; + return 1; + } + compiler->Position=saved; + if(compiler_take(compiler,'{')) { + if(compiler->ControlDepth>=32||!compiler_scope_push(compiler))return -1; + compiler->ControlDepth++; + for(;;) { + if(compiler_take(compiler,'}'))break; + if(compiler_statement(compiler)<=0)return -1; + } + compiler->ControlDepth--; + compiler_scope_pop(compiler); + return 1; + } + compiler->Position=saved; + char call_name[32]; + if(compiler_identifier(compiler,call_name,sizeof(call_name))) { + compiler_skip(compiler); + if(compiler_function_find(compiler,call_name)>=0&& + compiler_variable_find(compiler,call_name)<0&& + compiler->PositionLength&& + compiler->Source[compiler->Position]=='(') { + compiler->Position=saved; + if(!compiler_identifier(compiler,call_name,sizeof(call_name))|| + !compiler_emit_call(compiler,call_name)|| + !compiler_take(compiler,';'))return -1; + return 1; + } + } + compiler->Position=saved; + if(compiler_word(compiler,"bob64_app_write")) { + usize string_offset,string_length; + if(!compiler_take(compiler,'(')|| + !compiler_string(compiler,&string_offset,&string_length)|| + !compiler_take(compiler,',')||!compiler_integer(compiler,&compiler->IntegerValue)|| + compiler->IntegerValue!=string_length|| + !compiler_take(compiler,')')||!compiler_take(compiler,';')|| + !compiler_emit_write(compiler,string_offset,string_length))return -1; + return 1; + } + compiler->Position=saved; + if(compiler_take(compiler,';'))return 1; + return compiler_local_statement(compiler); +} + +static int compiler_for_post(BOB64_C_COMPILER *compiler) { + char name[32]; + if(!compiler_identifier(compiler,name,sizeof(name)))return 0; + int variable=compiler_variable_find(compiler,name); + if(variable<0||compiler_type_is_array(compiler_variable_type(compiler,(u32)variable))|| + !compiler_take(compiler,'=')||!compiler_expression(compiler)|| + (compiler_is_pointer(compiler_variable_type(compiler,(u32)variable))!= + compiler_is_pointer(compiler->ExpressionType)|| + (compiler_is_pointer(compiler_variable_type(compiler,(u32)variable))&& + compiler_variable_type(compiler,(u32)variable)!=compiler->ExpressionType))|| + !compiler_variable_store(compiler,(u32)variable))return 0; + return 1; +} + +static int compiler_function_body(BOB64_C_COMPILER *compiler) { + for(;;) { + usize saved=compiler->Position; + if(compiler_word(compiler,"return")) { + compiler->Position=saved; + break; + } + compiler->Position=saved; + int statement=compiler_statement(compiler); + if(statement<0)return 0; + if(statement>0)continue; + break; + } + if(compiler->ReturnType==COMPILER_TYPE_VOID) { + if(compiler->StackBytes)return 0; + if(compiler_word(compiler,"return")) { + if(!compiler_take(compiler,';')||!compiler_take(compiler,'}'))return 0; + } else if(!compiler_take(compiler,'}'))return 0; + return compiler_function_epilogue(compiler); + } + if(compiler->StackBytes||!compiler_word(compiler,"return")|| + !compiler_expression(compiler)|| + !compiler_return_type_matches(compiler)|| + !compiler_take(compiler,';')||!compiler_take(compiler,'}')|| + !compiler_function_epilogue(compiler))return 0; + return 1; +} + +static int compiler_store_parameter(BOB64_C_COMPILER *compiler,u32 variable, + u32 argument) { + s8 displacement=(s8)compiler->VariableDisplacement[variable]; + u8 type=compiler->VariableType[variable]; + if(argument>=4) { + u32 incoming=16u+argument*8u; + u8 load_modrm=incoming<=127u?0x45:0x85; + if(type==COMPILER_TYPE_SHORT) + return compiler_emit(compiler,0x0f)&&compiler_emit(compiler,0xbf)&& + compiler_emit(compiler,load_modrm)&& + (incoming<=127u?compiler_emit(compiler,(u8)incoming): + compiler_emit_u32(compiler,incoming))&& + compiler_emit(compiler,0x66)&&compiler_emit(compiler,0x89)&& + compiler_emit(compiler,0x45)&&compiler_emit(compiler,(u8)displacement); + if(type==COMPILER_TYPE_CHAR) + return compiler_emit(compiler,0x0f)&&compiler_emit(compiler,0xbe)&& + compiler_emit(compiler,load_modrm)&& + (incoming<=127u?compiler_emit(compiler,(u8)incoming): + compiler_emit_u32(compiler,incoming))&& + compiler_emit(compiler,0x88)&&compiler_emit(compiler,0x45)&& + compiler_emit(compiler,(u8)displacement); + if(compiler_is_pointer(type)||type==COMPILER_TYPE_USIZE|| + type==COMPILER_TYPE_LONG_LONG) { + if(!compiler_emit(compiler,0x48)||!compiler_emit(compiler,0x8b)|| + !compiler_emit(compiler,load_modrm)|| + !(incoming<=127u?compiler_emit(compiler,(u8)incoming): + compiler_emit_u32(compiler,incoming)))return 0; + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x89)&& + compiler_emit(compiler,0x45)&&compiler_emit(compiler,(u8)displacement); + } + if(!compiler_emit(compiler,0x8b)||!compiler_emit(compiler,load_modrm)|| + !(incoming<=127u?compiler_emit(compiler,(u8)incoming): + compiler_emit_u32(compiler,incoming)))return 0; + return compiler_emit(compiler,0x89)&&compiler_emit(compiler,0x45)&& + compiler_emit(compiler,(u8)displacement); + } + if(compiler_is_pointer(type)||type==COMPILER_TYPE_USIZE|| + type==COMPILER_TYPE_LONG_LONG) { + if(argument<2) { + u8 modrm=argument==0?0x4d:0x55; + return compiler_emit(compiler,0x48)&&compiler_emit(compiler,0x89)&& + compiler_emit(compiler,modrm)&&compiler_emit(compiler,(u8)displacement); + } + return compiler_emit(compiler,0x4c)&&compiler_emit(compiler,0x89)&& + compiler_emit(compiler,(u8)(argument==2?0x45:0x4d))&& + compiler_emit(compiler,(u8)displacement); + } + if(type==COMPILER_TYPE_CHAR) { + if(argument==0)return compiler_emit(compiler,0x88)&&compiler_emit(compiler,0x4d)&& + compiler_emit(compiler,(u8)displacement); + if(argument==1)return compiler_emit(compiler,0x88)&&compiler_emit(compiler,0x55)&& + compiler_emit(compiler,(u8)displacement); + return compiler_emit(compiler,0x41)&&compiler_emit(compiler,0x88)&& + compiler_emit(compiler,(u8)(argument==2?0x45:0x4d))&& + compiler_emit(compiler,(u8)displacement); + } + if(type==COMPILER_TYPE_SHORT) { + static const u8 short_stores[4][4]={ + {0x66,0x89,0x4d,0},{0x66,0x89,0x55,0}, + {0x66,0x44,0x89,0x45},{0x66,0x44,0x89,0x4d} + }; + u32 instruction_bytes=argument<2?3u:4u; + for(u32 byte=0;byteCodePosition, + return_type,(u8)argument_count,argument_types,1))return 0; + compiler->VariableCount=0;compiler->LocalBytes=0;compiler->ScopeDepth=0; + compiler->ReturnType=return_type; + compiler->Return64=return_type==COMPILER_TYPE_LONG_LONG|| + return_type==COMPILER_TYPE_USIZE|| + compiler_is_pointer(return_type); + compiler->StackBytes=0;compiler->ControlDepth=0; + if(!compiler_function_prologue(compiler)|| + (is_main&&!compiler_emit_global_initializers(compiler)))return 0; + for(u32 i=0;iCallCount;i++) { + BOB64_C_CALL *call=&compiler->Calls[i]; + int function=compiler_function_find(compiler,call->Name); + if(function<0||!compiler->Functions[function].Defined|| + compiler->Functions[function].ArgumentCount!=call->ArgumentCount) + return 0; + for(u32 argument=0;argumentArgumentCount;argument++) { + u8 expected=compiler->Functions[function].ArgumentTypes[argument]; + u8 actual=call->ArgumentTypes[argument]; + if(compiler_is_pointer(expected)!=compiler_is_pointer(actual)|| + (compiler_is_pointer(expected)&&expected!=actual))return 0; + } + s64 displacement=(s64)compiler->Functions[function].CodeOffset- + (s64)(call->DisplacementOffset+4u); + if(displacement<(-2147483647LL-1)||displacement>2147483647)return 0; + u32 encoded=(u32)(s32)displacement; + for(u32 byte=0;byte<4;byte++) + compiler->Code[call->DisplacementOffset+byte]=(u8)(encoded>>(byte*8)); + } + return 1; +} + +static u32 compiler_crc32(const u8 *bytes,usize length) { + u32 value=0xffffffffu; + for(usize i=0;i>1)^(0xedb88320u&-(value&1u)); + } + return ~value; +} + +static void compiler_write16(u8 *bytes,u16 value) { + bytes[0]=(u8)value;bytes[1]=(u8)(value>>8); +} + +static void compiler_write32(u8 *bytes,u32 value) { + for(u32 i=0;i<4;i++)bytes[i]=(u8)(value>>(i*8)); +} + +static void compiler_write64(u8 *bytes,u64 value) { + compiler_write32(bytes,(u32)value);compiler_write32(bytes+4,(u32)(value>>32)); +} + +static int compiler_scan_skip_quote(BOB64_C_COMPILER *compiler,usize *position) { + char quote=compiler->Source[(*position)++]; + while(*positionLength) { + char value=compiler->Source[(*position)++]; + if(value=='\\') { + if(*position>=compiler->Length)return 0; + (*position)++; + } else if(value==quote)return 1; + } + return 0; +} + +static int compiler_scan_skip_comment(BOB64_C_COMPILER *compiler,usize *position) { + if(*position+1>=compiler->Length||compiler->Source[*position]!='/')return 0; + if(compiler->Source[*position+1]=='/') { + *position+=2; + while(*positionLength&&compiler->Source[*position]!='\n')(*position)++; + return 1; + } + if(compiler->Source[*position+1]=='*') { + *position+=2; + while(*position+1Length&& + !(compiler->Source[*position]=='*'&&compiler->Source[*position+1]=='/')) + (*position)++; + if(*position+1>=compiler->Length)return -1; + *position+=2; + return 1; + } + return 0; +} + +static int compiler_global_add(BOB64_C_COMPILER *compiler,const char *name, + u8 type,u32 array_length,u32 bytes,u32 *global_index) { + usize name_length=0; + if(compiler->GlobalCount>=COMPILER_GLOBAL_LIMIT|| + compiler_variable_find(compiler,name)>=0||bytes>sizeof(compiler->Data)-compiler->DataLength) + return 0; + u32 alignment=compiler_type_is_struct(type)?compiler_type_alignment(compiler,type): + ((type==COMPILER_TYPE_LONG_LONG||type==COMPILER_TYPE_USIZE|| + type==COMPILER_TYPE_LONG_LONG_ARRAY||type==COMPILER_TYPE_USIZE_ARRAY|| + compiler_is_pointer(type))?8u: + (type==COMPILER_TYPE_INT||type==COMPILER_TYPE_INT_ARRAY?4u: + (type==COMPILER_TYPE_SHORT||type==COMPILER_TYPE_SHORT_ARRAY?2u:1u))); + compiler->DataLength=(compiler->DataLength+alignment-1u)&~(alignment-1u); + if(bytes>sizeof(compiler->Data)-compiler->DataLength)return 0; + u32 index=compiler->GlobalCount++; + BOB64_C_GLOBAL *global=&compiler->Globals[index]; + while(name[name_length]&&name_length+1Name)) { + global->Name[name_length]=name[name_length];name_length++; + } + if(name[name_length])return 0; + global->Name[name_length]=0; + global->Type=type; + global->ArrayLength=(u16)array_length; + global->InitKind=0;global->InitTarget=0; + global->DataOffset=(u16)compiler->DataLength; + for(u32 i=0;iData[compiler->DataLength+i]=0; + compiler->DataLength+=bytes; + if(global_index)*global_index=index; + return 1; +} + +static int compiler_struct_definition(BOB64_C_COMPILER *compiler,const char *name) { + usize name_length=0; + if(compiler->StructCount>=COMPILER_STRUCT_LIMIT|| + compiler_struct_find(compiler,name)>=0)return 0; + u32 index=compiler->StructCount++; + BOB64_C_STRUCT *structure=&compiler->Structs[index]; + while(name[name_length]&&name_length+1Name)) { + structure->Name[name_length]=name[name_length];name_length++; + } + if(name[name_length])return 0; + structure->Name[name_length]=0;structure->Size=0; + structure->Alignment=1;structure->FieldCount=0; + u32 offset=0; + for(;;) { + if(compiler_take(compiler,'}'))break; + int is_char=compiler_word(compiler,"char"),struct_index=-1; + u8 long_type=is_char?COMPILER_TYPE_CHAR:compiler_integer_type(compiler); + if(!long_type) { + if(compiler_word(compiler,"struct")) { + char field_struct_name[32]; + if(!compiler_identifier(compiler,field_struct_name, + sizeof(field_struct_name)))return 0; + struct_index=compiler_struct_find(compiler,field_struct_name); + if(struct_index<0)return 0; + } else return 0; + } + int pointer=compiler_take(compiler,'*'); + if(struct_index>=0&&!pointer)return 0; + char field_name[32]; + if(!compiler_identifier(compiler,field_name,sizeof(field_name))|| + !compiler_take(compiler,';')||structure->FieldCount>=COMPILER_FIELD_LIMIT|| + compiler_field_find(compiler,(u8)(COMPILER_TYPE_STRUCT_BASE+index),field_name)>=0) + return 0; + u8 field_type=struct_index>=0? + (u8)(COMPILER_TYPE_STRUCT_POINTER_BASE+(u32)struct_index): + (pointer?compiler_pointer_type(is_char?COMPILER_TYPE_CHAR:long_type): + long_type); + u32 alignment=compiler_type_alignment(compiler,field_type); + u32 size=compiler_type_size(compiler,field_type); + offset=(offset+alignment-1u)&~(alignment-1u); + BOB64_C_FIELD *field=&structure->Fields[structure->FieldCount++]; + usize field_length=0; + while(field_name[field_length]) { + field->Name[field_length]=field_name[field_length];field_length++; + } + field->Name[field_length]=0;field->Offset=(u16)offset;field->Type=field_type; + offset+=size; + if(alignment>structure->Alignment)structure->Alignment=(u8)alignment; + if(offset>2048)return 0; + } + if(!structure->FieldCount)return 0; + structure->Size=(u16)((offset+structure->Alignment-1u)&~(structure->Alignment-1u)); + return compiler_take(compiler,';'); +} + +static int compiler_global_declaration(BOB64_C_COMPILER *compiler) { + char name[32]; + u8 type; + u32 array_length=0,bytes,index; + int is_char=0,is_short=0,is_pointer=0,is_struct=0,is_struct_pointer=0; + u8 long_type=0; + if(compiler_word(compiler,"static")) { } + if(compiler_word(compiler,"struct")) { + char struct_name[32]; + if(!compiler_identifier(compiler,struct_name,sizeof(struct_name)))return 0; + if(compiler_take(compiler,'{'))return compiler_struct_definition(compiler,struct_name); + int structure=compiler_struct_find(compiler,struct_name); + if(structure<0)return 0; + type=(u8)(COMPILER_TYPE_STRUCT_BASE+(u32)structure); + is_struct=1; + } else if(compiler_word(compiler,"char"))is_char=1; + else if((long_type=compiler_integer_type(compiler))==0)return 0; + is_short=long_type==COMPILER_TYPE_SHORT; + is_pointer=compiler_take(compiler,'*'); + if(is_struct&&is_pointer) { + type=(u8)(COMPILER_TYPE_STRUCT_POINTER_BASE+ + type-COMPILER_TYPE_STRUCT_BASE); + is_struct=0;is_struct_pointer=1; + } + if(!compiler_identifier(compiler,name,sizeof(name)))return 0; + int array=compiler_take(compiler,'['); + if(array) { + u64 size; + if(is_pointer||is_struct||!compiler_integer(compiler,&size)||!size|| + !compiler_take(compiler,']'))return 0; + type=long_type==COMPILER_TYPE_USIZE?COMPILER_TYPE_USIZE_ARRAY: + (long_type==COMPILER_TYPE_LONG_LONG?COMPILER_TYPE_LONG_LONG_ARRAY: + (is_char?COMPILER_TYPE_CHAR_ARRAY: + (is_short?COMPILER_TYPE_SHORT_ARRAY:COMPILER_TYPE_INT_ARRAY))); + u32 element_size=compiler_array_element_size(type); + u32 maximum=sizeof(compiler->Data)/element_size; + if(size>maximum)return 0; + array_length=(u32)size; + bytes=array_length*element_size; + } else { + if(!is_struct&&!is_struct_pointer) + type=is_pointer?compiler_pointer_type(is_char?COMPILER_TYPE_CHAR:long_type): + (is_char?COMPILER_TYPE_CHAR:long_type); + bytes=is_struct?compiler_type_size(compiler,type): + (is_pointer?8u:compiler_type_size(compiler,type)); + } + if(!compiler_global_add(compiler,name,type,array_length,bytes,&index))return 0; + BOB64_C_GLOBAL *global=&compiler->Globals[index]; + if(compiler_take(compiler,'=')) { + if(is_struct)return 0; + if(is_pointer) { + usize string_offset,string_length; + if(is_char&&compiler_string(compiler,&string_offset,&string_length)) { + (void)string_length; + global->InitKind=2; + global->InitTarget=(u16)string_offset; + } else { + int address=compiler_take(compiler,'&'); + char target_name[32]; + if(compiler_identifier(compiler,target_name,sizeof(target_name))) { + int target=compiler_variable_find(compiler,target_name); + if(target<0||!compiler_variable_is_global((u32)target))return 0; + BOB64_C_GLOBAL *target_global=&compiler->Globals[(u32)target&0x7fffu]; + u8 target_type=target_global->Type; + u8 target_pointer_type; + if(compiler_type_is_struct(target_type)) + target_pointer_type=(u8)(COMPILER_TYPE_STRUCT_POINTER_BASE+ + target_type-COMPILER_TYPE_STRUCT_BASE); + else if(compiler_type_is_array(target_type)) + target_pointer_type=compiler_pointer_type(target_type); + else if(address) + target_pointer_type=compiler_pointer_type(target_type); + else target_pointer_type=0; + if(target_pointer_type!=type|| + (compiler_type_is_struct(target_type)&&!address))return 0; + global->InitKind=1; + global->InitTarget=target_global->DataOffset; + } else { + u64 value; + if(!compiler_integer(compiler,&value)||value!=0)return 0; + } + } + } else if(array&&is_char) { + usize string_offset,string_length; + if(compiler_string(compiler,&string_offset,&string_length)) { + if(string_length>array_length)return 0; + for(u32 i=0;iData[global->DataOffset+i]=compiler->Data[string_offset+i]; + } else { + if(!compiler_take(compiler,'{'))return 0; + u32 element=0; + for(;;) { + if(compiler_take(compiler,'}'))break; + u64 value; + if(element>=array_length|| + (!compiler_character(compiler,&value)&& + !compiler_integer(compiler,&value)))return 0; + compiler->Data[global->DataOffset+element++]=(u8)value; + if(compiler_take(compiler,'}'))break; + if(!compiler_take(compiler,','))return 0; + } + } + } else if(array) { + if(!compiler_take(compiler,'{'))return 0; + u32 element=0; + for(;;) { + if(compiler_take(compiler,'}'))break; + u64 value; + if(element>=array_length|| + (!compiler_character(compiler,&value)&& + !compiler_integer(compiler,&value)))return 0; + u32 element_size=compiler_array_element_size((u8)type); + u32 offset=global->DataOffset+element++*element_size; + for(u32 byte=0;byteData[offset+byte]=(u8)(value>>(byte*8)); + if(compiler_take(compiler,'}'))break; + if(!compiler_take(compiler,','))return 0; + } + } else { + u64 value; + if(!compiler_character(compiler,&value)&& + !compiler_integer(compiler,&value))return 0; + for(u32 byte=0;byteData[global->DataOffset+byte]=(u8)(value>>(byte*8)); + } + } + return compiler_take(compiler,';'); +} + +static int compiler_collect_function_sources(BOB64_C_COMPILER *compiler, + u32 *main_source_index) { + usize scan=0; + u32 main_count=0; + compiler->FunctionSourceCount=0; + while(scanLength) { + compiler->Position=scan; + compiler_skip(compiler); + if(compiler->Failed)return 0; + if(compiler->Position>=compiler->Length)break; + usize start=compiler->Position; + char name[32],parameter_names[COMPILER_ARGUMENT_LIMIT][32]; + u8 return_type,argument_count,argument_types[COMPILER_ARGUMENT_LIMIT]; + if(!compiler_function_signature(compiler,name,sizeof(name),&return_type, + &argument_count,argument_types,parameter_names,0)) { + compiler->Position=start; + if(!compiler_global_declaration(compiler))return 0; + scan=compiler->Position; + continue; + } + if(!compiler_function_declare(compiler,name,0,return_type,argument_count, + argument_types,0))return 0; + compiler_skip(compiler); + if(compiler->Position>=compiler->Length)return 0; + if(compiler->Source[compiler->Position]==';') { + compiler->Position++; + scan=compiler->Position; + continue; + } + if(compiler->Source[compiler->Position]!='{'|| + compiler->FunctionSourceCount>=COMPILER_FUNCTION_LIMIT)return 0; + compiler->Position++; + usize position=compiler->Position; + u32 depth=1; + while(positionLength&&depth) { + char value=compiler->Source[position]; + if(value=='/'&&position+1Length) { + usize next=position; + int skipped=compiler_scan_skip_comment(compiler,&next); + if(skipped<0)return 0; + if(skipped) { position=next;continue; } + } + if(value=='\''||value=='"') { + if(!compiler_scan_skip_quote(compiler,&position))return 0; + continue; + } + if(value=='{')depth++; + else if(value=='}')depth--; + position++; + } + if(depth)return 0; + usize end=position; + u32 source_index=compiler->FunctionSourceCount++; + compiler->FunctionSourceStart[source_index]=(u16)start; + compiler->FunctionSourceEnd[source_index]=(u16)end; + if(name[0]=='m'&&name[1]=='a'&&name[2]=='i'&&name[3]=='n'&&!name[4]) { + *main_source_index=source_index; + main_count++; + } + scan=end; + } + compiler->Position=0; + return main_count==1; +} + +int bob64_compile_c(const char *source,usize source_length,void *output, + usize output_capacity,usize *output_length, + usize *error_offset) { + /* The initial kernel is single-tasked; a later compiler job queue needs per-job state. */ + static BOB64_C_COMPILER compiler; + static u8 payload[2*BOB64_PAGE_SIZE]; + u8 *file=(u8 *)output; + u32 main_source_index=0; + if(output_length)*output_length=0; + if(error_offset)*error_offset=0; + if(!source||!output||!output_length||source_length>BOB64_COMPILER_SOURCE_LIMIT|| + output_capacity8?framebuffer.Height-8:0; + for(u32 y=0;y='a'&&value<='z')value=(u8)(value-'a'+'A'); + if(value==' ')return 0; + if(value>='A'&&value<='Z')return 1u+(u32)(value-'A'); + if(value>='0'&&value<='9')return 27u+(u32)(value-'0'); + if(value=='!')return 38; + if(value=='-')return 39; + if(value=='.')return 40; + if(value==':')return 41; + if(value=='=')return 42; + if(value=='>')return 43; + return 37; +} + +static void draw_character(u8 value) { + u32 foreground=color(228,238,248),background=color(12,18,28); + u32 glyph=glyph_index(value),origin_x=framebuffer.Column*6,origin_y=framebuffer.Row*8; + for(u32 y=0;y<8;y++)for(u32 x=0;x<6;x++) { + u32 on=x<5&&y<7&&(bob64_font5x7[glyph][x]&(1u<=framebuffer.Width/6) { + framebuffer.Column=0; + framebuffer.Row++; + } + if(framebuffer.Row>=framebuffer.Height/8)scroll(); +} + +static void erase_previous_character(void) { + u32 columns=framebuffer.Width/6; + if(framebuffer.Column)framebuffer.Column--; + else if(framebuffer.Row) { + framebuffer.Row--; + framebuffer.Column=columns-1; + } else return; + u32 origin_x=framebuffer.Column*6,origin_y=framebuffer.Row*8; + for(u32 y=0;y<8;y++)for(u32 x=0;x<6;x++) + pixel(origin_x+x,origin_y+y,color(12,18,28)); +} + +int bob64_framebuffer_init(u64 base,u64 size,u32 width,u32 height, + u32 pixels_per_scan_line,u32 pixel_format) { + u64 pixels,required; + if(!base||!size||width<6||height<8||pixels_per_scan_line~(u64)0/height)return -1; + pixels=(u64)pixels_per_scan_line*height; + if(pixels>~(u64)0/sizeof(u32))return -1; + required=pixels*sizeof(u32); + if(required>size)return -1; + framebuffer.Pixels=(volatile u32 *)(uintptr_t)base; + framebuffer.SizeBytes=size; + framebuffer.Width=width;framebuffer.Height=height; + framebuffer.Stride=pixels_per_scan_line;framebuffer.Format=pixel_format; + framebuffer.Column=0;framebuffer.Row=0;framebuffer.Ready=1; + for(u32 y=0;ytotal||(u64)count>total-first_pixel)return -1; + for(u32 i=0;i>16)&0xff,green=(pixels[i]>>8)&0xff,blue=pixels[i]&0xff; + pixel((u32)(index%framebuffer.Width),(u32)(index/framebuffer.Width), + color((u8)red,(u8)green,(u8)blue)); + } + return 0; +} + +void bob64_framebuffer_write(const char *text) { + if(!framebuffer.Ready||!text)return; + while(*text) { + u8 value=(u8)*text++; + if(value=='\r')framebuffer.Column=0; + else if(value=='\n') { + framebuffer.Column=0;framebuffer.Row++; + if(framebuffer.Row>=framebuffer.Height/8)scroll(); + } else if(value=='\b')erase_previous_character(); + else draw_character(value); + } +} diff --git a/bob64/console.h b/bob64/console.h new file mode 100644 index 0000000..2d5754c --- /dev/null +++ b/bob64/console.h @@ -0,0 +1,16 @@ +#ifndef BOB64_CONSOLE_H +#define BOB64_CONSOLE_H + +#include "types.h" + +/* UEFI GOP pixel formats 0 and 1; returns nonzero when unsupported/invalid. */ +int bob64_framebuffer_init(u64 base,u64 size,u32 width,u32 height, + u32 pixels_per_scan_line,u32 pixel_format); +int bob64_framebuffer_available(void); +int bob64_framebuffer_resolution(u32 *width,u32 *height); +/* App surfaces use packed 0x00RRGGBB pixels in row-major order. */ +int bob64_framebuffer_write_pixels(u64 first_pixel,const u32 *pixels,u32 count); +void bob64_framebuffer_clear(void); +void bob64_framebuffer_write(const char *text); + +#endif diff --git a/bob64/cpu.c b/bob64/cpu.c new file mode 100644 index 0000000..9d5933d --- /dev/null +++ b/bob64/cpu.c @@ -0,0 +1,58 @@ +#include "cpu.h" + +#define CPUID_PAE (1u<<6) +#define CPUID_LONG_MODE (1u<<29) +#define CPUID_NX (1u<<20) + +int bob64_cpu_decode_features(u32 max_basic_leaf,u32 max_extended_leaf, + u32 basic_leaf1_edx,u32 extended_leaf1_edx, + u32 extended_leaf8_eax,BOB64_CPU_FEATURES *features) { + u32 physical_bits; + if(!features)return -1; + features->PAE=(u8)(max_basic_leaf>=1&&(basic_leaf1_edx&CPUID_PAE)!=0); + features->LongMode=(u8)(max_extended_leaf>=0x80000001u&& + (extended_leaf1_edx&CPUID_LONG_MODE)!=0); + features->NX=(u8)(max_extended_leaf>=0x80000001u&& + (extended_leaf1_edx&CPUID_NX)!=0); + if(max_extended_leaf>=0x80000008u) { + physical_bits=extended_leaf8_eax&0xffu; + if(physical_bits<36||physical_bits>52)return -1; + } else physical_bits=36; + features->PhysicalAddressBits=(u8)physical_bits; + return 0; +} + +static void cpuid(u32 leaf,u32 *eax,u32 *ebx,u32 *ecx,u32 *edx) { + u32 a=leaf,b=0,c=0,d=0; + __asm__ volatile("cpuid":"+a"(a),"=b"(b),"=c"(c),"=d"(d)); + if(eax)*eax=a; + if(ebx)*ebx=b; + if(ecx)*ecx=c; + if(edx)*edx=d; +} + +int bob64_cpu_detect(BOB64_CPU_FEATURES *features) { + u32 max_basic=0,max_extended=0,leaf1_edx=0,extended1_edx=0,extended8_eax=0; + cpuid(0,&max_basic,0,0,0); + cpuid(0x80000000u,&max_extended,0,0,0); + if(max_basic>=1)cpuid(1,0,0,0,&leaf1_edx); + if(max_extended>=0x80000001u)cpuid(0x80000001u,0,0,0,&extended1_edx); + if(max_extended>=0x80000008u)cpuid(0x80000008u,&extended8_eax,0,0,0); + return bob64_cpu_decode_features(max_basic,max_extended,leaf1_edx, + extended1_edx,extended8_eax,features); +} + +int bob64_cpu_long_mode_active(const BOB64_CPU_FEATURES *features) { + u32 efer_low,efer_high; + u32 ecx=0xc0000080u; + if(!features||!features->PAE||!features->LongMode)return 0; + __asm__ volatile("rdmsr":"=a"(efer_low),"=d"(efer_high):"c"(ecx)); + (void)efer_high; + return (efer_low&(1u<<10))!=0; +} + +int bob64_cpu_four_level_paging_active(void) { + u64 cr4; + __asm__ volatile("mov %%cr4,%0":"=r"(cr4)); + return (cr4&(1ULL<<5))!=0&&!(cr4&(1ULL<<12)); /* PAE set, LA57 clear. */ +} diff --git a/bob64/cpu.h b/bob64/cpu.h new file mode 100644 index 0000000..b6662f4 --- /dev/null +++ b/bob64/cpu.h @@ -0,0 +1,20 @@ +#ifndef BOB64_CPU_H +#define BOB64_CPU_H + +#include "types.h" + +typedef struct { + u8 PAE; + u8 LongMode; + u8 NX; + u8 PhysicalAddressBits; +} BOB64_CPU_FEATURES; + +int bob64_cpu_decode_features(u32 max_basic_leaf,u32 max_extended_leaf, + u32 basic_leaf1_edx,u32 extended_leaf1_edx, + u32 extended_leaf8_eax,BOB64_CPU_FEATURES *features); +int bob64_cpu_detect(BOB64_CPU_FEATURES *features); +int bob64_cpu_long_mode_active(const BOB64_CPU_FEATURES *features); +int bob64_cpu_four_level_paging_active(void); + +#endif diff --git a/bob64/descriptors.c b/bob64/descriptors.c new file mode 100644 index 0000000..76eac54 --- /dev/null +++ b/bob64/descriptors.c @@ -0,0 +1,71 @@ +#include "descriptors.h" + +#define BOB64_GDT_CODE 0x00af9a000000ffffULL +#define BOB64_GDT_DATA 0x00cf92000000ffffULL +#define BOB64_GDT_USER_CODE 0x00affa000000ffffULL +#define BOB64_GDT_USER_DATA 0x00cff2000000ffffULL +#define BOB64_GDT_TSS_ACCESS 0x89u +#define BOB64_IDT_PRESENT 0x80u + +int bob64_tss_init(BOB64_TSS *tss,u64 ring0_stack_top) { + if(!tss||!ring0_stack_top||(ring0_stack_top&15))return -1; + for(usize i=0;iRsp0=ring0_stack_top; + tss->IoMapBase=(u16)sizeof(*tss); + return 0; +} + +int bob64_tss_set_rsp0(BOB64_TSS *tss,u64 ring0_stack_top) { + if(!tss||!ring0_stack_top||(ring0_stack_top&15))return -1; + tss->Rsp0=ring0_stack_top; + return 0; +} + +void bob64_gdt_init(u64 entries[BOB64_GDT_ENTRY_COUNT], + BOB64_DESCRIPTOR_TABLE_POINTER *pointer,const BOB64_TSS *tss) { + u64 base,limit,descriptor; + if(!entries||!pointer||!tss)return; + base=(u64)(uintptr_t)tss;limit=sizeof(*tss)-1; + entries[0]=0; + entries[1]=BOB64_GDT_CODE; + entries[2]=BOB64_GDT_DATA; + entries[3]=BOB64_GDT_USER_DATA; + entries[4]=BOB64_GDT_USER_CODE; + descriptor=(limit&0xffffULL)|((base&0xffffffULL)<<16)| + ((u64)BOB64_GDT_TSS_ACCESS<<40)| + ((limit&0xf0000ULL)<<32)|((base&0xff000000ULL)<<32); + entries[5]=descriptor;entries[6]=base>>32; + pointer->Limit=(u16)(BOB64_GDT_ENTRY_COUNT*sizeof(entries[0])-1); + pointer->Base=(u64)(uintptr_t)entries; +} + +int bob64_idt_set_gate(BOB64_IDT_GATE *gate,u64 handler,u16 selector,u8 ist, + u8 dpl,u8 gate_type) { + if(!gate||!handler||!selector||ist>7||dpl>3|| + (gate_type!=BOB64_IDT_INTERRUPT_GATE&&gate_type!=BOB64_IDT_TRAP_GATE)) + return -1; + gate->OffsetLow=(u16)handler; + gate->Selector=selector; + gate->Ist=ist; + gate->TypeAttributes=(u8)(BOB64_IDT_PRESENT|(dpl<<5)|gate_type); + gate->OffsetMiddle=(u16)(handler>>16); + gate->OffsetHigh=(u32)(handler>>32); + gate->Reserved=0; + return 0; +} + +int bob64_idt_init(BOB64_IDT_GATE entries[BOB64_IDT_ENTRIES],u64 default_handler, + u16 selector,u8 ist) { + BOB64_IDT_GATE default_gate; + if(!entries||bob64_idt_set_gate(&default_gate,default_handler,selector,ist,0, + BOB64_IDT_INTERRUPT_GATE))return -1; + for(usize i=0;iLimit=(u16)(BOB64_IDT_ENTRIES*sizeof(entries[0])-1); + pointer->Base=(u64)(uintptr_t)entries; +} diff --git a/bob64/descriptors.h b/bob64/descriptors.h new file mode 100644 index 0000000..6b814e2 --- /dev/null +++ b/bob64/descriptors.h @@ -0,0 +1,59 @@ +#ifndef BOB64_DESCRIPTORS_H +#define BOB64_DESCRIPTORS_H + +#include "types.h" + +#define BOB64_GDT_KERNEL_CODE_SELECTOR 0x08u +#define BOB64_GDT_KERNEL_DATA_SELECTOR 0x10u +#define BOB64_GDT_USER_DATA_SELECTOR 0x1bu +#define BOB64_GDT_USER_CODE_SELECTOR 0x23u +#define BOB64_GDT_TSS_SELECTOR 0x28u +#define BOB64_GDT_ENTRY_COUNT 7u +#define BOB64_IDT_ENTRIES 256 +#define BOB64_IDT_INTERRUPT_GATE 0x0eu +#define BOB64_IDT_TRAP_GATE 0x0fu + +typedef struct __attribute__((packed)) { + u16 Limit; + u64 Base; +} BOB64_DESCRIPTOR_TABLE_POINTER; + +typedef struct __attribute__((packed)) { + u16 OffsetLow; + u16 Selector; + u8 Ist; + u8 TypeAttributes; + u16 OffsetMiddle; + u32 OffsetHigh; + u32 Reserved; +} BOB64_IDT_GATE; + +typedef struct __attribute__((packed)) { + u32 Reserved0; + u64 Rsp0,Rsp1,Rsp2; + u64 Reserved1; + u64 Ist1,Ist2,Ist3,Ist4,Ist5,Ist6,Ist7; + u64 Reserved2; + u16 Reserved3; + u16 IoMapBase; +} BOB64_TSS; + +_Static_assert(sizeof(BOB64_DESCRIPTOR_TABLE_POINTER)==10,"x86-64 GDTR/IDTR layout"); +_Static_assert(sizeof(BOB64_IDT_GATE)==16,"x86-64 IDT gate layout"); +_Static_assert(sizeof(BOB64_TSS)==104,"x86-64 TSS layout"); +_Static_assert(__builtin_offsetof(BOB64_TSS,Rsp0)==4,"x86-64 TSS RSP0 offset"); +_Static_assert(__builtin_offsetof(BOB64_TSS,Ist1)==36,"x86-64 TSS IST offset"); +_Static_assert(__builtin_offsetof(BOB64_TSS,IoMapBase)==102,"x86-64 TSS I/O map offset"); + +int bob64_tss_init(BOB64_TSS *tss,u64 ring0_stack_top); +int bob64_tss_set_rsp0(BOB64_TSS *tss,u64 ring0_stack_top); +void bob64_gdt_init(u64 entries[BOB64_GDT_ENTRY_COUNT], + BOB64_DESCRIPTOR_TABLE_POINTER *pointer,const BOB64_TSS *tss); +int bob64_idt_set_gate(BOB64_IDT_GATE *gate,u64 handler,u16 selector,u8 ist, + u8 dpl,u8 gate_type); +int bob64_idt_init(BOB64_IDT_GATE entries[BOB64_IDT_ENTRIES],u64 default_handler, + u16 selector,u8 ist); +void bob64_idt_pointer(BOB64_DESCRIPTOR_TABLE_POINTER *pointer, + const BOB64_IDT_GATE entries[BOB64_IDT_ENTRIES]); + +#endif diff --git a/bob64/editor.h b/bob64/editor.h new file mode 100644 index 0000000..c981594 --- /dev/null +++ b/bob64/editor.h @@ -0,0 +1,104 @@ +#ifndef BOB64_EDITOR_H +#define BOB64_EDITOR_H + +#include "abi.h" + +#define BOB64_EDITOR_CAPACITY BOB64_SYSCALL_MAX_BUFFER + +typedef struct { + char Text[BOB64_EDITOR_CAPACITY+1]; + u32 Length; + u32 Cursor; + u32 ScrollRow; + u8 Dirty; +} BOB64_EDITOR; + +static inline void bob64_editor_init(BOB64_EDITOR *editor,const char *text,u32 length) { + if(!editor)return; + if(length>BOB64_EDITOR_CAPACITY)length=BOB64_EDITOR_CAPACITY; + for(u32 i=0;iText[i]=text?text[i]:0; + editor->Text[length]=0;editor->Length=length;editor->Cursor=length; + editor->ScrollRow=0;editor->Dirty=0; +} + +static inline int bob64_editor_insert(BOB64_EDITOR *editor,char character) { + if(!editor||editor->Length>=BOB64_EDITOR_CAPACITY|| + !((character>=32&&character<=126)||character=='\n'))return -1; + for(u32 i=editor->Length;i>editor->Cursor;i--)editor->Text[i]=editor->Text[i-1]; + editor->Text[editor->Cursor++]=character; + editor->Length++;editor->Text[editor->Length]=0;editor->Dirty=1; + return 0; +} + +static inline int bob64_editor_backspace(BOB64_EDITOR *editor) { + if(!editor||!editor->Cursor)return -1; + for(u32 i=editor->Cursor-1;iLength-1;i++)editor->Text[i]=editor->Text[i+1]; + editor->Cursor--;editor->Length--;editor->Text[editor->Length]=0;editor->Dirty=1; + return 0; +} + +static inline int bob64_editor_delete(BOB64_EDITOR *editor) { + if(!editor||editor->Cursor>=editor->Length)return -1; + for(u32 i=editor->Cursor;iLength-1;i++)editor->Text[i]=editor->Text[i+1]; + editor->Length--;editor->Text[editor->Length]=0;editor->Dirty=1; + return 0; +} + +static inline void bob64_editor_move(BOB64_EDITOR *editor,s32 direction) { + if(!editor)return; + if(direction<0&&editor->Cursor)editor->Cursor--; + else if(direction>0&&editor->CursorLength)editor->Cursor++; +} + +static inline void bob64_editor_move_vertical(BOB64_EDITOR *editor,s32 direction) { + u32 line_start=0,column=0,target_start,target_end,target_column; + if(!editor||!direction)return; + for(u32 i=0;iCursor;i++) { + if(editor->Text[i]=='\n'){line_start=i+1;column=0;}else column++; + } + if(direction<0) { + if(!line_start)return; + target_start=0; + for(u32 i=0;iText[i]=='\n')target_start=i+1; + target_end=line_start-1; + } else { + target_start=editor->Cursor; + while(target_startLength&&editor->Text[target_start]!='\n')target_start++; + if(target_start==editor->Length)return; + target_start++; + target_end=target_start; + while(target_endLength&&editor->Text[target_end]!='\n')target_end++; + } + target_column=column; + if(target_column>target_end-target_start)target_column=target_end-target_start; + editor->Cursor=target_start+target_column; +} + +static inline void bob64_editor_visual_position(const BOB64_EDITOR *editor, + u32 columns,u32 *row_out,u32 *column_out) { + u32 row=0,column=0; + if(!editor||!row_out||!column_out)return; + if(!columns)columns=1; + for(u32 i=0;iCursor;i++) { + if(column>=columns&&editor->Text[i]!='\n'){row++;column=0;} + if(editor->Text[i]=='\n'){row++;column=0;} + else column++; + } + if(column>=columns){row++;column=0;} + *row_out=row;*column_out=column; +} + +static inline void bob64_editor_handle_key(BOB64_EDITOR *editor,const BOB64_EVENT *event) { + if(!editor||!event||event->Type!=BOB64_EVENT_KEY_DOWN)return; + if(event->Key==(BOB64_EVENT_KEY_EXTENDED|0x4b))bob64_editor_move(editor,-1); + else if(event->Key==(BOB64_EVENT_KEY_EXTENDED|0x4d))bob64_editor_move(editor,1); + else if(event->Key==(BOB64_EVENT_KEY_EXTENDED|0x48))bob64_editor_move_vertical(editor,-1); + else if(event->Key==(BOB64_EVENT_KEY_EXTENDED|0x50))bob64_editor_move_vertical(editor,1); + else if(event->Key==(BOB64_EVENT_KEY_EXTENDED|0x53))bob64_editor_delete(editor); + else if(event->Character=='\b')bob64_editor_backspace(editor); + else if(event->Character=='\n')bob64_editor_insert(editor,'\n'); + else if(event->Character>=32&&event->Character<=126) + bob64_editor_insert(editor,(char)event->Character); +} + +#endif diff --git a/bob64/efi.h b/bob64/efi.h new file mode 100644 index 0000000..080acff --- /dev/null +++ b/bob64/efi.h @@ -0,0 +1,200 @@ +#ifndef BOB64_EFI_H +#define BOB64_EFI_H + +#include "types.h" + +#define EFIAPI __attribute__((ms_abi)) +typedef u16 CHAR16; +typedef uintptr_t UINTN; +typedef u64 EFI_STATUS; +typedef void *EFI_HANDLE; + +#define EFI_SUCCESS 0ULL +#define EFI_INVALID_PARAMETER 0x8000000000000002ULL +#define EFI_BUFFER_TOO_SMALL 0x8000000000000005ULL +#define EFI_UNSUPPORTED 0x8000000000000003ULL +#define EFI_ERROR(status) (((EFI_STATUS)(status) >> 63) != 0) +#define EFI_MEMORY_CONVENTIONAL 7u +#define EFI_MEMORY_LOADER_DATA 2u +#define EFI_PAGE_SIZE 4096ULL + +typedef struct { + u64 Signature; + u32 Revision; + u32 HeaderSize; + u32 CRC32; + u32 Reserved; +} EFI_TABLE_HEADER; + +typedef struct { + u32 Type; + u32 Pad; + u64 PhysicalStart; + u64 VirtualStart; + u64 NumberOfPages; + u64 Attribute; +} EFI_MEMORY_DESCRIPTOR; + +typedef EFI_STATUS (EFIAPI *EFI_GET_MEMORY_MAP)(UINTN *,EFI_MEMORY_DESCRIPTOR *, + UINTN *,UINTN *,u32 *); +typedef EFI_STATUS (EFIAPI *EFI_ALLOCATE_POOL)(u32,UINTN,void **); +typedef struct { + u32 Data1; + u16 Data2; + u16 Data3; + u8 Data4[8]; +} EFI_GUID; +typedef EFI_STATUS (EFIAPI *EFI_HANDLE_PROTOCOL)(EFI_HANDLE,const EFI_GUID *,void **); +typedef EFI_STATUS (EFIAPI *EFI_EXIT_BOOT_SERVICES)(EFI_HANDLE,UINTN); +typedef EFI_STATUS (EFIAPI *EFI_LOCATE_PROTOCOL)(const EFI_GUID *,void *,void **); + +typedef struct { + EFI_TABLE_HEADER Hdr; + void *RaiseTPL; + void *RestoreTPL; + void *AllocatePages; + void *FreePages; + EFI_GET_MEMORY_MAP GetMemoryMap; + EFI_ALLOCATE_POOL AllocatePool; + void *FreePool; + void *CreateEvent; + void *SetTimer; + void *WaitForEvent; + void *SignalEvent; + void *CloseEvent; + void *CheckEvent; + void *InstallProtocolInterface; + void *ReinstallProtocolInterface; + void *UninstallProtocolInterface; + EFI_HANDLE_PROTOCOL HandleProtocol; + void *Reserved; + void *RegisterProtocolNotify; + void *LocateHandle; + void *LocateDevicePath; + void *InstallConfigurationTable; + void *LoadImage; + void *StartImage; + void *Exit; + void *UnloadImage; + EFI_EXIT_BOOT_SERVICES ExitBootServices; + void *GetNextMonotonicCount; + void *Stall; + void *SetWatchdogTimer; + void *ConnectController; + void *DisconnectController; + void *OpenProtocol; + void *CloseProtocol; + void *OpenProtocolInformation; + void *ProtocolsPerHandle; + void *LocateHandleBuffer; + EFI_LOCATE_PROTOCOL LocateProtocol; +} EFI_BOOT_SERVICES; + +typedef struct { + u32 Version; + u32 HorizontalResolution; + u32 VerticalResolution; + u32 PixelFormat; + u32 PixelInformation[4]; + u32 PixelsPerScanLine; +} EFI_GRAPHICS_OUTPUT_MODE_INFORMATION; + +typedef struct { + u32 MaxMode; + u32 Mode; + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info; + UINTN SizeOfInfo; + u64 FrameBufferBase; + UINTN FrameBufferSize; +} EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE; + +typedef struct { + void *QueryMode; + void *SetMode; + void *Blt; + EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode; +} EFI_GRAPHICS_OUTPUT_PROTOCOL; + +typedef struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL; +typedef EFI_STATUS (EFIAPI *EFI_TEXT_RESET)(EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *, u8); +typedef EFI_STATUS (EFIAPI *EFI_TEXT_OUTPUT_STRING)(EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *, const CHAR16 *); + +struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL { + EFI_TEXT_RESET Reset; + EFI_TEXT_OUTPUT_STRING OutputString; + void *TestString; + void *QueryMode; + void *SetMode; + void *SetAttribute; + void *ClearScreen; + void *SetCursorPosition; + void *EnableCursor; + void *Mode; +}; + +typedef struct { + EFI_TABLE_HEADER Hdr; + CHAR16 *FirmwareVendor; + u32 FirmwareRevision; + EFI_HANDLE ConsoleInHandle; + void *ConIn; + EFI_HANDLE ConsoleOutHandle; + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut; + EFI_HANDLE StandardErrorHandle; + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *StdErr; + void *RuntimeServices; + EFI_BOOT_SERVICES *BootServices; + UINTN NumberOfTableEntries; + void *ConfigurationTable; +} EFI_SYSTEM_TABLE; + +typedef struct { + u32 Revision; + EFI_HANDLE ParentHandle; + EFI_SYSTEM_TABLE *SystemTable; + EFI_HANDLE DeviceHandle; + void *FilePath; + void *Reserved; + u32 LoadOptionsSize; + void *LoadOptions; + void *ImageBase; + u64 ImageSize; + u32 ImageCodeType; + u32 ImageDataType; + void *UnloadImage; +} EFI_LOADED_IMAGE_PROTOCOL; + +_Static_assert(sizeof(uintptr_t)==sizeof(EFI_STATUS),"EFI x64 status width mismatch"); +_Static_assert(__builtin_offsetof(EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL,OutputString)==8, + "UEFI text protocol layout mismatch"); +_Static_assert(__builtin_offsetof(EFI_SYSTEM_TABLE,ConOut)==64, + "UEFI x64 system table layout mismatch"); +_Static_assert(sizeof(EFI_SYSTEM_TABLE)==120,"UEFI x64 system table size mismatch"); +_Static_assert(sizeof(EFI_MEMORY_DESCRIPTOR)==40,"UEFI x64 memory descriptor layout mismatch"); +_Static_assert(__builtin_offsetof(EFI_BOOT_SERVICES,GetMemoryMap)==56, + "UEFI x64 boot services layout mismatch"); +_Static_assert(__builtin_offsetof(EFI_BOOT_SERVICES,AllocatePool)==64, + "UEFI x64 allocation service layout mismatch"); +_Static_assert(__builtin_offsetof(EFI_BOOT_SERVICES,HandleProtocol)==152, + "UEFI x64 HandleProtocol table offset mismatch"); +_Static_assert(__builtin_offsetof(EFI_BOOT_SERVICES,ExitBootServices)==232, + "UEFI x64 ExitBootServices table offset mismatch"); +_Static_assert(__builtin_offsetof(EFI_BOOT_SERVICES,LocateProtocol)==320, + "UEFI x64 LocateProtocol table offset mismatch"); +_Static_assert(sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION)==36, + "UEFI GOP mode information layout mismatch"); +_Static_assert(__builtin_offsetof(EFI_GRAPHICS_OUTPUT_PROTOCOL,Mode)==24, + "UEFI GOP protocol mode pointer offset mismatch"); +_Static_assert(__builtin_offsetof(EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE,FrameBufferBase)==24, + "UEFI GOP framebuffer base offset mismatch"); +_Static_assert(__builtin_offsetof(EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE,FrameBufferSize)==32&& + sizeof(EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE)==40, + "UEFI GOP mode layout mismatch"); +_Static_assert(__builtin_offsetof(EFI_LOADED_IMAGE_PROTOCOL,ImageBase)==64, + "UEFI loaded image base offset mismatch"); +_Static_assert(__builtin_offsetof(EFI_LOADED_IMAGE_PROTOCOL,ImageSize)==72, + "UEFI loaded image size offset mismatch"); +_Static_assert(sizeof(EFI_LOADED_IMAGE_PROTOCOL)==96, + "UEFI x64 loaded image protocol size mismatch"); + +#endif diff --git a/bob64/embedded_app.S b/bob64/embedded_app.S new file mode 100644 index 0000000..308a322 --- /dev/null +++ b/bob64/embedded_app.S @@ -0,0 +1,28 @@ +.intel_syntax noprefix +#ifdef __MINGW32__ +.section .rdata,"dr" +#else +.section .rodata +#endif +.balign 16 +.globl bob64_embedded_app +.globl bob64_embedded_app_end +bob64_embedded_app: + .incbin "build/bob64-app/smoke.b64e" +bob64_embedded_app_end: +.balign 16 +.globl bob64_embedded_gui +.globl bob64_embedded_gui_end +bob64_embedded_gui: + .incbin "build/bob64-app/gui.b64e" +bob64_embedded_gui_end: +.balign 16 +.globl bob64_embedded_source +.globl bob64_embedded_source_end +bob64_embedded_source: + .incbin "apps/bob64_demo.c" +bob64_embedded_source_end: + +#ifndef __MINGW32__ +.section .note.GNU-stack,"",@progbits +#endif diff --git a/bob64/event.h b/bob64/event.h new file mode 100644 index 0000000..270d0e4 --- /dev/null +++ b/bob64/event.h @@ -0,0 +1,33 @@ +#ifndef BOB64_EVENT_H +#define BOB64_EVENT_H + +#include "types.h" + +#define BOB64_EVENT_KEY_DOWN 1u +#define BOB64_EVENT_KEY_UP 2u +#define BOB64_EVENT_MOUSE_MOVE 3u +#define BOB64_EVENT_MOUSE_BUTTON 4u +#define BOB64_EVENT_MOUSE_WHEEL 5u +#define BOB64_EVENT_MOD_SHIFT 1u +#define BOB64_EVENT_MOD_CAPS_LOCK 2u +#define BOB64_EVENT_MOD_CONTROL 4u +#define BOB64_EVENT_MOD_ALT 8u +#define BOB64_EVENT_KEY_EXTENDED 0x100u + +/* Set-1 scan codes; extended keys set BOB64_EVENT_KEY_EXTENDED. */ +typedef struct { + u32 Type; + u32 Key; + u32 Character; + u32 Modifiers; + s32 X,Y; + s32 DeltaX,DeltaY; + u32 Buttons; + s32 Wheel; + u64 WindowHandle; + s32 ScreenX,ScreenY; +} BOB64_EVENT; + +_Static_assert(sizeof(BOB64_EVENT)==56,"bob64 input-event ABI size"); + +#endif diff --git a/bob64/exec.c b/bob64/exec.c new file mode 100644 index 0000000..78b199a --- /dev/null +++ b/bob64/exec.c @@ -0,0 +1,66 @@ +#include "exec.h" +#include "paging.h" + +static u16 read16(const u8 *bytes) { + return (u16)((u16)bytes[0]|((u16)bytes[1]<<8)); +} + +static u32 read32(const u8 *bytes) { + return (u32)bytes[0]|((u32)bytes[1]<<8)|((u32)bytes[2]<<16)|((u32)bytes[3]<<24); +} + +static u64 read64(const u8 *bytes) { + return (u64)read32(bytes)|((u64)read32(bytes+4)<<32); +} + +static u32 payload_checksum(const u8 *bytes,usize length) { + u32 value=0xffffffffu; + for(usize i=0;i>1)^(0xedb88320u&-(value&1u)); + } + return ~value; +} + +int bob64_exec_parse(const void *file,usize file_size,BOB64_EXEC_IMAGE *image) { + const u8 *bytes=(const u8 *)file; + u64 payload_size,memory_size,entry_offset,code_size; + if(!bytes||!image||file_sizepayload_size||memory_size=code_size|| + read32(bytes+48)!=payload_checksum(bytes+BOB64_EXEC_HEADER_SIZE, + file_size-BOB64_EXEC_HEADER_SIZE)) + return -1; + for(usize i=52;iImage=bytes+BOB64_EXEC_HEADER_SIZE; + image->FileSize=payload_size;image->MemorySize=memory_size; + image->EntryOffset=entry_offset;image->CodeSize=code_size; + image->AbiVersion=BOB64_EXEC_ABI_VERSION;image->Flags=0; + return 0; +} + +int bob64_exec_load(const BOB64_EXEC_IMAGE *image,u64 load_address, + void *destination,usize destination_capacity, + u64 *entry_address) { + u8 *output=(u8 *)destination; + if(!image||!image->Image||!output||!entry_address|| + image->AbiVersion!=BOB64_EXEC_ABI_VERSION||image->Flags|| + !image->CodeSize||image->CodeSize>image->FileSize|| + image->FileSize>image->MemorySize||image->EntryOffset>=image->CodeSize|| + image->MemorySize>(u64)destination_capacity|| + image->MemorySize>~(u64)0-load_address|| + image->EntryOffset>~(u64)0-load_address) + return -1; + for(u64 i=0;iFileSize;i++)output[(usize)i]=image->Image[(usize)i]; + for(u64 i=image->FileSize;iMemorySize;i++)output[(usize)i]=0; + *entry_address=load_address+image->EntryOffset; + return 0; +} diff --git a/bob64/exec.h b/bob64/exec.h new file mode 100644 index 0000000..5356a6a --- /dev/null +++ b/bob64/exec.h @@ -0,0 +1,29 @@ +#ifndef BOB64_EXEC_H +#define BOB64_EXEC_H + +#include "abi.h" + +/* B64E is flat/PIC; code ends on a 4 KiB boundary. Offsets are bytes. */ +#define BOB64_EXEC_VERSION 1u +#define BOB64_EXEC_ABI_VERSION BOB64_APP_ABI_VERSION +#define BOB64_EXEC_HEADER_SIZE 64u + +typedef struct { + const u8 *Image; + u64 FileSize; + u64 MemorySize; + u64 EntryOffset; + u64 CodeSize; + u32 AbiVersion; + u32 Flags; +} BOB64_EXEC_IMAGE; + +/* Parse and validate an exact B64E file. No allocations or state changes. */ +int bob64_exec_parse(const void *file,usize file_size,BOB64_EXEC_IMAGE *image); + +/* Copy a validated image, zero its memory tail, and return its full-width entry. */ +int bob64_exec_load(const BOB64_EXEC_IMAGE *image,u64 load_address, + void *destination,usize destination_capacity, + u64 *entry_address); + +#endif diff --git a/bob64/filesystem.c b/bob64/filesystem.c new file mode 100644 index 0000000..70da2ce --- /dev/null +++ b/bob64/filesystem.c @@ -0,0 +1,169 @@ +#include "filesystem.h" + +static usize string_length(const char *text) { + usize length=0; + while(text[length])length++; + return length; +} + +static int valid_name(const char *name,usize *length) { + usize size; + if(!name)return 0; + size=string_length(name); + if(!size||size>=BOB64_FS_NAME_CAPACITY)return 0; + for(usize i=0;i='a'&&value<='z')||(value>='A'&&value<='Z')|| + (value>='0'&&value<='9')||value=='.'||value=='_'||value=='-'))return 0; + } + if(length)*length=size; + return 1; +} + +static BOB64_FS_FILE *find_file(const BOB64_FILESYSTEM *filesystem,const char *name, + BOB64_FS_FILE **previous) { + BOB64_FS_FILE *before=0; + if(!filesystem||!name)return 0; + for(BOB64_FS_FILE *file=filesystem->First;file;file=file->Next) { + const char *left=file->Name,*right=name; + while(*left&&*right&&*left==*right){left++;right++;} + if(!*left&&!*right) { + if(previous)*previous=before; + return file; + } + before=file; + } + if(previous)*previous=before; + return 0; +} + +int bob64_fs_init(BOB64_FILESYSTEM *filesystem,BOB64_HEAP *heap) { + if(!filesystem||!heap)return -1; + filesystem->First=0;filesystem->Heap=heap; + filesystem->FileCount=0;filesystem->BytesUsed=0; + return 0; +} + +int bob64_fs_write(BOB64_FILESYSTEM *filesystem,const char *name, + const void *data,usize length) { + usize name_length; + BOB64_FS_FILE *file; + char *new_data,*new_name=0; + if(!filesystem||!filesystem->Heap||!valid_name(name,&name_length)|| + (!data&&length)||length==~(usize)0)return -1; + const u8 *source=(const u8 *)data; + file=find_file(filesystem,name,0); + new_data=(char *)bob64_heap_alloc(filesystem->Heap,length+1); + if(!new_data)return -1; + for(usize i=0;iHeap,1,sizeof(*file)); + new_name=(char *)bob64_heap_alloc(filesystem->Heap,name_length+1); + if(!file||!new_name) { + if(file)bob64_heap_free(filesystem->Heap,file); + if(new_name)bob64_heap_free(filesystem->Heap,new_name); + bob64_heap_free(filesystem->Heap,new_data); + return -1; + } + for(usize i=0;iName=new_name;file->Next=filesystem->First; + filesystem->First=file;filesystem->FileCount++; + } else { + filesystem->BytesUsed-=file->Length; + bob64_heap_free(filesystem->Heap,file->Data); + } + file->Data=new_data;file->Length=length; + filesystem->BytesUsed+=length; + return 0; +} + +int bob64_fs_read(const BOB64_FILESYSTEM *filesystem,const char *name, + const char **data,usize *length) { + BOB64_FS_FILE *file; + if(!filesystem||!data||!length||!valid_name(name,0))return -1; + file=find_file(filesystem,name,0); + if(!file)return -1; + *data=file->Data;*length=file->Length; + return 0; +} + +int bob64_fs_read_at(const BOB64_FILESYSTEM *filesystem,const char *name, + u64 offset,void *buffer,usize capacity,usize *read_count) { + BOB64_FS_FILE *file; + usize count; + if(!filesystem||!read_count||(!buffer&&capacity)||!valid_name(name,0))return -1; + file=find_file(filesystem,name,0); + if(!file)return -1; + if(offset>=file->Length){*read_count=0;return 0;} + count=file->Length-(usize)offset; + if(count>capacity)count=capacity; + for(usize i=0;iData[(usize)offset+i]; + *read_count=count; + return 0; +} + +int bob64_fs_write_at(BOB64_FILESYSTEM *filesystem,const char *name, + u64 offset,const void *buffer,usize length) { + BOB64_FS_FILE *file; + usize end,new_length; + char *replacement; + if(!filesystem||!filesystem->Heap||(!buffer&&length)|| + offset>(u64)(~(usize)0)||length>(usize)(~(usize)0)-(usize)offset|| + !valid_name(name,0))return -1; + end=(usize)offset+length; + file=find_file(filesystem,name,0); + if(!file) { + if(offset)return -1; + return bob64_fs_write(filesystem,name,buffer,length); + } + new_length=file->Length>end?file->Length:end; + if(new_length==~(usize)0)return -1; + replacement=(char *)bob64_heap_alloc(filesystem->Heap,new_length+1); + if(!replacement)return -1; + for(usize i=0;iLength?file->Data[i]:0; + for(usize i=0;iBytesUsed-=file->Length; + filesystem->BytesUsed+=new_length; + bob64_heap_free(filesystem->Heap,file->Data); + file->Data=replacement;file->Length=new_length; + return 0; +} + +int bob64_fs_delete(BOB64_FILESYSTEM *filesystem,const char *name) { + BOB64_FS_FILE *previous=0,*file; + if(!filesystem||!filesystem->Heap||!valid_name(name,0))return -1; + file=find_file(filesystem,name,&previous); + if(!file)return -1; + if(previous)previous->Next=file->Next; + else filesystem->First=file->Next; + filesystem->BytesUsed-=file->Length;filesystem->FileCount--; + bob64_heap_free(filesystem->Heap,file->Name); + bob64_heap_free(filesystem->Heap,file->Data); + bob64_heap_free(filesystem->Heap,file); + return 0; +} + +void bob64_fs_clear(BOB64_FILESYSTEM *filesystem) { + if(!filesystem)return; + while(filesystem->First) { + char name[BOB64_FS_NAME_CAPACITY]; + usize length=string_length(filesystem->First->Name); + for(usize i=0;iFirst->Name[i]; + name[length]=0; + if(bob64_fs_delete(filesystem,name))return; + } +} + +usize bob64_fs_list(const BOB64_FILESYSTEM *filesystem, + BOB64_FS_LIST_CALLBACK callback,void *context) { + usize count=0; + if(!filesystem)return 0; + for(BOB64_FS_FILE *file=filesystem->First;file;file=file->Next) { + count++; + if(callback&&callback(context,file->Name,file->Length))break; + } + return count; +} diff --git a/bob64/filesystem.h b/bob64/filesystem.h new file mode 100644 index 0000000..273279d --- /dev/null +++ b/bob64/filesystem.h @@ -0,0 +1,40 @@ +#ifndef BOB64_FILESYSTEM_H +#define BOB64_FILESYSTEM_H + +#include "heap.h" +#include "memory.h" + +#define BOB64_FS_NAME_CAPACITY 64 + +typedef struct BOB64_FS_FILE BOB64_FS_FILE; +struct BOB64_FS_FILE { + BOB64_FS_FILE *Next; + char *Name; + char *Data; + usize Length; +}; + +typedef struct { + BOB64_FS_FILE *First; + BOB64_HEAP *Heap; + usize FileCount,BytesUsed; +} BOB64_FILESYSTEM; + +typedef int (*BOB64_FS_LIST_CALLBACK)(void *context,const char *name,usize length); + +int bob64_fs_init(BOB64_FILESYSTEM *filesystem,BOB64_HEAP *heap); +/* File contents are length-delimited and may contain any byte value. */ +int bob64_fs_write(BOB64_FILESYSTEM *filesystem,const char *name, + const void *data,usize length); +int bob64_fs_read(const BOB64_FILESYSTEM *filesystem,const char *name, + const char **data,usize *length); +int bob64_fs_read_at(const BOB64_FILESYSTEM *filesystem,const char *name, + u64 offset,void *buffer,usize capacity,usize *read_count); +int bob64_fs_write_at(BOB64_FILESYSTEM *filesystem,const char *name, + u64 offset,const void *buffer,usize length); +int bob64_fs_delete(BOB64_FILESYSTEM *filesystem,const char *name); +void bob64_fs_clear(BOB64_FILESYSTEM *filesystem); +usize bob64_fs_list(const BOB64_FILESYSTEM *filesystem, + BOB64_FS_LIST_CALLBACK callback,void *context); + +#endif diff --git a/bob64/font.h b/bob64/font.h new file mode 100644 index 0000000..dca39b7 --- /dev/null +++ b/bob64/font.h @@ -0,0 +1,31 @@ +#ifndef BOB64_FONT_H +#define BOB64_FONT_H + +/* Compact 5x7 font: blank, A-Z, 0-9, ?, !, -, period, colon, equals, >. */ +static const u8 bob64_font5x7[44][5]={ + {0,0,0,0,0}, + {0x7e,0x11,0x11,0x11,0x7e},{0x7f,0x49,0x49,0x49,0x36}, + {0x3e,0x41,0x41,0x41,0x22},{0x7f,0x41,0x41,0x22,0x1c}, + {0x7f,0x49,0x49,0x49,0x41},{0x7f,0x09,0x09,0x09,0x01}, + {0x3e,0x41,0x49,0x49,0x7a},{0x7f,0x08,0x08,0x08,0x7f}, + {0x00,0x41,0x7f,0x41,0x00},{0x20,0x40,0x41,0x3f,0x01}, + {0x7f,0x08,0x14,0x22,0x41},{0x7f,0x40,0x40,0x40,0x40}, + {0x7f,0x02,0x0c,0x02,0x7f},{0x7f,0x04,0x08,0x10,0x7f}, + {0x3e,0x41,0x41,0x41,0x3e},{0x7f,0x09,0x09,0x09,0x06}, + {0x3e,0x41,0x51,0x21,0x5e},{0x7f,0x09,0x19,0x29,0x46}, + {0x46,0x49,0x49,0x49,0x31},{0x01,0x01,0x7f,0x01,0x01}, + {0x3f,0x40,0x40,0x40,0x3f},{0x1f,0x20,0x40,0x20,0x1f}, + {0x3f,0x40,0x38,0x40,0x3f},{0x63,0x14,0x08,0x14,0x63}, + {0x07,0x08,0x70,0x08,0x07},{0x61,0x51,0x49,0x45,0x43}, + {0x3e,0x51,0x49,0x45,0x3e},{0x00,0x42,0x7f,0x40,0x00}, + {0x62,0x51,0x49,0x49,0x46},{0x22,0x41,0x49,0x49,0x36}, + {0x18,0x14,0x12,0x7f,0x10},{0x2f,0x49,0x49,0x49,0x31}, + {0x3e,0x49,0x49,0x49,0x32},{0x01,0x71,0x09,0x05,0x03}, + {0x36,0x49,0x49,0x49,0x36},{0x26,0x49,0x49,0x49,0x3e}, + {0x02,0x01,0x51,0x09,0x06},{0x00,0x00,0x5f,0x00,0x00}, + {0x08,0x08,0x08,0x08,0x08},{0x00,0x60,0x60,0x00,0x00}, + {0x00,0x36,0x36,0x00,0x00},{0x14,0x14,0x14,0x14,0x14}, + {0x41,0x22,0x14,0x08,0x00} +}; + +#endif diff --git a/bob64/gfx.h b/bob64/gfx.h new file mode 100644 index 0000000..b6706bf --- /dev/null +++ b/bob64/gfx.h @@ -0,0 +1,82 @@ +#ifndef BOB64_GFX_H +#define BOB64_GFX_H + +#include "app.h" +#include "font.h" + +typedef struct { + u32 *Pixels; + u32 Width,Height; + usize Capacity; +} BOB64_GFX; + +static inline int bob64_gfx_init(BOB64_GFX *graphics,u32 *pixels,usize capacity) { + u32 width,height; + if(!graphics||!pixels||bob64_app_get_display(&width,&height)||!width||!height|| + (u64)width*height>capacity||width>1024||height>768)return -1; + graphics->Pixels=pixels;graphics->Width=width;graphics->Height=height; + graphics->Capacity=capacity; + return 0; +} + +static inline void bob64_gfx_pixel(BOB64_GFX *graphics,s32 x,s32 y,u32 color) { + if(graphics&&x>=0&&y>=0&&(u32)xWidth&&(u32)yHeight) + graphics->Pixels[(usize)(u32)y*graphics->Width+(u32)x]=color&0x00ffffffu; +} + +static inline void bob64_gfx_fill_rect(BOB64_GFX *graphics,s32 x,s32 y, + u32 width,u32 height,u32 color) { + if(!graphics)return; + for(u32 row=0;rowx0?x1-x0:x0-x1,sx=x0y0?y0-y1:y1-y0,sy=y0=dy){error+=dy;x0+=sx;} + if(twice<=dx){error+=dx;y0+=sy;} + } +} + +static inline u32 bob64_gfx_glyph(u8 value) { + if(value>='a'&&value<='z')value=(u8)(value-'a'+'A'); + if(value==' ')return 0; + if(value>='A'&&value<='Z')return 1u+(u32)(value-'A'); + if(value>='0'&&value<='9')return 27u+(u32)(value-'0'); + if(value=='?')return 37; + if(value=='!')return 38; + if(value=='-')return 39; + if(value=='.')return 40; + if(value==':')return 41; + if(value=='=')return 42; + if(value=='>')return 43; + return 37; +} + +static inline void bob64_gfx_text(BOB64_GFX *graphics,s32 x,s32 y, + const char *text,u32 color,u32 scale) { + if(!graphics||!text||!scale)return; + while(*text) { + u32 glyph=bob64_gfx_glyph((u8)*text++); + for(u32 column=0;column<5;column++)for(u32 row=0;row<7;row++) + if(bob64_font5x7[glyph][column]&(1u<Pixels)return -1; + return bob64_app_present(graphics->Pixels,graphics->Width,graphics->Height)== + (s64)((u64)graphics->Width*graphics->Height)?0:-1; +} + +#endif diff --git a/bob64/handoff.S b/bob64/handoff.S new file mode 100644 index 0000000..1b416d6 --- /dev/null +++ b/bob64/handoff.S @@ -0,0 +1,48 @@ +.intel_syntax noprefix +.text + +.globl bob64_enter_kernel +bob64_enter_kernel: + /* Microsoft x64 ABI: fifth argument is above the 32-byte shadow area. */ + mov r10,rcx + mov r11,rdx + mov r13,QWORD PTR [rsp+40] + cli + lgdt [r8] + push 0x08 + lea rax,[rip+.Lbob64_reload_cs] + push rax + retfq +.Lbob64_reload_cs: + mov ax,0x28 + ltr ax + lidt [r9] + mov ax,0x10 + mov ds,ax + mov es,ax + mov ss,ax + cmp BYTE PTR [r13+81],0 + je .Lbob64_nx_ready + mov ecx,0xc0000080 + rdmsr + or eax,0x800 + wrmsr +.Lbob64_nx_ready: + mov rax,cr0 + or rax,0x10000 + and rax,0xfffffffffffffffb + or rax,0x2 + mov cr0,rax + mov rax,cr4 + or rax,0x600 + mov cr4,rax + mov cr3,r10 + mov rsp,r11 + and rsp,-16 + sub rsp,32 + mov rcx,r13 + call bob64_kernel_main +.Lbob64_unexpected_return: + cli + hlt + jmp .Lbob64_unexpected_return diff --git a/bob64/heap.c b/bob64/heap.c new file mode 100644 index 0000000..9ea4a1c --- /dev/null +++ b/bob64/heap.c @@ -0,0 +1,128 @@ +#include "heap.h" + +#define BOB64_HEAP_BLOCK_MAGIC 0xB064B10Cu +#define BOB64_HEAP_ALIGNMENT 16u +#define BOB64_HEAP_MINIMUM_REGION 4096u + +static int align_size(usize value,usize *aligned) { + if(value>~(usize)0-(BOB64_HEAP_ALIGNMENT-1))return 0; + *aligned=(value+(BOB64_HEAP_ALIGNMENT-1))&~(usize)(BOB64_HEAP_ALIGNMENT-1); + return 1; +} + +static BOB64_HEAP_BLOCK *block_at(void *address,usize bytes) { + BOB64_HEAP_BLOCK *block; + if(bytesSize=bytes-sizeof(*block); + block->Previous=0;block->Next=0;block->Magic=BOB64_HEAP_BLOCK_MAGIC; + block->Free=1;block->Reserved[0]=block->Reserved[1]=block->Reserved[2]=0; + return block; +} + +int bob64_heap_init(BOB64_HEAP *heap,usize maximum_bytes, + BOB64_HEAP_GROW grow,void *context) { + if(!heap||!grow||maximum_bytesFirst=0;heap->Last=0;heap->Grow=grow;heap->Context=context; + heap->Base=0;heap->MappedBytes=0;heap->MaximumBytes=maximum_bytes; + return 0; +} + +static BOB64_HEAP_BLOCK *find_block(BOB64_HEAP *heap,usize size) { + for(BOB64_HEAP_BLOCK *block=heap->First;block;block=block->Next) + if(block->Magic==BOB64_HEAP_BLOCK_MAGIC&&block->Free&&block->Size>=size) + return block; + return 0; +} + +static int grow_heap(BOB64_HEAP *heap) { + void *region=0; + usize bytes=0; + if(heap->MappedBytes>=heap->MaximumBytes||!heap->Grow(heap->Context,®ion,&bytes)|| + !region||!bytes||(bytes&(BOB64_HEAP_ALIGNMENT-1))|| + bytes>heap->MaximumBytes-heap->MappedBytes|| + ((uintptr_t)region&(BOB64_HEAP_ALIGNMENT-1))|| + heap->MappedBytes>~(uintptr_t)0-(uintptr_t)region)return -1; + if(heap->Base&&(u8 *)region!=(u8 *)heap->Base+heap->MappedBytes)return -1; + BOB64_HEAP_BLOCK *block=block_at(region,bytes); + if(!block)return -1; + if(!heap->Base)heap->Base=region; + heap->MappedBytes+=bytes; + if(heap->Last&&heap->Last->Free) { + heap->Last->Size+=sizeof(*block)+block->Size; + heap->Last->Next=0; + } else { + block->Previous=heap->Last; + if(heap->Last)heap->Last->Next=block; + else heap->First=block; + heap->Last=block; + } + return 0; +} + +void *bob64_heap_alloc(BOB64_HEAP *heap,usize size) { + usize aligned; + if(!heap||!heap->Grow||!size||!align_size(size,&aligned))return 0; + BOB64_HEAP_BLOCK *block; + while(!(block=find_block(heap,aligned)))if(grow_heap(heap))return 0; + if(block->Size>=sizeof(*block)+BOB64_HEAP_ALIGNMENT&& + aligned<=block->Size-sizeof(*block)-BOB64_HEAP_ALIGNMENT) { + BOB64_HEAP_BLOCK *remainder=(BOB64_HEAP_BLOCK *)((u8 *)(block+1)+aligned); + remainder->Size=block->Size-aligned-sizeof(*remainder); + remainder->Previous=block;remainder->Next=block->Next; + remainder->Magic=BOB64_HEAP_BLOCK_MAGIC;remainder->Free=1; + remainder->Reserved[0]=remainder->Reserved[1]=remainder->Reserved[2]=0; + if(remainder->Next)remainder->Next->Previous=remainder; + else heap->Last=remainder; + block->Next=remainder;block->Size=aligned; + } + block->Free=0; + return block+1; +} + +void *bob64_heap_calloc(BOB64_HEAP *heap,usize count,usize size) { + usize bytes; + if(!count||!size||size>~(usize)0/count)return 0; + bytes=count*size; + void *pointer=bob64_heap_alloc(heap,bytes); + if(pointer) { + u8 *destination=(u8 *)pointer; + for(usize i=0;iBase||(address&(BOB64_HEAP_ALIGNMENT-1)))return -1; + base=(uintptr_t)heap->Base; + if(heap->MappedBytes>~(uintptr_t)0-base)return -1; + end=base+heap->MappedBytes; + if(address=end)return -1; + block=(BOB64_HEAP_BLOCK *)pointer-1; + if((uintptr_t)blockend|| + block->Magic!=BOB64_HEAP_BLOCK_MAGIC||block->Free|| + block->Size>(usize)(end-(uintptr_t)(block+1)))return -1; + block->Free=1; + if(block->Next&&block->Next->Magic==BOB64_HEAP_BLOCK_MAGIC&&block->Next->Free) { + BOB64_HEAP_BLOCK *next=block->Next; + block->Size+=sizeof(*next)+next->Size;block->Next=next->Next; + if(block->Next)block->Next->Previous=block; + else heap->Last=block; + next->Magic=0; + } + if(block->Previous&&block->Previous->Magic==BOB64_HEAP_BLOCK_MAGIC&&block->Previous->Free) { + BOB64_HEAP_BLOCK *previous=block->Previous; + previous->Size+=sizeof(*block)+block->Size;previous->Next=block->Next; + if(previous->Next)previous->Next->Previous=previous; + else heap->Last=previous; + block->Magic=0; + } + return 0; +} + +usize bob64_heap_mapped_bytes(const BOB64_HEAP *heap) { + return heap?heap->MappedBytes:0; +} diff --git a/bob64/heap.h b/bob64/heap.h new file mode 100644 index 0000000..579126d --- /dev/null +++ b/bob64/heap.h @@ -0,0 +1,34 @@ +#ifndef BOB64_HEAP_H +#define BOB64_HEAP_H + +#include "types.h" + +typedef int (*BOB64_HEAP_GROW)(void *context,void **region,usize *region_size); + +typedef struct BOB64_HEAP_BLOCK BOB64_HEAP_BLOCK; +struct BOB64_HEAP_BLOCK { + usize Size; + BOB64_HEAP_BLOCK *Previous,*Next; + u32 Magic; + u8 Free; + u8 Reserved[3]; +}; + +typedef struct { + BOB64_HEAP_BLOCK *First,*Last; + BOB64_HEAP_GROW Grow; + void *Context; + void *Base; + usize MappedBytes,MaximumBytes; +} BOB64_HEAP; + +int bob64_heap_init(BOB64_HEAP *heap,usize maximum_bytes, + BOB64_HEAP_GROW grow,void *context); +void *bob64_heap_alloc(BOB64_HEAP *heap,usize size); +void *bob64_heap_calloc(BOB64_HEAP *heap,usize count,usize size); +int bob64_heap_free(BOB64_HEAP *heap,void *pointer); +usize bob64_heap_mapped_bytes(const BOB64_HEAP *heap); + +_Static_assert(sizeof(BOB64_HEAP_BLOCK)==32,"bob64 heap block ABI alignment"); + +#endif diff --git a/bob64/interrupts.S b/bob64/interrupts.S new file mode 100644 index 0000000..d0c7399 --- /dev/null +++ b/bob64/interrupts.S @@ -0,0 +1,420 @@ +.intel_syntax noprefix +.text + +.macro BOB64_EXCEPTION_NO_ERROR number + .globl bob64_exception_\number +bob64_exception_\number: + push 0 + push \number + jmp bob64_exception_common +.endm + +.macro BOB64_EXCEPTION_ERROR number + .globl bob64_exception_\number +bob64_exception_\number: + push \number + jmp bob64_exception_common +.endm + +BOB64_EXCEPTION_NO_ERROR 0 +BOB64_EXCEPTION_NO_ERROR 1 +BOB64_EXCEPTION_NO_ERROR 2 +BOB64_EXCEPTION_NO_ERROR 3 +BOB64_EXCEPTION_NO_ERROR 4 +BOB64_EXCEPTION_NO_ERROR 5 +BOB64_EXCEPTION_NO_ERROR 6 +BOB64_EXCEPTION_NO_ERROR 7 +BOB64_EXCEPTION_ERROR 8 +BOB64_EXCEPTION_NO_ERROR 9 +BOB64_EXCEPTION_ERROR 10 +BOB64_EXCEPTION_ERROR 11 +BOB64_EXCEPTION_ERROR 12 +BOB64_EXCEPTION_ERROR 13 +BOB64_EXCEPTION_ERROR 14 +BOB64_EXCEPTION_NO_ERROR 15 +BOB64_EXCEPTION_NO_ERROR 16 +BOB64_EXCEPTION_ERROR 17 +BOB64_EXCEPTION_NO_ERROR 18 +BOB64_EXCEPTION_NO_ERROR 19 +BOB64_EXCEPTION_NO_ERROR 20 +BOB64_EXCEPTION_ERROR 21 +BOB64_EXCEPTION_NO_ERROR 22 +BOB64_EXCEPTION_NO_ERROR 23 +BOB64_EXCEPTION_NO_ERROR 24 +BOB64_EXCEPTION_NO_ERROR 25 +BOB64_EXCEPTION_NO_ERROR 26 +BOB64_EXCEPTION_NO_ERROR 27 +BOB64_EXCEPTION_NO_ERROR 28 +BOB64_EXCEPTION_ERROR 29 +BOB64_EXCEPTION_ERROR 30 +BOB64_EXCEPTION_NO_ERROR 31 + +.globl bob64_irq0_entry +bob64_irq0_entry: + push 0 + push 32 + push rax + push rbx + push rcx + push rdx + push rbp + push rsi + push rdi + push r8 + push r9 + push r10 + push r11 + push r12 + push r13 + push r14 + push r15 + mov r12,rsp + cld + and rsp,-16 + sub rsp,32 + mov rcx,r12 + call bob64_irq_dispatch + mov rsp,r12 + pop r15 + pop r14 + pop r13 + pop r12 + pop r11 + pop r10 + pop r9 + pop r8 + pop rdi + pop rsi + pop rbp + pop rdx + pop rcx + pop rbx + pop rax + add rsp,16 + iretq + +.globl bob64_irq1_entry +bob64_irq1_entry: + push 0 + push 33 + push rax + push rbx + push rcx + push rdx + push rbp + push rsi + push rdi + push r8 + push r9 + push r10 + push r11 + push r12 + push r13 + push r14 + push r15 + mov r12,rsp + cld + and rsp,-16 + sub rsp,32 + mov rcx,r12 + call bob64_irq_dispatch + mov rsp,r12 + pop r15 + pop r14 + pop r13 + pop r12 + pop r11 + pop r10 + pop r9 + pop r8 + pop rdi + pop rsi + pop rbp + pop rdx + pop rcx + pop rbx + pop rax + add rsp,16 + iretq + +.globl bob64_irq12_entry +bob64_irq12_entry: + push 0 + push 44 + push rax + push rbx + push rcx + push rdx + push rbp + push rsi + push rdi + push r8 + push r9 + push r10 + push r11 + push r12 + push r13 + push r14 + push r15 + mov r12,rsp + cld + and rsp,-16 + sub rsp,32 + mov rcx,r12 + call bob64_irq_dispatch + mov rsp,r12 + pop r15 + pop r14 + pop r13 + pop r12 + pop r11 + pop r10 + pop r9 + pop r8 + pop rdi + pop rsi + pop rbp + pop rdx + pop rcx + pop rbx + pop rax + add rsp,16 + iretq + +.globl bob64_unhandled_interrupt +bob64_unhandled_interrupt: + push 0 + push 255 + jmp bob64_exception_common + +.globl bob64_exception_common +bob64_exception_common: + push rax + push rbx + push rcx + push rdx + push rbp + push rsi + push rdi + push r8 + push r9 + push r10 + push r11 + push r12 + push r13 + push r14 + push r15 + mov r12,rsp + cld + and rsp,-16 + sub rsp,32 + mov rcx,r12 + call bob64_exception_dispatch + test rax,rax + jnz .Lbob64_user_abort_return + mov rsp,r12 + pop r15 + pop r14 + pop r13 + pop r12 + pop r11 + pop r10 + pop r9 + pop r8 + pop rdi + pop rsi + pop rbp + pop rdx + pop rcx + pop rbx + pop rax + add rsp,16 + iretq + +.globl bob64_enter_user +bob64_enter_user: + /* Preserve the kernel ABI's nonvolatile registers across the privilege change. */ + push rbx + push rbp + push rdi + push rsi + push r12 + push r13 + push r14 + push r15 + sub rsp,168 + movdqa XMMWORD PTR [rsp],xmm6 + movdqa XMMWORD PTR [rsp+16],xmm7 + movdqa XMMWORD PTR [rsp+32],xmm8 + movdqa XMMWORD PTR [rsp+48],xmm9 + movdqa XMMWORD PTR [rsp+64],xmm10 + movdqa XMMWORD PTR [rsp+80],xmm11 + movdqa XMMWORD PTR [rsp+96],xmm12 + movdqa XMMWORD PTR [rsp+112],xmm13 + movdqa XMMWORD PTR [rsp+128],xmm14 + movdqa XMMWORD PTR [rsp+144],xmm15 + mov r10,QWORD PTR [rip+bob64_user_depth] + cmp r10,8 + jae .Lbob64_user_depth_full + lea r11,[rip+bob64_user_return_frames] + lea r12,[r10+r10*4] + shl r12,3 + add r11,r12 + mov QWORD PTR [r11],rsp + mov QWORD PTR [r11+8],0 + mov rax,QWORD PTR [rip+bob64_user_return_value] + mov QWORD PTR [r11+16],rax + pushfq + pop rax + and rax,0x200 + mov QWORD PTR [r11+24],rax + mov rax,QWORD PTR [rip+bob64_user_active] + mov QWORD PTR [r11+32],rax + inc r10 + mov QWORD PTR [rip+bob64_user_depth],r10 + mov QWORD PTR [rip+bob64_user_return_value],0 + mov QWORD PTR [rip+bob64_user_active],1 + mov rax,rcx + mov rcx,rdx + /* User mode accepts IRQs; bob64_enter_user restores the caller's IF on return. */ + push 0x1b + push r8 + push 0x202 + push 0x23 + push rax + iretq +.Lbob64_user_depth_full: + mov rax,-1 + movdqa xmm6,XMMWORD PTR [rsp] + movdqa xmm7,XMMWORD PTR [rsp+16] + movdqa xmm8,XMMWORD PTR [rsp+32] + movdqa xmm9,XMMWORD PTR [rsp+48] + movdqa xmm10,XMMWORD PTR [rsp+64] + movdqa xmm11,XMMWORD PTR [rsp+80] + movdqa xmm12,XMMWORD PTR [rsp+96] + movdqa xmm13,XMMWORD PTR [rsp+112] + movdqa xmm14,XMMWORD PTR [rsp+128] + movdqa xmm15,XMMWORD PTR [rsp+144] + add rsp,168 + pop r15 + pop r14 + pop r13 + pop r12 + pop rsi + pop rdi + pop rbp + pop rbx + ret + +.globl bob64_syscall_entry +bob64_syscall_entry: + push 0 + push 128 + push rax + push rbx + push rcx + push rdx + push rbp + push rsi + push rdi + push r8 + push r9 + push r10 + push r11 + push r12 + push r13 + push r14 + push r15 + mov r12,rsp + cld + and rsp,-16 + sub rsp,32 + mov rcx,r12 + call bob64_syscall_dispatch + test rax,rax + jnz .Lbob64_user_abort_return + mov rsp,r12 + pop r15 + pop r14 + pop r13 + pop r12 + pop r11 + pop r10 + pop r9 + pop r8 + pop rdi + pop rsi + pop rbp + pop rdx + pop rcx + pop rbx + pop rax + add rsp,16 + iretq +.Lbob64_user_abort_return: + mov r10,QWORD PTR [rip+bob64_user_depth] + test r10,r10 + jz .Lbob64_user_return_corrupt + dec r10 + lea r11,[rip+bob64_user_return_frames] + lea r12,[r10+r10*4] + shl r12,3 + add r11,r12 + mov rsp,QWORD PTR [r11] + mov rax,QWORD PTR [r11+8] + mov r9,QWORD PTR [r11+24] + mov r8,QWORD PTR [r11+32] + mov rdx,QWORD PTR [r11+16] + movdqa xmm6,XMMWORD PTR [rsp] + movdqa xmm7,XMMWORD PTR [rsp+16] + movdqa xmm8,XMMWORD PTR [rsp+32] + movdqa xmm9,XMMWORD PTR [rsp+48] + movdqa xmm10,XMMWORD PTR [rsp+64] + movdqa xmm11,XMMWORD PTR [rsp+80] + movdqa xmm12,XMMWORD PTR [rsp+96] + movdqa xmm13,XMMWORD PTR [rsp+112] + movdqa xmm14,XMMWORD PTR [rsp+128] + movdqa xmm15,XMMWORD PTR [rsp+144] + add rsp,168 + pop r15 + pop r14 + pop r13 + pop r12 + pop rsi + pop rdi + pop rbp + pop rbx + mov QWORD PTR [rip+bob64_user_depth],r10 + mov QWORD PTR [rip+bob64_user_active],r8 + mov QWORD PTR [rip+bob64_user_return_value],rdx + test r9,r9 + jz .Lbob64_return_without_if + sti +.Lbob64_return_without_if: + ret +.Lbob64_user_return_corrupt: + cli +.Lbob64_user_return_halt: + hlt + jmp .Lbob64_user_return_halt + +#ifdef __MINGW32__ +.section .rdata,"dr" +#else +.section .rodata +#endif +.align 8 +.globl bob64_exception_stub_table +bob64_exception_stub_table: + .quad bob64_exception_0,bob64_exception_1,bob64_exception_2,bob64_exception_3 + .quad bob64_exception_4,bob64_exception_5,bob64_exception_6,bob64_exception_7 + .quad bob64_exception_8,bob64_exception_9,bob64_exception_10,bob64_exception_11 + .quad bob64_exception_12,bob64_exception_13,bob64_exception_14,bob64_exception_15 + .quad bob64_exception_16,bob64_exception_17,bob64_exception_18,bob64_exception_19 + .quad bob64_exception_20,bob64_exception_21,bob64_exception_22,bob64_exception_23 + .quad bob64_exception_24,bob64_exception_25,bob64_exception_26,bob64_exception_27 + .quad bob64_exception_28,bob64_exception_29,bob64_exception_30,bob64_exception_31 + +#ifndef __MINGW32__ +.section .note.GNU-stack,"",@progbits +#endif diff --git a/bob64/interrupts.c b/bob64/interrupts.c new file mode 100644 index 0000000..4a02086 --- /dev/null +++ b/bob64/interrupts.c @@ -0,0 +1,259 @@ +#include "interrupts.h" +#include "console.h" +#include "syscall.h" +#include "keyboard.h" +#include "mouse.h" + +#define BOB64_COM1 0x3f8u +static int serial_available; +static u8 pic_ready; +static u8 pic_master_mask=0xff,pic_slave_mask=0xff; +static volatile u64 timer_tick_count; +volatile u64 bob64_user_exception_vector=~(u64)0; +volatile u64 bob64_user_exception_error=~(u64)0; +volatile u64 bob64_user_exception_rip=~(u64)0; +volatile u64 bob64_user_expected_exception_vector=~(u64)0; +volatile u64 bob64_user_expected_exception_error_mask; +volatile u64 bob64_user_expected_exception_error_value; + +static void port_out8(u16 port,u8 value) { + __asm__ volatile("outb %0, %1"::"a"(value),"Nd"(port)); +} + +static u8 port_in8(u16 port) { + u8 value; + __asm__ volatile("inb %1, %0":"=a"(value):"Nd"(port)); + return value; +} + +static void serial_init(void) { + port_out8(BOB64_COM1+1,0x00); + port_out8(BOB64_COM1+3,0x80); + port_out8(BOB64_COM1+0,0x01); + port_out8(BOB64_COM1+1,0x00); + port_out8(BOB64_COM1+3,0x03); + port_out8(BOB64_COM1+2,0xc7); + port_out8(BOB64_COM1+4,0x0b); + serial_available=port_in8(BOB64_COM1+5)!=0xff; +} + +static void serial_char(char value) { + if(!serial_available)return; + for(u32 timeout=0;timeout<100000;timeout++) { + if(port_in8(BOB64_COM1+5)&0x20) { + port_out8(BOB64_COM1,(u8)value); + return; + } + } +} + +static void serial_text(const char *text) { + while(*text)serial_char(*text++); +} + +static void diagnostic_text(const char *text) { + serial_text(text); + bob64_framebuffer_write(text); +} + +static void serial_hex64(u64 value) { + static const char digits[]="0123456789abcdef"; + for(int shift=60;shift>=0;shift-=4)serial_char(digits[(value>>shift)&15]); +} + +void bob64_early_console_init(void) { + serial_init(); +} + +void bob64_early_console_write(const char *text) { + if(text)serial_text(text); +} + +void bob64_early_console_hex64(u64 value) { + serial_hex64(value); +} + +int bob64_early_console_try_read(void) { + if(!serial_available||(port_in8(BOB64_COM1+5)&1)==0)return -1; + return port_in8(BOB64_COM1); +} + +static void diagnostic_register(const char *name,u64 value) { + static const char digits[]="0123456789abcdef"; + char line[17]; + diagnostic_text(name);diagnostic_text("=0x"); + for(int i=0;i<16;i++)line[i]=digits[(value>>(60-i*4))&15]; + line[16]=0; + diagnostic_text(line);diagnostic_text("\r\n"); +} + +int bob64_interrupts_build_idt(BOB64_IDT_GATE entries[BOB64_IDT_ENTRIES],u16 selector) { + if(!entries||bob64_idt_init(entries,(u64)(uintptr_t)bob64_unhandled_interrupt, + selector,0))return -1; + for(usize vector=0;vector<32;vector++) { + u64 handler=(u64)(uintptr_t)bob64_exception_stub_table[vector]; + if(bob64_idt_set_gate(&entries[vector],handler,selector,0,0, + BOB64_IDT_INTERRUPT_GATE))return -1; + } + if(bob64_idt_set_gate(&entries[0x20],(u64)(uintptr_t)bob64_irq0_entry, + selector,0,0,BOB64_IDT_INTERRUPT_GATE))return -1; + if(bob64_idt_set_gate(&entries[0x80],(u64)(uintptr_t)bob64_syscall_entry, + selector,0,3,BOB64_IDT_INTERRUPT_GATE))return -1; + if(bob64_idt_set_gate(&entries[0x21],(u64)(uintptr_t)bob64_irq1_entry, + selector,0,0,BOB64_IDT_INTERRUPT_GATE))return -1; + if(bob64_idt_set_gate(&entries[0x2c],(u64)(uintptr_t)bob64_irq12_entry, + selector,0,0,BOB64_IDT_INTERRUPT_GATE))return -1; + return 0; +} + +static int pic_initialize(void) { + if(pic_ready)return 0; + pic_master_mask=pic_slave_mask=0xff; + port_out8(0x21,pic_master_mask);port_out8(0xa1,pic_slave_mask); + port_out8(0x20,0x11);port_out8(0x80,0); + port_out8(0xa0,0x11);port_out8(0x80,0); + port_out8(0x21,0x20);port_out8(0x80,0); + port_out8(0xa1,0x28);port_out8(0x80,0); + port_out8(0x21,0x04);port_out8(0x80,0); + port_out8(0xa1,0x02);port_out8(0x80,0); + port_out8(0x21,0x01);port_out8(0x80,0); + port_out8(0xa1,0x01);port_out8(0x80,0); + pic_ready=1; + return 0; +} + +static void pic_unmask(u8 irq) { + if(irq<8)pic_master_mask=(u8)(pic_master_mask&~(1u<>8)); + pic_unmask(0); + __asm__ volatile("sti":::"memory"); + return 0; +} + +static int wait_keyboard_controller(u8 mask,u8 expected) { + for(u32 i=0;i<100000;i++) { + u8 status=port_in8(0x64); + if(status==0xff)return -1; + if((status&mask)==expected)return 0; + } + return -1; +} + +int bob64_interrupts_enable_keyboard(void) { + u8 command; + if(pic_initialize())return -1; + for(u32 i=0;i<32;i++) { + u8 status=port_in8(0x64); + if(status==0xff)return -1; + if(!(status&1))break; + if(status&0x20)return -1; + (void)port_in8(0x60); + } + if(wait_keyboard_controller(0,0))return -1; + port_out8(0x64,0x20); + if(wait_keyboard_controller(1,1))return -1; + if(port_in8(0x64)&0x20)return -1; + command=port_in8(0x60); + command=(u8)((command|1)&~0x10u); /* enable keyboard IRQ and clock */ + if(wait_keyboard_controller(2,0))return -1; + port_out8(0x64,0x60); + if(wait_keyboard_controller(2,0))return -1; + port_out8(0x60,command); + bob64_keyboard_reset(); + bob64_keyboard_irq_set_active(1); + pic_unmask(1); + __asm__ volatile("sti":::"memory"); + return 0; +} + +int bob64_interrupts_enable_mouse(void) { + u64 saved_flags; + u8 command; + __asm__ volatile("pushfq; pop %0; cli":"=r"(saved_flags)::"memory"); + for(u32 i=0;i<32;i++) { + u8 status=port_in8(0x64); + if(status==0xff)goto failed; + if(!(status&1))break; + if(!(status&0x20))goto failed; + (void)port_in8(0x60); + } + if(wait_keyboard_controller(0,0))goto failed; + port_out8(0x64,0x20); + if(wait_keyboard_controller(1,1)||(port_in8(0x64)&0x20))goto failed; + command=port_in8(0x60); + command=(u8)((command|2)&~0x20u); /* enable mouse IRQ and clock */ + if(wait_keyboard_controller(2,0))goto failed; + port_out8(0x64,0x60); + if(wait_keyboard_controller(2,0))goto failed; + port_out8(0x60,command); + bob64_mouse_irq_set_active(1); + pic_unmask(12); + __asm__ volatile("sti":::"memory"); + return 0; +failed: + if(saved_flags&0x200)__asm__ volatile("sti":::"memory"); + return -1; +} + +void BOB64_MS_ABI bob64_irq_dispatch(const BOB64_INTERRUPT_FRAME *frame) { + if(frame&&frame->Vector==0x20) bob64_timer_irq_tick(); + else if(frame&&frame->Vector==0x21) (void)bob64_keyboard_irq_service(); + else if(frame&&frame->Vector==0x2c) { + (void)bob64_mouse_irq_service(); + port_out8(0xa0,0x20); + } + /* IRQ1 is on the master; IRQ12 also needs the slave and cascade EOIs. */ + port_out8(0x20,0x20); +} + +u64 BOB64_MS_ABI bob64_exception_dispatch(const BOB64_INTERRUPT_FRAME *frame) { + __asm__ volatile("cli"); + bob64_early_console_init(); + int from_user=frame&&(frame->CS&3)==3&&bob64_user_active; + int expected_user_fault=from_user&& + frame->Vector==bob64_user_expected_exception_vector&& + (frame->ErrorCode&bob64_user_expected_exception_error_mask)== + bob64_user_expected_exception_error_value; + if(!expected_user_fault) + diagnostic_text(from_user?"bob64 user exception\r\n":"bob64 exception\r\n"); + if(frame&&!expected_user_fault) { + diagnostic_register("vector",frame->Vector); + diagnostic_register("error",frame->ErrorCode); + diagnostic_register("rip",frame->RIP); + diagnostic_register("cs",frame->CS); + diagnostic_register("rflags",frame->RFLAGS); + diagnostic_register("rax",frame->RAX);diagnostic_register("rbx",frame->RBX); + diagnostic_register("rcx",frame->RCX);diagnostic_register("rdx",frame->RDX); + diagnostic_register("rbp",frame->RBP);diagnostic_register("rsi",frame->RSI); + diagnostic_register("rdi",frame->RDI);diagnostic_register("r8",frame->R8); + diagnostic_register("r9",frame->R9);diagnostic_register("r10",frame->R10); + diagnostic_register("r11",frame->R11);diagnostic_register("r12",frame->R12); + diagnostic_register("r13",frame->R13);diagnostic_register("r14",frame->R14); + diagnostic_register("r15",frame->R15); + } + if(from_user) { + bob64_user_exception_vector=frame->Vector; + bob64_user_exception_error=frame->ErrorCode; + bob64_user_exception_rip=frame->RIP; + bob64_user_expected_exception_vector=~(u64)0; + bob64_user_request_return(-(s64)(128+frame->Vector)); + return 1; + } + diagnostic_text("system halted\r\n"); + for(;;)__asm__ volatile("cli\n\thlt"); +} diff --git a/bob64/interrupts.h b/bob64/interrupts.h new file mode 100644 index 0000000..97ba9f0 --- /dev/null +++ b/bob64/interrupts.h @@ -0,0 +1,45 @@ +#ifndef BOB64_INTERRUPTS_H +#define BOB64_INTERRUPTS_H + +#include "descriptors.h" +#include "abi.h" + +typedef struct { + u64 R15,R14,R13,R12,R11,R10,R9,R8; + u64 RDI,RSI,RBP,RDX,RCX,RBX,RAX; + u64 Vector,ErrorCode,RIP,CS,RFLAGS; +} BOB64_INTERRUPT_FRAME; + +_Static_assert(__builtin_offsetof(BOB64_INTERRUPT_FRAME,Vector)==120, + "interrupt stub register save layout"); +_Static_assert(__builtin_offsetof(BOB64_INTERRUPT_FRAME,RIP)==136, + "interrupt hardware frame layout"); +_Static_assert(sizeof(BOB64_INTERRUPT_FRAME)==160, + "interrupt frame fixed prefix size"); + +extern void (*bob64_exception_stub_table[32])(void); +extern void bob64_irq0_entry(void); +extern void bob64_syscall_entry(void); +extern void bob64_irq1_entry(void); +extern void bob64_irq12_entry(void); +extern volatile u64 bob64_user_exception_vector; +extern volatile u64 bob64_user_exception_error; +extern volatile u64 bob64_user_exception_rip; +extern volatile u64 bob64_user_expected_exception_vector; +extern volatile u64 bob64_user_expected_exception_error_mask; +extern volatile u64 bob64_user_expected_exception_error_value; +void bob64_unhandled_interrupt(void); +int bob64_interrupts_build_idt(BOB64_IDT_GATE entries[BOB64_IDT_ENTRIES],u16 selector); +void bob64_early_console_init(void); +int bob64_interrupts_enable_keyboard(void); +int bob64_interrupts_enable_mouse(void); +int bob64_interrupts_enable_timer(void); +void bob64_timer_irq_tick(void); +u64 bob64_timer_ticks(void); +void bob64_early_console_write(const char *text); +void bob64_early_console_hex64(u64 value); +int bob64_early_console_try_read(void); +u64 BOB64_MS_ABI bob64_exception_dispatch(const BOB64_INTERRUPT_FRAME *frame); +void BOB64_MS_ABI bob64_irq_dispatch(const BOB64_INTERRUPT_FRAME *frame); + +#endif diff --git a/bob64/kernel.c b/bob64/kernel.c new file mode 100644 index 0000000..17d1d38 --- /dev/null +++ b/bob64/kernel.c @@ -0,0 +1,788 @@ +#include "kernel.h" +#include "interrupts.h" +#include "paging.h" +#include "console.h" +#include "heap.h" +#include "runtime.h" +#include "keyboard.h" +#include "mouse.h" +#include "shell.h" +#include "filesystem.h" +#include "exec.h" +#include "process.h" +#include "syscall.h" +#include "compiler.h" + +#define BOB64_KERNEL_HEAP_BASE 0xffff900000000000ULL +#define BOB64_KERNEL_HEAP_LIMIT (64ULL*1024ULL*1024ULL) +#define BOB64_KERNEL_PRIVILEGE_STACK_SIZE (16ULL*1024ULL) + +static BOB64_HEAP kernel_heap; +static BOB64_FILESYSTEM kernel_filesystem; +static u64 kernel_next_window_owner=1; +static BOB64_SHELL kernel_shell; +typedef struct { + BOB64_FILESYSTEM *Filesystem; + u8 NxSupported,PhysicalAddressBits; +} KERNEL_APP_CONTEXT; +static KERNEL_APP_CONTEXT kernel_app_context; +static usize kernel_heap_mapped; +static void *kernel_privilege_stack; +static char kernel_user_output[5]; +static usize kernel_user_output_length; +static u8 kernel_compiler_output[BOB64_COMPILER_IMAGE_LIMIT]; +static void kernel_write(const char *text); + +static int kernel_interrupts_enabled(void) { + u64 flags; + __asm__ volatile("pushfq; pop %0":"=r"(flags)); + return (flags&0x200)!=0; +} +static void kernel_user_write_character(void *context,u8 character); +static int kernel_copy_user_bytes(void *context,u64 address,void *destination, + usize length); +static int kernel_process_fault_smoke_test(BOB64_PROCESS *process, + BOB64_PAGE_TABLE *process_table,const BOB64_PROCESS_OPERATIONS *operations, + const u8 *executable,usize executable_size,u64 expected_rip,u64 error_mask, + u64 error_value,const char *success_message); +static int kernel_wait_for_input_event(void *context,BOB64_EVENT *event); +extern const u8 bob64_embedded_app[]; +extern const u8 bob64_embedded_app_end[]; +extern const u8 bob64_embedded_gui[]; +extern const u8 bob64_embedded_gui_end[]; +extern const u8 bob64_embedded_source[]; +extern const u8 bob64_embedded_source_end[]; + +typedef struct { + BOB64_PAGE_TABLE *PageTable; +} KERNEL_PROCESS_CONTEXT; + +static u64 read_cr3(void); + +static u64 process_allocate_page(void *context) { + (void)context; + return bob64_page_alloc(&bob64_boot_page_allocator,1); +} + +static int process_free_page(void *context,u64 physical_address) { + (void)context; + return bob64_page_free(&bob64_boot_page_allocator,physical_address,1); +} + +static int process_map_page(void *context,u64 virtual_address,u64 physical_address, + u64 flags,u8 **writable_address) { + KERNEL_PROCESS_CONTEXT *process=(KERNEL_PROCESS_CONTEXT *)context; + if(!process||!process->PageTable||!writable_address|| + bob64_page_map(process->PageTable, + virtual_address,physical_address,flags))return -1; + __asm__ volatile("invlpg (%0)"::"r"((void *)(uintptr_t)virtual_address):"memory"); + *writable_address=(u8 *)(uintptr_t)virtual_address; + return 0; +} + +static int process_protect_page(void *context,u64 virtual_address,u64 flags) { + KERNEL_PROCESS_CONTEXT *process=(KERNEL_PROCESS_CONTEXT *)context; + if(!process||!process->PageTable|| + bob64_page_protect(process->PageTable,virtual_address,flags))return -1; + __asm__ volatile("invlpg (%0)"::"r"((void *)(uintptr_t)virtual_address):"memory"); + return 0; +} + +static int process_unmap_page(void *context,u64 virtual_address) { + KERNEL_PROCESS_CONTEXT *process=(KERNEL_PROCESS_CONTEXT *)context; + if(!process||!process->PageTable|| + bob64_page_unmap(process->PageTable,virtual_address,0,0))return -1; + __asm__ volatile("invlpg (%0)"::"r"((void *)(uintptr_t)virtual_address):"memory"); + return 0; +} + +static void kernel_write16(u8 *bytes,u16 value) { + bytes[0]=(u8)value;bytes[1]=(u8)(value>>8); +} + +static void kernel_write32(u8 *bytes,u32 value) { + for(u32 i=0;i<4;i++)bytes[i]=(u8)(value>>(i*8)); +} + +static void kernel_write64(u8 *bytes,u64 value) { + kernel_write32(bytes,(u32)value);kernel_write32(bytes+4,(u32)(value>>32)); +} + +static usize kernel_emit_test_syscall(u8 *code,usize offset,u32 number,u32 argument) { + code[offset++]=0xb8;kernel_write32(code+offset,number);offset+=4; + code[offset++]=0xb9;kernel_write32(code+offset,argument);offset+=4; + code[offset++]=0xcd;code[offset++]=0x80; + return offset; +} + +static usize kernel_emit_test_buffer_syscall(u8 *code,usize offset, + const char *text,usize length) { + usize instruction_start=offset,lea_end,buffer_offset; + code[offset++]=0xb8;kernel_write32(code+offset,BOB64_SYSCALL_WRITE_BUFFER);offset+=4; + code[offset++]=0x48;code[offset++]=0x8d;code[offset++]=0x0d; + lea_end=offset+4; + buffer_offset=instruction_start+24; + kernel_write32(code+offset,(u32)(buffer_offset-lea_end));offset+=4; + code[offset++]=0xba;kernel_write32(code+offset,(u32)length);offset+=4; + code[offset++]=0xcd;code[offset++]=0x80; + code[offset++]=0xe9; + kernel_write32(code+offset,(u32)length);offset+=4; + for(usize i=0;i>1)^(0xedb88320u&-(value&1u)); + } + return ~value; +} + +static int kernel_bytes_equal(const char *left,const char *right) { + while(*left&&*left==*right){left++;right++;} + return *left==*right; +} + +static void kernel_build_bob_application(u8 *executable) { + static const char text[]="bob!"; + usize code_size=0; + for(usize i=0;iNxSupported)return 1; + pages=(BOB64_PROCESS_PAGE *)bob64_heap_calloc(&kernel_heap, + (usize)BOB64_PROCESS_PAGE_LIMIT,sizeof(*pages)); + if(!pages)return -1; + kernel_root=read_cr3(); + table_checkpoint=bob64_bootstrap_space.TablePoolUsed; + allocated_before=bob64_boot_page_allocator.AllocatedCount; + operations.NxSupported=info->NxSupported; + if(bob64_process_init(&process,pages,(usize)BOB64_PROCESS_PAGE_LIMIT,&operations)) { + bob64_heap_free(&kernel_heap,pages);return -1; + } + if(bob64_page_table_init(&process_table,info->PhysicalAddressBits, + bob64_bootstrap_space.PageTable.Allocate,bob64_bootstrap_space.PageTable.Access, + bob64_bootstrap_space.PageTable.Context)|| + bob64_page_table_clone_isolated(&process_table,&bob64_bootstrap_space.PageTable, + BOB64_PROCESS_IMAGE_BASE,BOB64_PROCESS_ISOLATED_SIZE)) { + bob64_bootstrap_space.TablePoolUsed=table_checkpoint; + bob64_heap_free(&kernel_heap,pages);return -1; + } + __asm__ volatile("mov %0,%%cr3"::"r"(process_table.RootPhysical):"memory"); + kernel_build_bob_application(executable); + int result=bob64_process_load(&process,executable,sizeof(executable),1,arguments); + if(result) { + bob64_process_unload(&process); + __asm__ volatile("mov %0,%%cr3"::"r"(kernel_root):"memory"); + bob64_bootstrap_space.TablePoolUsed=table_checkpoint; + bob64_heap_free(&kernel_heap,pages);return -1; + } + startup=(BOB64_APP_STARTUP *)(uintptr_t)process.StartupAddress; + result=process.EntryAddress==BOB64_PROCESS_IMAGE_BASE&& + startup->AbiVersion==BOB64_APP_ABI_VERSION&&startup->ArgumentCount==1&& + startup->Arguments&&kernel_bytes_equal(startup->Arguments[0],"bob!")&& + bob64_page_translate(&process_table, + BOB64_PROCESS_IMAGE_BASE,&physical,&flags)==1&&physical&& + (flags&BOB64_PAGE_USER)&&!(flags&BOB64_PAGE_WRITE)&&!(flags&BOB64_PAGE_NX)&& + bob64_page_translate(&process_table, + BOB64_PROCESS_IMAGE_BASE+BOB64_PAGE_SIZE,&physical,&flags)==1&& + (flags&BOB64_PAGE_USER)&&(flags&BOB64_PAGE_WRITE)&&(flags&BOB64_PAGE_NX)&& + bob64_page_translate(&process_table, + BOB64_PROCESS_STACK_GUARD,&physical,&flags)==0; + if(result) { + kernel_user_output_length=0; + bob64_syscall_set_address_space(&process_table); + bob64_syscall_set_read_user(kernel_copy_user_bytes,0); + bob64_syscall_set_write(kernel_user_write_character,0); + bob64_syscall_set_wait_event(kernel_wait_for_input_event,0); + s64 app_status=bob64_enter_user(process.EntryAddress,process.StartupAddress, + process.InitialStackPointer); + bob64_syscall_set_wait_event(0,0); + bob64_syscall_set_write(0,0); + bob64_syscall_set_read_user(0,0); + bob64_syscall_set_address_space(0); + kernel_user_output[kernel_user_output_length]=0; + if(app_status||kernel_user_output_length!=sizeof(kernel_user_output)-1|| + !kernel_bytes_equal(kernel_user_output,"bob!"))result=0; + else kernel_write("\r\n"); + } + int unload_result=bob64_process_unload(&process); + if(unload_result||process.PageCount||process.Loaded|| + bob64_boot_page_allocator.AllocatedCount!=allocated_before)result=-1; + else result=result?0:-1; + if(!result) { + kernel_build_code_write_fault_application(executable); + if(kernel_process_fault_smoke_test(&process,&process_table,&operations, + executable,sizeof(executable),BOB64_PROCESS_IMAGE_BASE+28,0x7,0x7, + "bob64 kernel: read-only code protection passed\r\n"))result=-1; + } + if(!result) { + kernel_build_nx_fault_application(nx_executable); + if(kernel_process_fault_smoke_test(&process,&process_table,&operations, + nx_executable,sizeof(nx_executable), + BOB64_PROCESS_IMAGE_BASE+BOB64_PAGE_SIZE,0x15,0x15, + "bob64 kernel: non-executable data protection passed\r\n"))result=-1; + } + __asm__ volatile("mov %0,%%cr3"::"r"(kernel_root):"memory"); + bob64_bootstrap_space.TablePoolUsed=table_checkpoint; + if(bob64_boot_page_allocator.AllocatedCount!=allocated_before)result=-1; + if(bob64_heap_free(&kernel_heap,pages))result=-1; + return result; +} + +static u64 read_cr3(void) { + u64 value; + __asm__ volatile("mov %%cr3,%0":"=r"(value)); + return value&BOB64_PAGE_ADDRESS_MASK; +} + +static __attribute__((noreturn)) void kernel_halt(void) { + __asm__ volatile("cli"); + for(;;)__asm__ volatile("hlt"); +} + +static void kernel_write(const char *text) { + bob64_early_console_write(text); + bob64_framebuffer_write(text); +} + +static void kernel_user_write_character(void *context,u8 character) { + char text[2]={(char)character,0}; + (void)context; + if(kernel_user_output_length+1BOB64_SYSCALL_COPY_CHUNK_BYTES) + return -1; + for(usize i=0;iPages,process->PageCapacity,operations)|| + bob64_process_load(process,executable,executable_size,1,arguments)) { + (void)bob64_process_unload(process); + return -1; + } + kernel_user_output_length=0; + bob64_user_exception_vector=~(u64)0; + bob64_user_exception_error=~(u64)0; + bob64_user_exception_rip=~(u64)0; + bob64_user_expected_exception_vector=14; + bob64_user_expected_exception_error_mask=error_mask; + bob64_user_expected_exception_error_value=error_value; + bob64_syscall_set_address_space(process_table); + bob64_syscall_set_read_user(kernel_copy_user_bytes,0); + bob64_syscall_set_write(kernel_user_write_character,0); + status=bob64_enter_user(process->EntryAddress,process->StartupAddress, + process->InitialStackPointer); + bob64_user_expected_exception_vector=~(u64)0; + bob64_syscall_set_write(0,0); + bob64_syscall_set_read_user(0,0); + bob64_syscall_set_address_space(0); + kernel_user_output[kernel_user_output_length]=0; + passed=status==-142&&bob64_user_exception_vector==14&& + bob64_user_exception_rip==expected_rip&& + (bob64_user_exception_error&error_mask)==error_value&& + kernel_user_output_length==sizeof(kernel_user_output)-1&& + kernel_bytes_equal(kernel_user_output,"bob!"); + if(bob64_process_unload(process))return -1; + if(!passed)return -1; + kernel_write(success_message); + return 0; +} + +static int kernel_wait_for_input_event(void *context,BOB64_EVENT *event) { + (void)context; + if(!event)return -1; + for(;;) { + if(!bob64_mouse_poll_event(event)||!bob64_keyboard_poll_event(event))return 0; + __asm__ volatile("pause"); + } +} + +static int kernel_write_user_bytes(void *context,u64 address,const void *source, + usize length) { + volatile u8 *target=(volatile u8 *)(uintptr_t)address; + const u8 *bytes=(const u8 *)source; + (void)context; + if((!target&&length)||(!bytes&&length)||length>BOB64_SYSCALL_MAX_BUFFER) + return -1; + for(usize i=0;iFilesystem||!name||(!buffer&&capacity))return -22; + if(bob64_fs_read(app->Filesystem,name,&data,&length))return -2; + if(length>capacity)return -28; + for(usize i=0;iFilesystem||!name||(!buffer&&length))return -22; + if(bob64_fs_write(app->Filesystem,name,buffer,length))return -28; + return (s64)length; +} + +static s64 kernel_app_open_stream(void *context,const char *name,u32 flags) { + KERNEL_APP_CONTEXT *app=(KERNEL_APP_CONTEXT *)context; + const char *data;usize length; + if(!app||!app->Filesystem||!name)return -22; + if(bob64_fs_read(app->Filesystem,name,&data,&length)) { + if(!(flags&BOB64_FILE_OPEN_CREATE))return -2; + if(bob64_fs_write(app->Filesystem,name,0,0))return -28; + length=0; + } else if(flags&BOB64_FILE_OPEN_TRUNCATE) { + if(bob64_fs_write(app->Filesystem,name,0,0))return -28; + length=0; + } + if(length>0x7fffffffffffffffULL)return -75; + return (s64)length; +} + +static s64 kernel_app_read_stream(void *context,const char *name,u64 offset, + u8 *buffer,usize capacity) { + KERNEL_APP_CONTEXT *app=(KERNEL_APP_CONTEXT *)context; + usize count=0; + if(!app||!app->Filesystem||!name||(!buffer&&capacity))return -22; + if(bob64_fs_read_at(app->Filesystem,name,offset,buffer,capacity,&count))return -2; + return (s64)count; +} + +static s64 kernel_app_write_stream(void *context,const char *name,u64 offset, + const u8 *buffer,usize length) { + KERNEL_APP_CONTEXT *app=(KERNEL_APP_CONTEXT *)context; + if(!app||!app->Filesystem||!name||(!buffer&&length))return -22; + if(bob64_fs_write_at(app->Filesystem,name,offset,buffer,length))return -28; + return (s64)length; +} + +typedef struct { + BOB64_FILE_INFO *Entries; + usize Capacity,Count; + int Full; +} KERNEL_FILE_LIST_CONTEXT; + +static int kernel_app_list_file(void *context,const char *name,usize size) { + KERNEL_FILE_LIST_CONTEXT *list=(KERNEL_FILE_LIST_CONTEXT *)context; + usize length=0; + BOB64_FILE_INFO *entry; + while(name[length]&&lengthEntries[0].Name)-1)length++; + if(name[length]||list->Count>=list->Capacity) { + list->Full=1;return 1; + } + entry=&list->Entries[list->Count++]; + for(usize i=0;iName[i]=name[i]; + entry->Size=(u64)size; + return 0; +} + +static s64 kernel_app_list_files(void *context,BOB64_FILE_INFO *entries, + usize capacity) { + KERNEL_APP_CONTEXT *app=(KERNEL_APP_CONTEXT *)context; + KERNEL_FILE_LIST_CONTEXT list={entries,capacity,0,0}; + if(!app||!app->Filesystem||!entries||!capacity)return -22; + bob64_fs_list(app->Filesystem,kernel_app_list_file,&list); + return list.Full?-28:(s64)list.Count; +} + +static s64 kernel_app_delete_file(void *context,const char *name) { + KERNEL_APP_CONTEXT *app=(KERNEL_APP_CONTEXT *)context; + if(!app||!app->Filesystem||!name)return -22; + return bob64_fs_delete(app->Filesystem,name)?-2:0; +} + +static s64 kernel_run_application(void *context,const char *name,usize argument_count, + const char *const *arguments,int *started) { + BOB64_PAGE_TABLE process_table; + KERNEL_PROCESS_CONTEXT process_context={&process_table}; + BOB64_PROCESS_OPERATIONS operations; + BOB64_PROCESS process; + BOB64_PROCESS_PAGE *pages; + const char *image; + usize image_size; + u64 kernel_root,table_checkpoint; + s64 status=-1; + KERNEL_APP_CONTEXT *app=(KERNEL_APP_CONTEXT *)context; + void *application_privilege_stack=0; + BOB64_WINDOW_SERVER *window_server=0; + u64 previous_privilege_stack=bob64_kernel_tss.Rsp0; + int entered=0,cleanup_error=0,syscall_context_saved=0; + int window_server_ready=0; + u64 window_owner=0; + if(started)*started=0; + if(!app||!app->Filesystem||!app->NxSupported||!started|| + !app->PhysicalAddressBits|| + bob64_fs_read(app->Filesystem,name,&image,&image_size))return -1; + operations=(BOB64_PROCESS_OPERATIONS){process_allocate_page,process_free_page, + process_map_page,process_protect_page,process_unmap_page,&process_context, + app->NxSupported}; + pages=(BOB64_PROCESS_PAGE *)bob64_heap_calloc(&kernel_heap, + (usize)BOB64_PROCESS_PAGE_LIMIT,sizeof(*pages)); + if(!pages)return -1; + kernel_root=read_cr3(); + table_checkpoint=bob64_bootstrap_space.TablePoolUsed; + if(bob64_process_init(&process,pages,(usize)BOB64_PROCESS_PAGE_LIMIT,&operations)) + goto done; + if(bob64_page_table_init(&process_table,app->PhysicalAddressBits, + bob64_bootstrap_space.PageTable.Allocate,bob64_bootstrap_space.PageTable.Access, + bob64_bootstrap_space.PageTable.Context))goto done; + if(bob64_page_table_clone_isolated(&process_table,&bob64_bootstrap_space.PageTable, + BOB64_PROCESS_IMAGE_BASE,BOB64_PROCESS_ISOLATED_SIZE))goto done; + __asm__ volatile("mov %0,%%cr3"::"r"(process_table.RootPhysical):"memory"); + if(bob64_process_load(&process,image,image_size,argument_count,arguments))goto restore; + application_privilege_stack=bob64_heap_alloc(&kernel_heap, + (usize)BOB64_KERNEL_PRIVILEGE_STACK_SIZE); + if(!application_privilege_stack) { + if(bob64_process_unload(&process))cleanup_error=1; + goto restore; + } + for(usize i=0;i<(usize)BOB64_KERNEL_PRIVILEGE_STACK_SIZE;i++) + ((u8 *)application_privilege_stack)[i]=0; + u64 application_stack_top=(u64)(uintptr_t)application_privilege_stack+ + BOB64_KERNEL_PRIVILEGE_STACK_SIZE; + if(bob64_tss_set_rsp0(&bob64_kernel_tss,application_stack_top)|| + bob64_kernel_tss.Rsp0!=application_stack_top) { + if(bob64_process_unload(&process))cleanup_error=1; + goto restore; + } + if(bob64_syscall_context_push()) { + if(bob64_process_unload(&process))cleanup_error=1; + goto restore; + } + syscall_context_saved=1; + kernel_user_output_length=0; + u32 display_width,display_height; + if(!bob64_framebuffer_resolution(&display_width,&display_height)) { + window_owner=kernel_next_window_owner++; + if(!window_owner)window_owner=kernel_next_window_owner++; + window_server=(BOB64_WINDOW_SERVER *)bob64_heap_calloc(&kernel_heap,1, + sizeof(*window_server)); + if(window_server&&!bob64_window_server_init(window_server,&kernel_heap, + window_owner,display_width,display_height))window_server_ready=1; + else if(window_server) { + bob64_window_server_close(window_server); + if(bob64_heap_free(&kernel_heap,window_server))cleanup_error=1; + window_server=0; + } + } + bob64_syscall_set_address_space(&process_table); + bob64_syscall_set_read_user(kernel_copy_user_bytes,0); + bob64_syscall_set_write_user(kernel_write_user_bytes,0); + bob64_syscall_set_filesystem(kernel_app_read_file,kernel_app_write_file,app); + bob64_syscall_set_file_stream(kernel_app_open_stream,kernel_app_read_stream, + kernel_app_write_stream,app); + bob64_syscall_set_file_manager(kernel_app_list_files,kernel_app_delete_file,app); + bob64_syscall_set_write(kernel_user_write_character,0); + bob64_syscall_set_wait_event(kernel_wait_for_input_event,0); + bob64_syscall_set_window_server(window_server_ready?window_server:0, + window_owner); + *started=1;entered=1; + status=bob64_enter_user(process.EntryAddress,process.StartupAddress, + process.InitialStackPointer); + if(bob64_tss_set_rsp0(&bob64_kernel_tss,previous_privilege_stack)|| + bob64_kernel_tss.Rsp0!=previous_privilege_stack)cleanup_error=1; + if(bob64_heap_free(&kernel_heap,application_privilege_stack))cleanup_error=1; + application_privilege_stack=0; + if(window_server_ready)bob64_window_server_close(window_server); + if(window_server&&bob64_heap_free(&kernel_heap,window_server))cleanup_error=1; + if(syscall_context_saved&&bob64_syscall_context_pop())cleanup_error=1; + kernel_write("\r\n"); + if(bob64_process_unload(&process))cleanup_error=1; +restore: + if(application_privilege_stack) { + if(bob64_tss_set_rsp0(&bob64_kernel_tss,previous_privilege_stack)) + cleanup_error=1; + if(bob64_heap_free(&kernel_heap,application_privilege_stack))cleanup_error=1; + application_privilege_stack=0; + } + __asm__ volatile("mov %0,%%cr3"::"r"(kernel_root):"memory"); +done: + bob64_bootstrap_space.TablePoolUsed=table_checkpoint; + if(bob64_heap_free(&kernel_heap,pages)||cleanup_error)status=-1; + if(!entered)*started=0; + return status; +} + +static int kernel_compile_application(void *context,const char *source_name, + const char *output_name,usize *error_offset) { + KERNEL_APP_CONTEXT *app=(KERNEL_APP_CONTEXT *)context; + const char *source; + usize source_length,output_length; + int result; + if(!app||!app->Filesystem||!source_name||!output_name|| + bob64_fs_read(app->Filesystem,source_name,&source,&source_length))return -1; + result=bob64_compile_c(source,source_length,kernel_compiler_output, + sizeof(kernel_compiler_output),&output_length,error_offset); + if(result)return result; + if(bob64_fs_write(app->Filesystem,output_name,kernel_compiler_output,output_length)) + return -1; + return 0; +} + +static void kernel_hex64(u64 value) { + static const char digits[]="0123456789abcdef"; + char text[17]; + for(u32 i=0;i<16;i++)text[i]=digits[(value>>(60-i*4))&15]; + text[16]=0; + kernel_write(text); +} + +static int kernel_heap_grow(void *context,void **region,usize *region_size) { + const BOB64_KERNEL_BOOT_INFO *info=(const BOB64_KERNEL_BOOT_INFO *)context; + u64 physical,virtual_address; + if(!info||!region||!region_size||kernel_heap_mapped>=BOB64_KERNEL_HEAP_LIMIT) + return 0; + physical=bob64_page_alloc(&bob64_boot_page_allocator,1); + if(!physical)return 0; + virtual_address=BOB64_KERNEL_HEAP_BASE+kernel_heap_mapped; + if(bob64_page_map(&bob64_bootstrap_space.PageTable,virtual_address,physical, + BOB64_PAGE_WRITE|(info->NxSupported?BOB64_PAGE_NX:0))) { + bob64_page_free(&bob64_boot_page_allocator,physical,1); + return 0; + } + __asm__ volatile("invlpg (%0)"::"r"((void *)(uintptr_t)virtual_address):"memory"); + volatile u64 *words=(volatile u64 *)(uintptr_t)virtual_address; + for(usize i=0;i=BOB64_KERNEL_HEAP_BASE))return -1; + first[0]='b';first[1]='o';first[2]='b';first[3]=0; + large[0]='6';large[1]='4';large[4999]='!'; + for(usize i=0;i<64;i++)if(zero[i])return -1; + if(first[0]!='b'||first[1]!='o'||first[2]!='b'||large[0]!='6'|| + large[1]!='4'||large[4999]!='!')return -1; + if(bob64_heap_free(&kernel_heap,large)||bob64_heap_free(&kernel_heap,first)|| + bob64_heap_free(&kernel_heap,zero)||bob64_heap_free(&kernel_heap,zero)!=-1) + return -1; + return 0; +} + +static int kernel_privilege_stack_init(void) { + kernel_privilege_stack=bob64_heap_alloc(&kernel_heap, + (usize)BOB64_KERNEL_PRIVILEGE_STACK_SIZE); + if(!kernel_privilege_stack)return -1; + for(usize i=0;i<(usize)BOB64_KERNEL_PRIVILEGE_STACK_SIZE;i++) + ((u8 *)kernel_privilege_stack)[i]=0; + return bob64_tss_set_rsp0(&bob64_kernel_tss, + (u64)(uintptr_t)kernel_privilege_stack+ + BOB64_KERNEL_PRIVILEGE_STACK_SIZE); +} + +static void shell_write(void *context,const char *text) { + (void)context; + kernel_write(text); +} + +static void shell_clear(void *context) { + (void)context; + bob64_framebuffer_clear(); + bob64_early_console_write("\x1b[2J\x1b[H"); +} + +__attribute__((noreturn)) void bob64_kernel_main(const BOB64_KERNEL_BOOT_INFO *info) { + bob64_early_console_init(); + if(info&&info->HasFramebuffer&&bob64_framebuffer_init(info->FramebufferBase, + info->FramebufferSize,info->FramebufferWidth,info->FramebufferHeight, + info->FramebufferPixelsPerScanLine,info->FramebufferPixelFormat)) + bob64_early_console_write("bob64 kernel: framebuffer rejected\r\n"); + kernel_write("bob64!\r\nbob64 kernel: long mode entry\r\n"); + if(!info||sizeof(void *)!=8||read_cr3()!=info->PageTableRoot|| + !info->MemoryMapAddress||!info->MemoryMapSize|| + info->MemoryDescriptorSize<40||!info->StackBase||!info->StackSize|| + info->PhysicalAddressBits<36||info->PhysicalAddressBits>52|| + info->NxSupported>1||info->HasFramebuffer>1) { + kernel_write("bob64 kernel: invalid boot information\r\n"); + kernel_halt(); + } + if(kernel_heap_smoke_test(info)) { + kernel_write("bob64 kernel: heap initialization failed\r\n"); + kernel_halt(); + } + if(kernel_privilege_stack_init()) { + kernel_write("bob64 kernel: privilege stack initialization failed\r\n"); + kernel_halt(); + } + int process_test=kernel_process_smoke_test(info); + if(process_test<0) { + kernel_write("bob64 kernel: application loader smoke test failed\r\n"); + kernel_halt(); + } + if(!process_test)kernel_write("bob64 kernel: ring-3 bob! app passed\r\n"); + else kernel_write("bob64 kernel: app test skipped (NX unavailable)\r\n"); + if(bob64_fs_init(&kernel_filesystem,&kernel_heap)) { + kernel_write("bob64 kernel: filesystem initialization failed\r\n"); + kernel_halt(); + } + if(info->NxSupported&&kernel_install_bob_application(&kernel_filesystem)) + kernel_write("bob64 kernel: demo app install failed\r\n"); + if(info->NxSupported&&kernel_install_gui_application(&kernel_filesystem)) + kernel_write("bob64 kernel: desktop app install failed\r\n"); + if(kernel_install_bob_source(&kernel_filesystem)) + kernel_write("bob64 kernel: C demo source install failed\r\n"); + kernel_app_context.Filesystem=&kernel_filesystem; + kernel_app_context.NxSupported=info->NxSupported; + kernel_app_context.PhysicalAddressBits=info->PhysicalAddressBits; + kernel_write("CR3=0x");kernel_hex64(info->PageTableRoot); + kernel_write(" memory-map=0x");kernel_hex64(info->MemoryMapAddress); + kernel_write(" bytes=0x");kernel_hex64(info->MemoryMapSize); + kernel_write(" heap=0x");kernel_hex64(BOB64_KERNEL_HEAP_BASE); + kernel_write(" mapped=0x");kernel_hex64((u64)bob64_heap_mapped_bytes(&kernel_heap)); + kernel_write("\r\n"); + kernel_write("bob64 kernel: memory checks passed\r\n"); + if(bob64_interrupts_enable_timer()) { + kernel_write("bob64 kernel: timer IRQ unavailable\r\n"); + kernel_halt(); + } + kernel_write("bob64 kernel: timer IRQ enabled\r\n"); + bob64_keyboard_reset(); + int keyboard_irq_enabled=bob64_interrupts_enable_keyboard()==0; + if(!keyboard_irq_enabled) + kernel_write("bob64 kernel: keyboard IRQ unavailable; using polling\r\n"); + else kernel_write("bob64 kernel: keyboard IRQ enabled\r\n"); + if(info->NxSupported) { + int started=0; + s64 status=kernel_run_application(&kernel_app_context,"bob.b64e",0,0,&started); + if(!started||status||(keyboard_irq_enabled&&!kernel_interrupts_enabled())) { + kernel_write("bob64 kernel: native streaming app test failed\r\n"); + kernel_halt(); + } + kernel_write("bob64 kernel: native streaming app passed\r\n"); + } + u32 display_width,display_height; + if(!bob64_framebuffer_resolution(&display_width,&display_height)) { + if(bob64_mouse_init(display_width,display_height)) + kernel_write("bob64 kernel: PS/2 mouse unavailable\r\n"); + else if(bob64_interrupts_enable_mouse()) + kernel_write("bob64 kernel: mouse IRQ unavailable; using polling\r\n"); + else kernel_write("bob64 kernel: PS/2 mouse IRQ enabled\r\n"); + } + if(bob64_shell_init(&kernel_shell,&bob64_boot_page_allocator,&kernel_heap, + &kernel_filesystem, + shell_write,shell_clear,&kernel_app_context)) { + kernel_write("bob64 kernel: shell initialization failed\r\n"); + kernel_halt(); + } + bob64_shell_set_runner(&kernel_shell,kernel_run_application); + bob64_shell_set_compiler(&kernel_shell,kernel_compile_application); + for(;;) { + int character=bob64_keyboard_poll(); + if(character<0)character=bob64_early_console_try_read(); + if(character>=0)bob64_shell_input(&kernel_shell,character); + else __asm__ volatile("pause"); + } +} diff --git a/bob64/kernel.h b/bob64/kernel.h new file mode 100644 index 0000000..795d4af --- /dev/null +++ b/bob64/kernel.h @@ -0,0 +1,37 @@ +#ifndef BOB64_KERNEL_H +#define BOB64_KERNEL_H + +#include "types.h" +#include "descriptors.h" + +typedef struct { + u64 PageTableRoot; + u64 MemoryMapAddress; + u64 MemoryMapSize; + u64 MemoryDescriptorSize; + u64 StackBase; + u64 StackSize; + u64 FramebufferBase; + u64 FramebufferSize; + u32 FramebufferWidth; + u32 FramebufferHeight; + u32 FramebufferPixelsPerScanLine; + u32 FramebufferPixelFormat; + u8 PhysicalAddressBits; + u8 NxSupported; + u8 HasFramebuffer; + u8 Reserved[5]; +} BOB64_KERNEL_BOOT_INFO; + +_Static_assert(sizeof(BOB64_KERNEL_BOOT_INFO)==88,"bob64 kernel boot information ABI"); +_Static_assert(__builtin_offsetof(BOB64_KERNEL_BOOT_INFO,NxSupported)==81, + "handoff assembly NX-support offset mismatch"); + +__attribute__((noreturn)) void bob64_kernel_main(const BOB64_KERNEL_BOOT_INFO *info); +__attribute__((noreturn)) void bob64_enter_kernel( + u64 page_table_root,u64 stack_top, + const BOB64_DESCRIPTOR_TABLE_POINTER *gdtr, + const BOB64_DESCRIPTOR_TABLE_POINTER *idtr, + const BOB64_KERNEL_BOOT_INFO *info); + +#endif diff --git a/bob64/keyboard.c b/bob64/keyboard.c new file mode 100644 index 0000000..b1dbaf0 --- /dev/null +++ b/bob64/keyboard.c @@ -0,0 +1,150 @@ +#include "keyboard.h" + +static BOB64_KEYBOARD_STATE keyboard_state; +#define KEYBOARD_EVENT_QUEUE_SIZE 64u +static BOB64_EVENT keyboard_event_queue[KEYBOARD_EVENT_QUEUE_SIZE]; +static volatile u32 keyboard_event_head,keyboard_event_tail; +static volatile u8 keyboard_irq_active; + +static const u8 unshifted[128]={ + [0x02]='1',[0x03]='2',[0x04]='3',[0x05]='4',[0x06]='5', + [0x07]='6',[0x08]='7',[0x09]='8',[0x0a]='9',[0x0b]='0', + [0x0c]='-',[0x0d]='=',[0x0e]='\b',[0x0f]='\t', + [0x10]='q',[0x11]='w',[0x12]='e',[0x13]='r',[0x14]='t', + [0x15]='y',[0x16]='u',[0x17]='i',[0x18]='o',[0x19]='p', + [0x1a]='[',[0x1b]=']',[0x1c]='\n',[0x1e]='a',[0x1f]='s', + [0x20]='d',[0x21]='f',[0x22]='g',[0x23]='h',[0x24]='j', + [0x25]='k',[0x26]='l',[0x27]=';',[0x28]='\'',[0x29]='`', + [0x2b]='\\',[0x2c]='z',[0x2d]='x',[0x2e]='c',[0x2f]='v', + [0x30]='b',[0x31]='n',[0x32]='m',[0x33]=',',[0x34]='.', + [0x35]='/',[0x39]=' ' +}; + +static const u8 shifted[128]={ + [0x02]='!',[0x03]='@',[0x04]='#',[0x05]='$',[0x06]='%', + [0x07]='^',[0x08]='&',[0x09]='*',[0x0a]='(',[0x0b]=')', + [0x0c]='_',[0x0d]='+',[0x10]='Q',[0x11]='W',[0x12]='E', + [0x13]='R',[0x14]='T',[0x15]='Y',[0x16]='U',[0x17]='I', + [0x18]='O',[0x19]='P',[0x1a]='{',[0x1b]='}',[0x1e]='A', + [0x1f]='S',[0x20]='D',[0x21]='F',[0x22]='G',[0x23]='H', + [0x24]='J',[0x25]='K',[0x26]='L',[0x27]=':',[0x28]='"', + [0x29]='~',[0x2b]='|',[0x2c]='Z',[0x2d]='X',[0x2e]='C', + [0x2f]='V',[0x30]='B',[0x31]='N',[0x32]='M',[0x33]='<', + [0x34]='>',[0x35]='?' +}; + +void bob64_keyboard_reset(void) { + keyboard_state.LeftShift=0;keyboard_state.RightShift=0; + keyboard_state.LeftControl=0;keyboard_state.RightControl=0; + keyboard_state.LeftAlt=0;keyboard_state.RightAlt=0; + keyboard_state.CapsLock=0;keyboard_state.Extended=0; + keyboard_state.PauseRemaining=0; + keyboard_event_head=keyboard_event_tail=0; +} + +void bob64_keyboard_irq_set_active(int active) { + keyboard_event_head=keyboard_event_tail=0; + keyboard_irq_active=(u8)(active!=0); +} + +int bob64_keyboard_irq_capture(u8 scancode) { + BOB64_EVENT event; + u32 head=keyboard_event_head,tail=keyboard_event_tail; + if(bob64_keyboard_decode_event(&keyboard_state,scancode,&event))return -1; + if((u32)(head-tail)>=KEYBOARD_EVENT_QUEUE_SIZE)return -1; + keyboard_event_queue[head&(KEYBOARD_EVENT_QUEUE_SIZE-1)]=event; + __asm__ volatile("":::"memory"); + keyboard_event_head=head+1; + return 0; +} + +int bob64_keyboard_irq_pop_event(BOB64_EVENT *event) { + u32 tail=keyboard_event_tail,head=keyboard_event_head; + if(!event||tail==head)return -1; + __asm__ volatile("":::"memory"); + *event=keyboard_event_queue[tail&(KEYBOARD_EVENT_QUEUE_SIZE-1)]; + __asm__ volatile("":::"memory"); + keyboard_event_tail=tail+1; + return 0; +} + +int bob64_keyboard_irq_service(void) { + u8 status,scancode; + __asm__ volatile("inb $0x64,%0":"=a"(status)); + if(status==0xff||!(status&1)||(status&0x20))return -1; + __asm__ volatile("inb $0x60,%0":"=a"(scancode)); + return bob64_keyboard_irq_capture(scancode); +} + +int bob64_keyboard_decode_event(BOB64_KEYBOARD_STATE *state,u8 scancode, + BOB64_EVENT *event) { + u8 released,code,letter,extended; + int character=0; + if(!state||!event)return -1; + if(state->PauseRemaining) { state->PauseRemaining--;return -1; } + if(scancode==0xe1) { state->PauseRemaining=5;state->Extended=0;return -1; } + if(scancode==0xe0) { state->Extended=1;return -1; } + extended=state->Extended;state->Extended=0; + released=(u8)(scancode&0x80);code=(u8)(scancode&0x7f); + if(!extended&&(code==0x2a||code==0x36)) { + u8 *shift=code==0x2a?&state->LeftShift:&state->RightShift; + *shift=(u8)!released; + } else if(code==0x1d) { + u8 *control=extended?&state->RightControl:&state->LeftControl; + *control=(u8)!released; + } else if(code==0x38) { + u8 *alt=extended?&state->RightAlt:&state->LeftAlt; + *alt=(u8)!released; + } else if(code==0x3a&&!released)state->CapsLock^=1; + else if(!released&&!extended) { + letter=(u8)(code>=0x10&&code<=0x32&&unshifted[code]>='a'&&unshifted[code]<='z'); + u8 shift=(u8)(state->LeftShift||state->RightShift); + character=letter?((shift^state->CapsLock)?shifted[code]:unshifted[code]): + (shift&&shifted[code]?shifted[code]:unshifted[code]); + if(code==0x01)character=0x1b; + } + event->Type=released?BOB64_EVENT_KEY_UP:BOB64_EVENT_KEY_DOWN; + event->Key=(extended?BOB64_EVENT_KEY_EXTENDED:0u)|code; + event->Character=(u32)character; + event->Modifiers=(state->LeftShift||state->RightShift?BOB64_EVENT_MOD_SHIFT:0u)| + (state->CapsLock?BOB64_EVENT_MOD_CAPS_LOCK:0u)| + (state->LeftControl||state->RightControl?BOB64_EVENT_MOD_CONTROL:0u)| + (state->LeftAlt||state->RightAlt?BOB64_EVENT_MOD_ALT:0u); + event->X=0;event->Y=0;event->DeltaX=0;event->DeltaY=0; + event->Buttons=0;event->Wheel=0;event->WindowHandle=0; + event->ScreenX=0;event->ScreenY=0; + return 0; +} + +int bob64_keyboard_decode(BOB64_KEYBOARD_STATE *state,u8 scancode) { + BOB64_EVENT event; + if(bob64_keyboard_decode_event(state,scancode,&event)|| + event.Type!=BOB64_EVENT_KEY_DOWN||!event.Character)return -1; + return (int)event.Character; +} + +int bob64_keyboard_poll(void) { + u8 status,scancode; + if(keyboard_irq_active) { + BOB64_EVENT event; + while(!bob64_keyboard_irq_pop_event(&event)) + if(event.Type==BOB64_EVENT_KEY_DOWN&&event.Character) + return (int)event.Character; + return -1; + } + __asm__ volatile("inb $0x64,%0":"=a"(status)); + if(status==0xff||!(status&1))return -1; + if(status&0x20) { __asm__ volatile("inb $0x60,%0":"=a"(scancode));return -1; } + __asm__ volatile("inb $0x60,%0":"=a"(scancode)); + return bob64_keyboard_decode(&keyboard_state,scancode); +} + +int bob64_keyboard_poll_event(BOB64_EVENT *event) { + u8 status,scancode; + if(!event)return -1; + if(keyboard_irq_active)return bob64_keyboard_irq_pop_event(event); + __asm__ volatile("inb $0x64,%0":"=a"(status)); + if(status==0xff||!(status&1)||(status&0x20))return -1; + __asm__ volatile("inb $0x60,%0":"=a"(scancode)); + return bob64_keyboard_decode_event(&keyboard_state,scancode,event); +} diff --git a/bob64/keyboard.h b/bob64/keyboard.h new file mode 100644 index 0000000..6d9aa47 --- /dev/null +++ b/bob64/keyboard.h @@ -0,0 +1,24 @@ +#ifndef BOB64_KEYBOARD_H +#define BOB64_KEYBOARD_H + +#include "types.h" +#include "event.h" + +typedef struct { + u8 LeftShift,RightShift,LeftControl,RightControl,LeftAlt,RightAlt; + u8 CapsLock,Extended,PauseRemaining; +} BOB64_KEYBOARD_STATE; + +void bob64_keyboard_reset(void); +int bob64_keyboard_decode(BOB64_KEYBOARD_STATE *state,u8 scancode); +int bob64_keyboard_decode_event(BOB64_KEYBOARD_STATE *state,u8 scancode, + BOB64_EVENT *event); +int bob64_keyboard_poll(void); +int bob64_keyboard_poll_event(BOB64_EVENT *event); +/* IRQ producer and foreground consumer; the queue drops new events when full. */ +int bob64_keyboard_irq_capture(u8 scancode); +int bob64_keyboard_irq_service(void); +int bob64_keyboard_irq_pop_event(BOB64_EVENT *event); +void bob64_keyboard_irq_set_active(int active); + +#endif diff --git a/bob64/libc.c b/bob64/libc.c new file mode 100644 index 0000000..e11ca96 --- /dev/null +++ b/bob64/libc.c @@ -0,0 +1,40 @@ +#include "libc.h" + +void *bob64_memcpy(void *destination,const void *source,usize length) { + u8 *out=(u8 *)destination; + const u8 *in=(const u8 *)source; + for(usize i=0;i(uintptr_t)in) + for(usize i=length;i;i--)out[i-1]=in[i-1]; + return destination; +} + +void *bob64_memset(void *destination,int value,usize length) { + u8 *out=(u8 *)destination; + for(usize i=0;i(u8)*right?1:0; +} diff --git a/bob64/libc.h b/bob64/libc.h new file mode 100644 index 0000000..75e956a --- /dev/null +++ b/bob64/libc.h @@ -0,0 +1,13 @@ +#ifndef BOB64_LIBC_H +#define BOB64_LIBC_H + +#include "types.h" + +void *bob64_memcpy(void *destination,const void *source,usize length); +void *bob64_memmove(void *destination,const void *source,usize length); +void *bob64_memset(void *destination,int value,usize length); +int bob64_memcmp(const void *left,const void *right,usize length); +usize bob64_strlen(const char *text); +int bob64_strcmp(const char *left,const char *right); + +#endif diff --git a/bob64/memory.c b/bob64/memory.c new file mode 100644 index 0000000..a95aefe --- /dev/null +++ b/bob64/memory.c @@ -0,0 +1,116 @@ +#include "memory.h" + +#define BOB64_LOW_MEMORY_LIMIT 0x100000ULL +#define BOB64_U64_MAX (~(u64)0) + +static int extent_end(u64 base,u64 pages,u64 *end) { + if(!pages||pages>(BOB64_U64_MAX-base)/EFI_PAGE_SIZE)return 0; + *end=base+pages*EFI_PAGE_SIZE; + return 1; +} + +static void remove_extent(BOB64_PAGE_ALLOCATOR *allocator,usize index) { + for(usize i=index;i+1Count;i++)allocator->Extents[i]=allocator->Extents[i+1]; + allocator->Count--; +} + +static int add_extent(BOB64_PAGE_ALLOCATOR *allocator,u64 base,u64 pages) { + usize index=0; + u64 end,next_end; + if(!pages)return 0; + if((base&(EFI_PAGE_SIZE-1))||!extent_end(base,pages,&end))return BOB64_PAGE_ALLOC_INVALID; + while(indexCount&&allocator->Extents[index].Base0) { + BOB64_PAGE_EXTENT *previous=&allocator->Extents[index-1]; + if(!extent_end(previous->Base,previous->Pages,&next_end)||next_end>base) + return BOB64_PAGE_ALLOC_INVALID; + } + if(indexCount&&end>allocator->Extents[index].Base) + return BOB64_PAGE_ALLOC_INVALID; + if(index>0) { + BOB64_PAGE_EXTENT *previous=&allocator->Extents[index-1]; + if(previous->Base+previous->Pages*EFI_PAGE_SIZE==base) { + previous->Pages+=pages; + if(indexCount&&end==allocator->Extents[index].Base) { + previous->Pages+=allocator->Extents[index].Pages; + remove_extent(allocator,index); + } + return 0; + } + } + if(indexCount&&end==allocator->Extents[index].Base) { + allocator->Extents[index].Base=base; + allocator->Extents[index].Pages+=pages; + return 0; + } + if(allocator->Count>=allocator->Capacity)return BOB64_PAGE_ALLOC_FULL; + for(usize i=allocator->Count;i>index;i--)allocator->Extents[i]=allocator->Extents[i-1]; + allocator->Extents[index].Base=base; + allocator->Extents[index].Pages=pages; + allocator->Count++; + return 0; +} + +int bob64_page_allocator_init(BOB64_PAGE_ALLOCATOR *allocator, + BOB64_PAGE_EXTENT *storage,usize capacity, + u8 physical_address_bits, + const void *memory_map,usize memory_map_size, + usize descriptor_size) { + const u8 *bytes=(const u8 *)memory_map; + u64 physical_limit; + if(!allocator||!storage||!capacity||capacity>BOB64_PAGE_EXTENT_LIMIT|| + physical_address_bits<36||physical_address_bits>52|| + !memory_map||descriptor_sizeCount=0;allocator->Capacity=capacity;allocator->Extents=storage; + allocator->AllocatedCount=0; + for(usize offset=0;offsetPhysicalStart,pages=descriptor->NumberOfPages,end; + if(descriptor->Type!=EFI_MEMORY_CONVENTIONAL||!pages)continue; + if(!extent_end(base,pages,&end))return BOB64_PAGE_ALLOC_INVALID; + if(base>=physical_limit)continue; + if(end>physical_limit)pages=(physical_limit-base)/EFI_PAGE_SIZE; + if(base=pages)continue; + base+=skipped*EFI_PAGE_SIZE; + pages-=skipped; + } + int result=add_extent(allocator,base,pages); + if(result)return result; + } + return (int)allocator->Count; +} + +u64 bob64_page_alloc(BOB64_PAGE_ALLOCATOR *allocator,u64 pages) { + if(!allocator||!allocator->Extents||!pages|| + allocator->AllocatedCount==BOB64_PAGE_ALLOCATION_LIMIT)return 0; + for(usize i=0;iCount;i++)if(allocator->Extents[i].Pages>=pages) { + u64 address=allocator->Extents[i].Base; + allocator->Extents[i].Base+=pages*EFI_PAGE_SIZE; + allocator->Extents[i].Pages-=pages; + if(!allocator->Extents[i].Pages)remove_extent(allocator,i); + allocator->Allocated[allocator->AllocatedCount].Base=address; + allocator->Allocated[allocator->AllocatedCount].Pages=pages; + allocator->AllocatedCount++; + return address; + } + return 0; +} + +int bob64_page_free(BOB64_PAGE_ALLOCATOR *allocator,u64 address,u64 pages) { + usize index=0; + int result; + if(!allocator||!allocator->Extents||addressAllocatedCount&& + (allocator->Allocated[index].Base!=address||allocator->Allocated[index].Pages!=pages))index++; + if(index==allocator->AllocatedCount)return BOB64_PAGE_ALLOC_INVALID; + result=add_extent(allocator,address,pages); + if(result)return result; + for(usize i=index;i+1AllocatedCount;i++)allocator->Allocated[i]=allocator->Allocated[i+1]; + allocator->AllocatedCount--; + return 0; +} diff --git a/bob64/memory.h b/bob64/memory.h new file mode 100644 index 0000000..43150b5 --- /dev/null +++ b/bob64/memory.h @@ -0,0 +1,33 @@ +#ifndef BOB64_MEMORY_H +#define BOB64_MEMORY_H + +#include "efi.h" + +#define BOB64_PAGE_EXTENT_LIMIT 128 +#define BOB64_PAGE_ALLOCATION_LIMIT 16384 +#define BOB64_PAGE_ALLOC_INVALID (-1) +#define BOB64_PAGE_ALLOC_FULL (-2) + +typedef struct { + u64 Base; + u64 Pages; +} BOB64_PAGE_EXTENT; + +/* Sorted, non-overlapping runs of currently available physical 4 KiB pages. */ +typedef struct { + usize Count; + usize Capacity; + BOB64_PAGE_EXTENT *Extents; + usize AllocatedCount; + BOB64_PAGE_EXTENT Allocated[BOB64_PAGE_ALLOCATION_LIMIT]; +} BOB64_PAGE_ALLOCATOR; + +int bob64_page_allocator_init(BOB64_PAGE_ALLOCATOR *allocator, + BOB64_PAGE_EXTENT *storage,usize capacity, + u8 physical_address_bits, + const void *memory_map,usize memory_map_size, + usize descriptor_size); +u64 bob64_page_alloc(BOB64_PAGE_ALLOCATOR *allocator,u64 pages); +int bob64_page_free(BOB64_PAGE_ALLOCATOR *allocator,u64 address,u64 pages); + +#endif diff --git a/bob64/mouse.c b/bob64/mouse.c new file mode 100644 index 0000000..f098386 --- /dev/null +++ b/bob64/mouse.c @@ -0,0 +1,171 @@ +#include "mouse.h" + +static BOB64_MOUSE_STATE mouse_state; +#define MOUSE_EVENT_QUEUE_SIZE 64u +static BOB64_EVENT mouse_event_queue[MOUSE_EVENT_QUEUE_SIZE]; +static volatile u32 mouse_event_head,mouse_event_tail; +static volatile u8 mouse_irq_active; + +static void out8(u16 port,u8 value) { + __asm__ volatile("outb %0,%1"::"a"(value),"Nd"(port)); +} + +static u8 in8(u16 port) { + u8 value; + __asm__ volatile("inb %1,%0":"=a"(value):"Nd"(port)); + return value; +} + +static int wait_input_empty(void) { + for(u32 i=0;i<100000;i++) { + u8 status=in8(0x64); + if(status==0xff)return -1; + if(!(status&2))return 0; + } + return -1; +} + +static int send_mouse_byte(u8 command) { + if(wait_input_empty())return -1; + out8(0x64,0xd4); + if(wait_input_empty())return -1; + out8(0x60,command); + for(u32 i=0;i<100000;i++) { + u8 status=in8(0x64); + if(status==0xff)return -1; + if((status&0x21)==0x21)return in8(0x60)==0xfa?0:-1; + } + return -1; +} + +static int read_mouse_response(u8 *value) { + if(!value)return -1; + for(u32 i=0;i<100000;i++) { + u8 status=in8(0x64); + if(status==0xff)return -1; + if((status&0x21)==0x21) {*value=in8(0x60);return 0;} + } + return -1; +} + +static int set_sample_rate(u8 rate) { + return send_mouse_byte(0xf3)||send_mouse_byte(rate)?-1:0; +} + +int bob64_mouse_reset(BOB64_MOUSE_STATE *state,u32 width,u32 height) { + if(!state||!width||!height||width>0x7fffffffU||height>0x7fffffffU)return -1; + state->Width=width;state->Height=height; + state->X=(s32)(width/2);state->Y=(s32)(height/2); + state->Packet[0]=state->Packet[1]=state->Packet[2]=state->Packet[3]=0; + state->PacketLength=0;state->PacketSize=3;state->Buttons=0; + state->DeviceId=0;state->Enabled=0; + return 0; +} + +int bob64_mouse_irq_queue_init(u32 width,u32 height) { + if(bob64_mouse_reset(&mouse_state,width,height))return -1; + mouse_event_head=mouse_event_tail=0;mouse_irq_active=0; + return 0; +} + +void bob64_mouse_irq_set_active(int active) { + mouse_event_head=mouse_event_tail=0; + mouse_irq_active=(u8)(active!=0); +} + +int bob64_mouse_irq_capture(u8 value) { + BOB64_EVENT event; + u32 head=mouse_event_head,tail=mouse_event_tail; + if(bob64_mouse_decode(&mouse_state,value,&event))return -1; + if((u32)(head-tail)>=MOUSE_EVENT_QUEUE_SIZE)return -1; + mouse_event_queue[head&(MOUSE_EVENT_QUEUE_SIZE-1)]=event; + __asm__ volatile("":::"memory"); + mouse_event_head=head+1; + return 0; +} + +int bob64_mouse_irq_pop_event(BOB64_EVENT *event) { + u32 tail=mouse_event_tail,head=mouse_event_head; + if(!event||tail==head)return -1; + __asm__ volatile("":::"memory"); + *event=mouse_event_queue[tail&(MOUSE_EVENT_QUEUE_SIZE-1)]; + __asm__ volatile("":::"memory"); + mouse_event_tail=tail+1; + return 0; +} + +int bob64_mouse_irq_service(void) { + u8 status,value; + __asm__ volatile("inb $0x64,%0":"=a"(status)); + if(status==0xff||!(status&1)||!(status&0x20))return -1; + __asm__ volatile("inb $0x60,%0":"=a"(value)); + return bob64_mouse_irq_capture(value); +} + +static s32 signed_byte(u8 value) { + return value<128?(s32)value:(s32)value-256; +} + +int bob64_mouse_decode(BOB64_MOUSE_STATE *state,u8 value,BOB64_EVENT *event) { + u8 flags,buttons; + s32 dx,dy,wheel=0,old_x,old_y,new_x,new_y; + s64 proposed_x,proposed_y; + if(!state||!event||!state->Width||!state->Height)return -1; + if(!state->PacketLength&&!(value&8))return -1; + if(state->PacketSize!=3&&state->PacketSize!=4)return -1; + state->Packet[state->PacketLength++]=value; + if(state->PacketLengthPacketSize)return -1; + state->PacketLength=0; + flags=state->Packet[0];buttons=(u8)(flags&7); + if(state->PacketSize==4) { + u8 wheel_nibble=(u8)(state->Packet[3]&15); + wheel=(wheel_nibble&8)?(s32)wheel_nibble-16:(s32)wheel_nibble; + if(state->DeviceId==4)buttons|=(u8)((state->Packet[3]&0x30)>>1); + } + dx=(flags&0x40)?0:signed_byte(state->Packet[1]); + dy=(flags&0x80)?0:-signed_byte(state->Packet[2]); + old_x=state->X;old_y=state->Y; + proposed_x=(s64)old_x+dx;proposed_y=(s64)old_y+dy; + if(proposed_x<0)proposed_x=0; + if(proposed_y<0)proposed_y=0; + if((u64)proposed_x>=state->Width)proposed_x=(s64)state->Width-1; + if((u64)proposed_y>=state->Height)proposed_y=(s64)state->Height-1; + new_x=(s32)proposed_x;new_y=(s32)proposed_y; + state->X=new_x;state->Y=new_y; + if(new_x==old_x&&new_y==old_y&&buttons==state->Buttons&&!wheel)return -1; + event->Type=buttons!=state->Buttons?BOB64_EVENT_MOUSE_BUTTON: + wheel?BOB64_EVENT_MOUSE_WHEEL:BOB64_EVENT_MOUSE_MOVE; + event->Key=0;event->Character=0;event->Modifiers=0; + event->X=new_x;event->Y=new_y; + event->DeltaX=new_x-old_x;event->DeltaY=new_y-old_y; + event->Buttons=buttons;event->Wheel=wheel;event->WindowHandle=0; + event->ScreenX=state->X;event->ScreenY=state->Y; + state->Buttons=buttons; + return 0; +} + +int bob64_mouse_init(u32 width,u32 height) { + u8 device_id; + if(bob64_mouse_irq_queue_init(width,height))return -1; + if(wait_input_empty())return -1; + out8(0x64,0xa8); + if(send_mouse_byte(0xf4))return -1; + mouse_state.Enabled=1; + if(!set_sample_rate(200)&&!set_sample_rate(100)&&!set_sample_rate(80)&& + !send_mouse_byte(0xf2)&&!read_mouse_response(&device_id)&& + (device_id==3||device_id==4)) { + mouse_state.DeviceId=device_id; + mouse_state.PacketSize=4; + } + return 0; +} + +int bob64_mouse_poll_event(BOB64_EVENT *event) { + u8 status,value; + if(!event||!mouse_state.Enabled)return -1; + if(mouse_irq_active)return bob64_mouse_irq_pop_event(event); + status=in8(0x64); + if(status==0xff||!(status&1)||!(status&0x20))return -1; + value=in8(0x60); + return bob64_mouse_decode(&mouse_state,value,event); +} diff --git a/bob64/mouse.h b/bob64/mouse.h new file mode 100644 index 0000000..cb384e7 --- /dev/null +++ b/bob64/mouse.h @@ -0,0 +1,23 @@ +#ifndef BOB64_MOUSE_H +#define BOB64_MOUSE_H + +#include "event.h" + +typedef struct { + u32 Width,Height; + s32 X,Y; + u8 Packet[4]; + u8 PacketLength,PacketSize,Buttons,DeviceId,Enabled; +} BOB64_MOUSE_STATE; + +int bob64_mouse_reset(BOB64_MOUSE_STATE *state,u32 width,u32 height); +int bob64_mouse_decode(BOB64_MOUSE_STATE *state,u8 value,BOB64_EVENT *event); +int bob64_mouse_init(u32 width,u32 height); +int bob64_mouse_poll_event(BOB64_EVENT *event); +int bob64_mouse_irq_queue_init(u32 width,u32 height); +int bob64_mouse_irq_capture(u8 value); +int bob64_mouse_irq_service(void); +int bob64_mouse_irq_pop_event(BOB64_EVENT *event); +void bob64_mouse_irq_set_active(int active); + +#endif diff --git a/bob64/paging.c b/bob64/paging.c new file mode 100644 index 0000000..d996173 --- /dev/null +++ b/bob64/paging.c @@ -0,0 +1,272 @@ +#include "paging.h" + +#define BOB64_PAGE_LARGE 0x080ULL +#define BOB64_U64_MAX (~(u64)0) + +static int canonical_address(u64 address) { + u64 top=address>>48; + return ((address>>47)&1)?top==0xffffULL:top==0; +} + +static u64 physical_address_mask(u8 bits) { + return ((1ULL<52)return 0; + mask=physical_address_mask(bits); + return !(address&(BOB64_PAGE_SIZE-1))&&!(address&~mask); +} + +static u64 *table_entries(const BOB64_PAGE_TABLE *table,u64 physical) { + if(!table||!table->Access||!physical_page_valid(physical,table->PhysicalAddressBits))return 0; + return table->Access(table->Context,physical); +} + +int bob64_page_table_init(BOB64_PAGE_TABLE *table,u8 physical_address_bits, + BOB64_TABLE_ALLOCATE allocate,BOB64_TABLE_ACCESS access, + void *context) { + u64 root; + u64 *entries; + if(!table||!allocate||!access||physical_address_bits<36||physical_address_bits>52) + return BOB64_PAGING_INVALID; + root=allocate(context); + if(!root||!physical_page_valid(root,physical_address_bits))return BOB64_PAGING_NO_MEMORY; + entries=access(context,root); + if(!entries)return BOB64_PAGING_INVALID; + for(usize i=0;i<512;i++)entries[i]=0; + table->RootPhysical=root;table->PhysicalAddressBits=physical_address_bits; + table->Allocate=allocate;table->Access=access; + table->Context=context; + return 0; +} + +static int copy_table_page(BOB64_PAGE_TABLE *destination, + const BOB64_PAGE_TABLE *source,u64 source_physical, + u64 *destination_physical) { + u64 physical=destination->Allocate(destination->Context); + u64 *target; + if(!physical||!physical_page_valid(physical,destination->PhysicalAddressBits)) + return BOB64_PAGING_NO_MEMORY; + target=destination->Access(destination->Context,physical); + if(!target)return BOB64_PAGING_NO_MEMORY; + if(source_physical) { + u64 *original=table_entries(source,source_physical); + if(!original)return BOB64_PAGING_INVALID; + for(usize i=0;i<512;i++)target[i]=original[i]; + } else for(usize i=0;i<512;i++)target[i]=0; + *destination_physical=physical; + return 0; +} + +int bob64_page_table_clone_isolated(BOB64_PAGE_TABLE *destination, + const BOB64_PAGE_TABLE *source, + u64 isolated_base,u64 isolated_size) { + u64 *source_root,*destination_root,*source_pdpt,*destination_pdpt; + u64 *destination_pd,source_entry,new_pdpt,new_pd; + u64 end,last,base_page,end_page; + usize pml4_index,pdpt_index,first_pd,last_pd; + int result; + if(!destination||!source||!destination->RootPhysical||!source->RootPhysical|| + destination->RootPhysical==source->RootPhysical||!isolated_size|| + (isolated_base&((1ULL<<21)-1))|| + (isolated_size&((1ULL<<21)-1))||isolated_size>BOB64_U64_MAX-isolated_base) + return BOB64_PAGING_INVALID; + end=isolated_base+isolated_size;last=end-1; + if(!canonical_address(isolated_base)||!canonical_address(last)|| + (((isolated_base>>47)&1)!=((last>>47)&1))|| + ((isolated_base>>39)&0x1ff)!=((last>>39)&0x1ff)|| + ((isolated_base>>30)&0x1ff)!=((last>>30)&0x1ff)) + return BOB64_PAGING_INVALID; + source_root=table_entries(source,source->RootPhysical); + destination_root=table_entries(destination,destination->RootPhysical); + if(!source_root||!destination_root)return BOB64_PAGING_INVALID; + for(usize i=0;i<512;i++)destination_root[i]=source_root[i]; + pml4_index=(usize)((isolated_base>>39)&0x1ff); + pdpt_index=(usize)((isolated_base>>30)&0x1ff); + source_entry=source_root[pml4_index]; + result=copy_table_page(destination,source, + (source_entry&BOB64_PAGE_PRESENT)?source_entry&BOB64_PAGE_ADDRESS_MASK:0, + &new_pdpt); + if(result)return result; + destination_root[pml4_index]=new_pdpt| + ((source_entry&~BOB64_PAGE_ADDRESS_MASK)|BOB64_PAGE_PRESENT| + BOB64_PAGE_WRITE|BOB64_PAGE_USER); + destination_pdpt=destination->Access(destination->Context,new_pdpt); + if(!destination_pdpt)return BOB64_PAGING_INVALID; + source_pdpt=(source_entry&BOB64_PAGE_PRESENT)? + table_entries(source,source_entry&BOB64_PAGE_ADDRESS_MASK):0; + if((source_entry&BOB64_PAGE_PRESENT)&&!source_pdpt)return BOB64_PAGING_INVALID; + source_entry=source_pdpt?source_pdpt[pdpt_index]:0; + if((source_entry&BOB64_PAGE_PRESENT)&&(source_entry&BOB64_PAGE_LARGE)) + return BOB64_PAGING_INVALID; + result=copy_table_page(destination,source, + (source_entry&BOB64_PAGE_PRESENT)?source_entry&BOB64_PAGE_ADDRESS_MASK:0, + &new_pd); + if(result)return result; + destination_pdpt[pdpt_index]=new_pd| + ((source_entry&~BOB64_PAGE_ADDRESS_MASK)|BOB64_PAGE_PRESENT| + BOB64_PAGE_WRITE|BOB64_PAGE_USER); + destination_pd=destination->Access(destination->Context,new_pd); + if(!destination_pd)return BOB64_PAGING_INVALID; + if(source_entry&BOB64_PAGE_PRESENT) { + u64 *source_pd=table_entries(source,source_entry&BOB64_PAGE_ADDRESS_MASK); + if(!source_pd)return BOB64_PAGING_INVALID; + } + base_page=isolated_base>>21;end_page=end>>21; + first_pd=(usize)(base_page&0x1ff);last_pd=(usize)((end_page-1)&0x1ff); + if(first_pd>last_pd)return BOB64_PAGING_INVALID; + for(usize i=first_pd;i<=last_pd;i++)destination_pd[i]=0; + return 0; +} + +static int next_level(BOB64_PAGE_TABLE *table,u64 *parent,usize index,u64 **child) { + u64 entry=parent[index],physical; + if(entry&BOB64_PAGE_PRESENT) { + if(entry&BOB64_PAGE_LARGE)return BOB64_PAGING_INVALID; + physical=entry&BOB64_PAGE_ADDRESS_MASK; + *child=table_entries(table,physical); + return *child?0:BOB64_PAGING_INVALID; + } + physical=table->Allocate(table->Context); + if(!physical||!physical_page_valid(physical,table->PhysicalAddressBits)) + return BOB64_PAGING_NO_MEMORY; + *child=table_entries(table,physical); + if(!*child)return BOB64_PAGING_INVALID; + for(usize i=0;i<512;i++)(*child)[i]=0; + /* Parent permissions are permissive; leaf PTEs enforce user/write policy. */ + parent[index]=physical|BOB64_PAGE_PRESENT|BOB64_PAGE_WRITE|BOB64_PAGE_USER; + return 0; +} + +int bob64_page_map(BOB64_PAGE_TABLE *table,u64 virtual_address,u64 physical_address, + u64 flags) { + u64 *level,*next; + int result; + if(!table||!table->RootPhysical||!table->Allocate||!table->Access|| + !canonical_address(virtual_address)|| + (virtual_address&(BOB64_PAGE_SIZE-1))|| + !physical_page_valid(physical_address,table->PhysicalAddressBits)|| + (flags&~BOB64_PAGE_ALLOWED_FLAGS))return BOB64_PAGING_INVALID; + level=table_entries(table,table->RootPhysical); + if(!level)return BOB64_PAGING_INVALID; + result=next_level(table,level,(usize)((virtual_address>>39)&0x1ff),&next); + if(result)return result; + level=next; + result=next_level(table,level,(usize)((virtual_address>>30)&0x1ff),&next); + if(result)return result; + level=next; + result=next_level(table,level,(usize)((virtual_address>>21)&0x1ff),&next); + if(result)return result; + level=next; + usize index=(usize)((virtual_address>>12)&0x1ff); + if(level[index]&BOB64_PAGE_PRESENT)return BOB64_PAGING_ALREADY_MAPPED; + level[index]=physical_address|BOB64_PAGE_PRESENT|flags; + return 0; +} + +int bob64_page_map_range(BOB64_PAGE_TABLE *table,u64 virtual_address, + u64 physical_address,u64 byte_size,u64 flags) { + u64 offset,pages,span,last_delta,last_virtual,last_physical; + u64 virtual_page,physical_page; + if(!table||!byte_size)return BOB64_PAGING_INVALID; + offset=virtual_address&(BOB64_PAGE_SIZE-1); + if((physical_address&(BOB64_PAGE_SIZE-1))!=offset|| + byte_size>BOB64_U64_MAX-offset)return BOB64_PAGING_INVALID; + span=byte_size+offset; + if(span>BOB64_U64_MAX-(BOB64_PAGE_SIZE-1))return BOB64_PAGING_INVALID; + pages=(span+BOB64_PAGE_SIZE-1)/BOB64_PAGE_SIZE; + last_delta=(pages-1)*BOB64_PAGE_SIZE; + virtual_page=virtual_address&~(BOB64_PAGE_SIZE-1); + physical_page=physical_address&~(BOB64_PAGE_SIZE-1); + if(virtual_page>BOB64_U64_MAX-last_delta||physical_page>BOB64_U64_MAX-last_delta) + return BOB64_PAGING_INVALID; + last_virtual=virtual_page+last_delta; + last_physical=physical_page+last_delta; + if(!canonical_address(virtual_page)||!canonical_address(last_virtual)|| + (((virtual_page>>47)&1)!=((last_virtual>>47)&1))|| + !physical_page_valid(physical_page,table->PhysicalAddressBits)|| + !physical_page_valid(last_physical,table->PhysicalAddressBits)) + return BOB64_PAGING_INVALID; + for(u64 i=0;iRootPhysical||!table->Access||!leaf|| + !canonical_address(virtual_address)|| + (virtual_address&(BOB64_PAGE_SIZE-1)))return BOB64_PAGING_INVALID; + physical=table->RootPhysical; + for(usize depth=0;depth<3;depth++) { + level=table_entries(table,physical); + if(!level)return BOB64_PAGING_INVALID; + u64 entry=level[(virtual_address>>shifts[depth])&0x1ff]; + if(!(entry&BOB64_PAGE_PRESENT))return BOB64_PAGING_NOT_MAPPED; + if(entry&BOB64_PAGE_LARGE)return BOB64_PAGING_INVALID; + physical=entry&BOB64_PAGE_ADDRESS_MASK; + } + level=table_entries(table,physical); + if(!level)return BOB64_PAGING_INVALID; + *leaf=&level[(virtual_address>>12)&0x1ff]; + if(!(**leaf&BOB64_PAGE_PRESENT))return BOB64_PAGING_NOT_MAPPED; + return 0; +} + +/* Caller invalidates the TLB entry when changing a live address space. */ +int bob64_page_protect(BOB64_PAGE_TABLE *table,u64 virtual_address,u64 flags) { + u64 *leaf; + int result; + if(flags&~BOB64_PAGE_ALLOWED_FLAGS)return BOB64_PAGING_INVALID; + result=locate_leaf(table,virtual_address,&leaf); + if(result)return result; + *leaf=(*leaf&BOB64_PAGE_ADDRESS_MASK)|BOB64_PAGE_PRESENT|flags; + return 0; +} + +/* Caller invalidates the TLB entry when removing a live mapping. */ +int bob64_page_unmap(BOB64_PAGE_TABLE *table,u64 virtual_address, + u64 *physical_address,u64 *previous_flags) { + u64 *leaf,entry; + int result=locate_leaf(table,virtual_address,&leaf); + if(result)return result; + entry=*leaf;*leaf=0; + if(physical_address)*physical_address=entry&BOB64_PAGE_ADDRESS_MASK; + if(previous_flags)*previous_flags=entry&~BOB64_PAGE_ADDRESS_MASK; + return 0; +} + +int bob64_page_translate(const BOB64_PAGE_TABLE *table,u64 virtual_address, + u64 *physical_address,u64 *flags) { + static const u8 shifts[]={39,30,21,12}; + u64 physical,entry,*level; + int effective_user=1,effective_write=1,effective_nx=0; + if(!table||!table->RootPhysical||!physical_address||!canonical_address(virtual_address)) + return BOB64_PAGING_INVALID; + physical=table->RootPhysical; + for(usize depth=0;depth<4;depth++) { + level=table_entries(table,physical); + if(!level)return BOB64_PAGING_INVALID; + entry=level[(virtual_address>>shifts[depth])&0x1ff]; + if(!(entry&BOB64_PAGE_PRESENT))return 0; + if(depth<3&&(entry&BOB64_PAGE_LARGE))return BOB64_PAGING_INVALID; + if(!(entry&BOB64_PAGE_USER))effective_user=0; + if(!(entry&BOB64_PAGE_WRITE))effective_write=0; + if(entry&BOB64_PAGE_NX)effective_nx=1; + physical=entry&BOB64_PAGE_ADDRESS_MASK; + } + *physical_address=physical|(virtual_address&(BOB64_PAGE_SIZE-1)); + if(flags) { + *flags=entry&~BOB64_PAGE_ADDRESS_MASK; + if(!effective_user)*flags&=~BOB64_PAGE_USER; + if(!effective_write)*flags&=~BOB64_PAGE_WRITE; + if(effective_nx)*flags|=BOB64_PAGE_NX; + } + return 1; +} diff --git a/bob64/paging.h b/bob64/paging.h new file mode 100644 index 0000000..34df499 --- /dev/null +++ b/bob64/paging.h @@ -0,0 +1,51 @@ +#ifndef BOB64_PAGING_H +#define BOB64_PAGING_H + +#include "types.h" + +#define BOB64_PAGE_SIZE 4096ULL +#define BOB64_PAGE_PRESENT 0x001ULL +#define BOB64_PAGE_WRITE 0x002ULL +#define BOB64_PAGE_USER 0x004ULL +#define BOB64_PAGE_PWT 0x008ULL +#define BOB64_PAGE_PCD 0x010ULL +#define BOB64_PAGE_GLOBAL 0x100ULL +#define BOB64_PAGE_NX (1ULL<<63) +#define BOB64_PAGE_ADDRESS_MASK 0x000ffffffffff000ULL +#define BOB64_PAGE_ALLOWED_FLAGS (BOB64_PAGE_WRITE|BOB64_PAGE_USER|BOB64_PAGE_PWT|\ + BOB64_PAGE_PCD|BOB64_PAGE_GLOBAL|BOB64_PAGE_NX) +#define BOB64_PAGING_INVALID (-1) +#define BOB64_PAGING_NO_MEMORY (-2) +#define BOB64_PAGING_ALREADY_MAPPED (-3) +#define BOB64_PAGING_NOT_MAPPED (-4) + +/* Allocate returns a physical page; map returns its currently accessible address. */ +typedef u64 (*BOB64_TABLE_ALLOCATE)(void *context); +typedef u64 *(*BOB64_TABLE_ACCESS)(void *context,u64 physical_address); + +typedef struct { + u64 RootPhysical; + u8 PhysicalAddressBits; + BOB64_TABLE_ALLOCATE Allocate; + BOB64_TABLE_ACCESS Access; + void *Context; +} BOB64_PAGE_TABLE; + +int bob64_page_table_init(BOB64_PAGE_TABLE *table,u8 physical_address_bits, + BOB64_TABLE_ALLOCATE allocate,BOB64_TABLE_ACCESS access, + void *context); +/* Clone shared kernel mappings while replacing a 2 MiB-aligned user arena. */ +int bob64_page_table_clone_isolated(BOB64_PAGE_TABLE *destination, + const BOB64_PAGE_TABLE *source, + u64 isolated_base,u64 isolated_size); +int bob64_page_map(BOB64_PAGE_TABLE *table,u64 virtual_address,u64 physical_address, + u64 flags); +int bob64_page_map_range(BOB64_PAGE_TABLE *table,u64 virtual_address, + u64 physical_address,u64 byte_size,u64 flags); +int bob64_page_protect(BOB64_PAGE_TABLE *table,u64 virtual_address,u64 flags); +int bob64_page_unmap(BOB64_PAGE_TABLE *table,u64 virtual_address, + u64 *physical_address,u64 *previous_flags); +int bob64_page_translate(const BOB64_PAGE_TABLE *table,u64 virtual_address, + u64 *physical_address,u64 *flags); + +#endif diff --git a/bob64/process.c b/bob64/process.c new file mode 100644 index 0000000..d314759 --- /dev/null +++ b/bob64/process.c @@ -0,0 +1,188 @@ +#include "process.h" + +static usize bounded_length(const char *text,usize limit) { + usize length=0; + if(!text)return limit; + while(lengthAllocatePage|| + !operations->FreePage||!operations->MapPage||!operations->ProtectPage|| + !operations->UnmapPage|| + page_capacity>BOB64_PROCESS_PAGE_LIMIT)return -1; + process->Pages=page_storage;process->PageCapacity=page_capacity;process->PageCount=0; + process->Operations=*operations;process->EntryAddress=0;process->StartupAddress=0; + process->InitialStackPointer=0;process->Loaded=0; + return 0; +} + +static int map_page(BOB64_PROCESS *process,u64 virtual_address,u64 flags) { + u64 physical; + u8 *writable=0; + BOB64_PROCESS_PAGE *page; + if(process->PageCount>=process->PageCapacity)return -1; + physical=process->Operations.AllocatePage(process->Operations.Context); + if(!physical)return -1; + page=process->Pages+process->PageCount++; + page->VirtualAddress=virtual_address;page->PhysicalAddress=physical;page->Flags=flags; + page->WritableAddress=0;page->Allocated=1;page->Mapped=0; + if(process->Operations.MapPage(process->Operations.Context,virtual_address, + physical,flags,&writable))return -1; + page->WritableAddress=writable;page->Mapped=1; + if(!writable)return -1; + clear_bytes(writable,(usize)BOB64_PAGE_SIZE); + return 0; +} + +static BOB64_PROCESS_PAGE *find_page(BOB64_PROCESS *process,u64 virtual_address) { + u64 page_address=virtual_address&~(BOB64_PAGE_SIZE-1); + for(usize i=0;iPageCount;i++) + if(process->Pages[i].Mapped&&process->Pages[i].VirtualAddress==page_address) + return process->Pages+i; + return 0; +} + +static int write_virtual(BOB64_PROCESS *process,u64 address,const void *source, + usize length) { + const u8 *bytes=(const u8 *)source; + while(length) { + BOB64_PROCESS_PAGE *page=find_page(process,address); + usize offset=(usize)(address&(BOB64_PAGE_SIZE-1)); + usize part=(usize)BOB64_PAGE_SIZE-offset; + if(!page)return -1; + if(part>length)part=length; + copy_bytes(page->WritableAddress+offset,bytes,part); + bytes+=part;length-=part;address+=part; + } + return 0; +} + +static int prepare_arguments(BOB64_PROCESS *process,usize argument_count, + const char *const *arguments) { + u64 string_addresses[BOB64_PROCESS_MAX_ARGUMENTS]; + u64 cursor=BOB64_PROCESS_STACK_BASE+BOB64_PROCESS_STACK_SIZE; + u64 argv_address,startup_address,initial_rsp; + BOB64_APP_STARTUP startup; + u64 zero=0; + if(argument_count>BOB64_PROCESS_MAX_ARGUMENTS|| + (argument_count&&!arguments))return -1; + for(usize i=argument_count;i>0;i--) { + usize length=bounded_length(arguments[i-1],(usize)BOB64_PROCESS_STACK_SIZE); + if(length==(usize)BOB64_PROCESS_STACK_SIZE|| + (u64)length+1>cursor-BOB64_PROCESS_STACK_BASE)return -1; + cursor-=(u64)length+1;string_addresses[i-1]=cursor; + if(write_virtual(process,cursor,arguments[i-1],length)|| + write_virtual(process,cursor+length,"",1))return -1; + } + cursor&=~7ULL; + if((u64)(argument_count+1)*sizeof(u64)>cursor-BOB64_PROCESS_STACK_BASE)return -1; + cursor-=(u64)(argument_count+1)*sizeof(u64);argv_address=cursor; + for(usize i=0;icursor-BOB64_PROCESS_STACK_BASE)return -1; + cursor-=sizeof(startup);startup_address=cursor; + startup.StructSize=(u32)sizeof(startup);startup.AbiVersion=BOB64_APP_ABI_VERSION; + startup.ArgumentCount=(u64)argument_count; + startup.Arguments=(const char *const *)(uintptr_t)argv_address; + startup.Flags=0; + if(write_virtual(process,startup_address,&startup,sizeof(startup)))return -1; + cursor&=~15ULL; + if(cursorStartupAddress=startup_address;process->InitialStackPointer=initial_rsp; + return 0; +} + +int bob64_process_load(BOB64_PROCESS *process,const void *file,usize file_size, + usize argument_count,const char *const *arguments) { + BOB64_EXEC_IMAGE parsed; + const BOB64_EXEC_IMAGE *image=&parsed; + usize image_pages; + if(!process||process->Loaded||process->PageCount|| + !process->Pages||!process->Operations.NxSupported|| + bob64_exec_parse(file,file_size,&parsed)|| + !image->Image||image->AbiVersion!=BOB64_APP_ABI_VERSION||image->Flags|| + !image->CodeSize||(image->CodeSize&(BOB64_PAGE_SIZE-1))|| + image->CodeSize>image->FileSize||image->FileSize>image->MemorySize|| + !image->MemorySize||image->MemorySize>BOB64_PROCESS_IMAGE_LIMIT|| + image->EntryOffset>=image->CodeSize|| + image->MemorySize>~(u64)0-BOB64_PROCESS_IMAGE_BASE|| + argument_count>BOB64_PROCESS_MAX_ARGUMENTS|| + process->PageCapacityMemorySize+BOB64_PAGE_SIZE-1)/BOB64_PAGE_SIZE) + return -1; + image_pages=(usize)((image->MemorySize+BOB64_PAGE_SIZE-1)/BOB64_PAGE_SIZE); + for(usize page=0;pageFileSize;) { + usize page=(usize)(offset/BOB64_PAGE_SIZE); + usize in_page=(usize)(offset&(BOB64_PAGE_SIZE-1)); + usize part=(usize)BOB64_PAGE_SIZE-in_page; + if((u64)part>image->FileSize-offset)part=(usize)(image->FileSize-offset); + copy_bytes(process->Pages[page].WritableAddress+in_page,image->Image+(usize)offset,part); + offset+=part; + } + for(usize page=0;page<(usize)(image->CodeSize/BOB64_PAGE_SIZE);page++) { + BOB64_PROCESS_PAGE *record=process->Pages+page; + if(process->Operations.ProtectPage(process->Operations.Context, + record->VirtualAddress,BOB64_PAGE_USER))goto fail; + record->Flags=BOB64_PAGE_USER; + } + for(usize page=0;pageEntryAddress=BOB64_PROCESS_IMAGE_BASE+image->EntryOffset; + process->Loaded=1; + return 0; +fail: + bob64_process_unload(process); + return -1; +} + +int bob64_process_unload(BOB64_PROCESS *process) { + int result=0; + if(!process||!process->Pages)return -1; + for(usize i=process->PageCount;i>0;i--) { + BOB64_PROCESS_PAGE *page=process->Pages+(i-1); + if(page->Mapped) { + if(process->Operations.UnmapPage(process->Operations.Context,page->VirtualAddress)) { + result=-1;continue; + } + page->Mapped=0;page->WritableAddress=0; + } + if(page->Allocated) { + if(process->Operations.FreePage(process->Operations.Context,page->PhysicalAddress)) { + result=-1;continue; + } + page->Allocated=0; + } + } + usize remaining=0; + for(usize i=0;iPageCount;i++) + if(process->Pages[i].Mapped||process->Pages[i].Allocated) + process->Pages[remaining++]=process->Pages[i]; + process->PageCount=remaining; + if(!remaining) { + process->Loaded=0;process->EntryAddress=0;process->StartupAddress=0; + process->InitialStackPointer=0; + } + return result; +} diff --git a/bob64/process.h b/bob64/process.h new file mode 100644 index 0000000..508716c --- /dev/null +++ b/bob64/process.h @@ -0,0 +1,63 @@ +#ifndef BOB64_PROCESS_H +#define BOB64_PROCESS_H + +#include "abi.h" +#include "exec.h" +#include "paging.h" + +#define BOB64_PROCESS_IMAGE_BASE 0x0000004000000000ULL +#define BOB64_PROCESS_IMAGE_LIMIT (16ULL*1024ULL*1024ULL) +#define BOB64_PROCESS_STACK_GUARD (BOB64_PROCESS_IMAGE_BASE+0x02000000ULL) +#define BOB64_PROCESS_STACK_BASE (BOB64_PROCESS_STACK_GUARD+BOB64_PAGE_SIZE) +#define BOB64_PROCESS_STACK_SIZE (64ULL*1024ULL) +#define BOB64_PROCESS_ISOLATED_SIZE (34ULL*1024ULL*1024ULL) +#define BOB64_PROCESS_PAGE_LIMIT ((BOB64_PROCESS_IMAGE_LIMIT/BOB64_PAGE_SIZE)+\ + (BOB64_PROCESS_STACK_SIZE/BOB64_PAGE_SIZE)) +#define BOB64_PROCESS_MAX_ARGUMENTS 128 + +typedef u64 (*BOB64_PROCESS_ALLOCATE_PAGE)(void *context); +typedef int (*BOB64_PROCESS_FREE_PAGE)(void *context,u64 physical_address); +/* Map failure must leave the VA unmapped; writable_address is a kernel alias. */ +typedef int (*BOB64_PROCESS_MAP_PAGE)(void *context,u64 virtual_address, + u64 physical_address,u64 flags, + u8 **writable_address); +/* Protect/unmap callbacks invalidate the active address-space TLB entry. */ +typedef int (*BOB64_PROCESS_PROTECT_PAGE)(void *context,u64 virtual_address,u64 flags); +typedef int (*BOB64_PROCESS_UNMAP_PAGE)(void *context,u64 virtual_address); + +typedef struct { + BOB64_PROCESS_ALLOCATE_PAGE AllocatePage; + BOB64_PROCESS_FREE_PAGE FreePage; + BOB64_PROCESS_MAP_PAGE MapPage; + BOB64_PROCESS_PROTECT_PAGE ProtectPage; + BOB64_PROCESS_UNMAP_PAGE UnmapPage; + void *Context; + u8 NxSupported; +} BOB64_PROCESS_OPERATIONS; + +typedef struct { + u64 VirtualAddress; + u64 PhysicalAddress; + u64 Flags; + u8 *WritableAddress; + u8 Allocated; + u8 Mapped; + u8 Reserved[6]; +} BOB64_PROCESS_PAGE; + +typedef struct { + BOB64_PROCESS_PAGE *Pages; + usize PageCapacity,PageCount; + BOB64_PROCESS_OPERATIONS Operations; + u64 EntryAddress,StartupAddress,InitialStackPointer; + u8 Loaded; +} BOB64_PROCESS; + +int bob64_process_init(BOB64_PROCESS *process,BOB64_PROCESS_PAGE *page_storage, + usize page_capacity,const BOB64_PROCESS_OPERATIONS *operations); +/* Parse an untrusted B64E file before allocating any application pages. */ +int bob64_process_load(BOB64_PROCESS *process,const void *file,usize file_size, + usize argument_count,const char *const *arguments); +int bob64_process_unload(BOB64_PROCESS *process); + +#endif diff --git a/bob64/runtime.h b/bob64/runtime.h new file mode 100644 index 0000000..17b00af --- /dev/null +++ b/bob64/runtime.h @@ -0,0 +1,14 @@ +#ifndef BOB64_RUNTIME_H +#define BOB64_RUNTIME_H + +#include "memory.h" +#include "bootstrap.h" +#include "descriptors.h" + +/* Boot-owned state remains in the mapped EFI image and is adopted after EBS. */ +extern BOB64_PAGE_EXTENT bob64_boot_page_extents[BOB64_PAGE_EXTENT_LIMIT]; +extern BOB64_PAGE_ALLOCATOR bob64_boot_page_allocator; +extern BOB64_BOOTSTRAP_SPACE bob64_bootstrap_space; +extern BOB64_TSS bob64_kernel_tss; + +#endif diff --git a/bob64/shell.c b/bob64/shell.c new file mode 100644 index 0000000..442d90d --- /dev/null +++ b/bob64/shell.c @@ -0,0 +1,286 @@ +#include "shell.h" + +static void output(BOB64_SHELL *shell,const char *text) { + shell->Write(shell->Context,text); +} + +static char lower_ascii(char value) { + if(value>='A'&&value<='Z')return (char)(value-'A'+'a'); + return value; +} + +static int equals(const char *left,const char *right) { + while(*left&&*right&&lower_ascii(*left)==*right){left++;right++;} + return !*left&&!*right; +} + +static void print_hex64(BOB64_SHELL *shell,u64 value) { + static const char digits[]="0123456789abcdef"; + char text[17]; + for(u32 i=0;i<16;i++)text[i]=digits[(value>>(60-i*4))&15]; + text[16]=0;output(shell,text); +} + +static void print_decimal(BOB64_SHELL *shell,usize value) { + char text[21];usize length=0; + do {text[length++]=(char)('0'+value%10);value/=10;} while(value&&lengthPageAllocator; + if(allocator) { + for(usize i=0;iCount;i++)free_pages+=allocator->Extents[i].Pages; + for(usize i=0;iAllocatedCount;i++) + allocated_pages+=allocator->Allocated[i].Pages; + } + output(shell,"free pages=0x");print_hex64(shell,free_pages);output(shell,"\r\n"); + output(shell,"allocated pages=0x");print_hex64(shell,allocated_pages);output(shell,"\r\n"); + output(shell,"heap mapped=0x"); + print_hex64(shell,(u64)bob64_heap_mapped_bytes(shell->Heap));output(shell," bytes\r\n"); +} + +static void print_file_data(BOB64_SHELL *shell,const char *data,usize length) { + static const char digits[]="0123456789abcdef"; + char character[2]={0,0},escaped[5]={'\\','x','0','0',0}; + for(usize i=0;i=32&&value<=126)||value=='\r'||value=='\n'||value=='\t') { + character[0]=(char)value;output(shell,character); + } else { + escaped[2]=digits[value>>4];escaped[3]=digits[value&15]; + output(shell,escaped); + } + } +} + +static void run_file_command(BOB64_SHELL *shell,char *arguments) { + char *argv[BOB64_SHELL_ARGUMENT_LIMIT]; + usize argc=0; + char *cursor=arguments; + int started=0; + if(!shell->Run) {output(shell,"app execution unavailable\r\n");return;} + while(*cursor==' ')cursor++; + if(!*cursor) {output(shell,"usage: run NAME [ARG ...]\r\n");return;} + while(*cursor) { + if(argc==BOB64_SHELL_ARGUMENT_LIMIT) { + output(shell,"too many arguments\r\n");return; + } + argv[argc++]=cursor; + while(*cursor&&*cursor!=' ')cursor++; + if(*cursor)*cursor++=0; + while(*cursor==' ')cursor++; + } + s64 status=shell->Run(shell->Context,argv[0],argc, + (const char *const *)argv,&started); + if(!started) {output(shell,"unable to start application\r\n");return;} + output(shell,"application exit status=0x"); + print_hex64(shell,(u64)status);output(shell,"\r\n"); +} + +static void compile_file_command(BOB64_SHELL *shell,char *arguments) { + char source[BOB64_FS_NAME_CAPACITY],destination[BOB64_FS_NAME_CAPACITY]; + usize source_length=0,destination_length=0,error_offset=0; + char *cursor=arguments; + int result; + while(*cursor==' ')cursor++; + while(cursor[source_length]&&cursor[source_length]!=' '&& + source_lengthCompile) {output(shell,"C compiler unavailable\r\n");return;} + result=shell->Compile(shell->Context,source,destination,&error_offset); + if(result==-2) { + output(shell,"C compile error near character ");print_decimal(shell,error_offset); + output(shell,". Supports int main(void), helper calls, void/char returns, pointers, and bob64_app_write.\r\n"); + } else if(result)output(shell,"C compile failed; check source and free filesystem space\r\n"); + else {output(shell,"compiled to ");output(shell,destination);output(shell,"\r\n");} +} + +static int list_file(void *context,const char *name,usize length) { + BOB64_SHELL *shell=(BOB64_SHELL *)context; + output(shell,name);output(shell," 0x");print_hex64(shell,(u64)length); + output(shell," bytes\r\n"); + return 0; +} + +static usize text_length(const char *text) { + usize length=0; + while(text[length])length++; + return length; +} + +static void execute_file_command(BOB64_SHELL *shell,u8 operation,char *arguments) { + BOB64_FILESYSTEM *filesystem=shell->Filesystem; + char *name=arguments,*separator=arguments,*contents_argument; + const char *contents; + usize length; + if(!filesystem) { output(shell,"filesystem unavailable\r\n");return; } + if(operation==0) { + if(!bob64_fs_list(filesystem,list_file,shell))output(shell,"no files\r\n"); + return; + } + while(*name==' ')name++; + separator=name; + while(*separator&&*separator!=' ')separator++; + contents_argument=separator; + if(*separator) { + *separator++=0; + while(*separator==' ')separator++; + } + if(!*name||((operation==1||operation==3)&&*contents_argument)) { + output(shell,"usage: cat NAME | write NAME TEXT | rm NAME\r\n");return; + } + if(operation==1) { + if(bob64_fs_read(filesystem,name,&contents,&length)) { + output(shell,"file not found\r\n");return; + } + print_file_data(shell,contents,length);output(shell,"\r\n");return; + } + if(operation==2) { + if(bob64_fs_write(filesystem,name,separator,text_length(separator))) + output(shell,"write failed (name/data invalid or heap full)\r\n"); + else output(shell,"saved\r\n"); + return; + } + if(bob64_fs_delete(filesystem,name))output(shell,"file not found\r\n"); + else output(shell,"deleted\r\n"); +} + +static void execute(BOB64_SHELL *shell) { + char *line=shell->Line; + if(!shell->Length)return; + line[shell->Length]=0; + if(equals(line,"help")) { + output(shell,"help show commands\r\nclear clear screen\r\nmem physical memory and heap\r\n"); + output(shell,"heap heap usage\r\nls list files\r\ncat NAME read a file\r\n"); + output(shell,"write NAME TEXT save text\r\nrm NAME delete a file\r\n"); + output(shell,"run NAME [ARG ...] launch a B64E application (try bob.b64e)\r\n"); + output(shell,"run desktop.b64e [FILE] edit a RAM text file in the GUI\r\n"); + output(shell,"cc SOURCE [OUTPUT] compile supported C to B64E (try bob.c)\r\n"); + output(shell,"save checkpoint files in RAM\r\nrestore restore RAM checkpoint\r\n"); + output(shell,"echo print text\r\nversion show kernel version\r\n"); + } else if(equals(line,"clear")) { + if(shell->Clear)shell->Clear(shell->Context); + output(shell,"bob64! kernel shell\r\n"); + } else if(equals(line,"mem"))print_memory(shell); + else if(equals(line,"heap")) { + output(shell,"heap mapped=0x"); + print_hex64(shell,(u64)bob64_heap_mapped_bytes(shell->Heap)); + output(shell," bytes\r\n"); + } else if(equals(line,"version"))output(shell,"bob64 kernel 0.1\r\n"); + else if(equals(line,"save")) { + usize size,written; + if(bob64_fs_snapshot_size(shell->Filesystem,&size)) { + output(shell,"snapshot size failed\r\n");return; + } + void *snapshot=bob64_heap_alloc(shell->Heap,size); + if(!snapshot||bob64_fs_snapshot_write(shell->Filesystem,snapshot,size,&written)) { + if(snapshot)bob64_heap_free(shell->Heap,snapshot); + output(shell,"snapshot save failed (heap full)\r\n");return; + } + if(shell->Snapshot)bob64_heap_free(shell->Heap,shell->Snapshot); + shell->Snapshot=snapshot;shell->SnapshotSize=written; + output(shell,"saved B64S v1 checkpoint in RAM; lost on reboot\r\n"); + } else if(equals(line,"restore")) { + if(!shell->Snapshot||bob64_fs_snapshot_restore(shell->Filesystem, + shell->Snapshot,shell->SnapshotSize)) { + output(shell,"restore failed; files unchanged\r\n");return; + } + output(shell,"restored B64S v1 checkpoint\r\n"); + } + else if(equals(line,"ls"))execute_file_command(shell,0,line+2); + else if(shell->Length>4&&lower_ascii(line[0])=='c'&& + lower_ascii(line[1])=='a'&&lower_ascii(line[2])=='t'&&line[3]==' ') + execute_file_command(shell,1,line+4); + else if(shell->Length>6&&lower_ascii(line[0])=='w'&& + lower_ascii(line[1])=='r'&&lower_ascii(line[2])=='i'&& + lower_ascii(line[3])=='t'&&lower_ascii(line[4])=='e'&&line[5]==' ') + execute_file_command(shell,2,line+6); + else if(shell->Length>3&&lower_ascii(line[0])=='r'&& + lower_ascii(line[1])=='m'&&line[2]==' ') + execute_file_command(shell,3,line+3); + else if(shell->Length>4&&lower_ascii(line[0])=='r'&& + lower_ascii(line[1])=='u'&&lower_ascii(line[2])=='n'&&line[3]==' ') + run_file_command(shell,line+4); + else if(shell->Length>3&&lower_ascii(line[0])=='c'&& + lower_ascii(line[1])=='c'&&line[2]==' ') + compile_file_command(shell,line+3); + else if(shell->Length>=5&&lower_ascii(line[0])=='e'&& + lower_ascii(line[1])=='c'&&lower_ascii(line[2])=='h'&& + lower_ascii(line[3])=='o'&&line[4]==' ') { + output(shell,line+5);output(shell,"\r\n"); + } else { + output(shell,"unknown command: ");output(shell,line);output(shell,"\r\n"); + } +} + +static void prompt(BOB64_SHELL *shell) { + output(shell,"bob64> "); +} + +int bob64_shell_init(BOB64_SHELL *shell,BOB64_PAGE_ALLOCATOR *allocator, + BOB64_HEAP *heap,BOB64_FILESYSTEM *filesystem, + BOB64_SHELL_WRITE write, + BOB64_SHELL_CLEAR clear,void *context) { + if(!shell||!write)return -1; + shell->Length=0;shell->IgnoreLineFeed=0;shell->Line[0]=0; + shell->PageAllocator=allocator;shell->Heap=heap;shell->Filesystem=filesystem; + shell->Snapshot=0;shell->SnapshotSize=0; + shell->Write=write;shell->Clear=clear;shell->Context=context; + shell->Run=0; + shell->Compile=0; + output(shell,"bob64! kernel shell; type help\r\n");prompt(shell); + return 0; +} + +void bob64_shell_set_runner(BOB64_SHELL *shell,BOB64_SHELL_RUN run) { + if(shell)shell->Run=run; +} + +void bob64_shell_set_compiler(BOB64_SHELL *shell,BOB64_SHELL_COMPILE compile) { + if(shell)shell->Compile=compile; +} + +void bob64_shell_input(BOB64_SHELL *shell,int character) { + char echo[2]; + if(!shell||!shell->Write||character<0)return; + if(character=='\n'&&shell->IgnoreLineFeed) { shell->IgnoreLineFeed=0;return; } + shell->IgnoreLineFeed=(u8)(character=='\r'); + if(character=='\r'||character=='\n') { + output(shell,"\r\n");execute(shell);shell->Length=0;shell->Line[0]=0; + prompt(shell);return; + } + if(character=='\b'||character==0x7f) { + if(shell->Length) { + shell->Length--;shell->Line[shell->Length]=0; + output(shell,"\b \b"); + } + return; + } + if(character<32||character>126||shell->Length>=BOB64_SHELL_LINE_CAPACITY-1)return; + shell->Line[shell->Length++]=(char)character; + shell->Line[shell->Length]=0; + echo[0]=(char)character;echo[1]=0;output(shell,echo); +} diff --git a/bob64/shell.h b/bob64/shell.h new file mode 100644 index 0000000..6ecf4c2 --- /dev/null +++ b/bob64/shell.h @@ -0,0 +1,40 @@ +#ifndef BOB64_SHELL_H +#define BOB64_SHELL_H + +#include "filesystem.h" +#include "snapshot.h" + +#define BOB64_SHELL_LINE_CAPACITY 128 +#define BOB64_SHELL_ARGUMENT_LIMIT 16 +typedef void (*BOB64_SHELL_WRITE)(void *context,const char *text); +typedef void (*BOB64_SHELL_CLEAR)(void *context); +typedef s64 (*BOB64_SHELL_RUN)(void *context,const char *name,usize argument_count, + const char *const *arguments,int *started); +typedef int (*BOB64_SHELL_COMPILE)(void *context,const char *source_name, + const char *output_name,usize *error_offset); + +typedef struct { + char Line[BOB64_SHELL_LINE_CAPACITY]; + usize Length; + u8 IgnoreLineFeed; + BOB64_PAGE_ALLOCATOR *PageAllocator; + BOB64_HEAP *Heap; + BOB64_FILESYSTEM *Filesystem; + void *Snapshot; + usize SnapshotSize; + BOB64_SHELL_WRITE Write; + BOB64_SHELL_CLEAR Clear; + BOB64_SHELL_RUN Run; + BOB64_SHELL_COMPILE Compile; + void *Context; +} BOB64_SHELL; + +int bob64_shell_init(BOB64_SHELL *shell,BOB64_PAGE_ALLOCATOR *allocator, + BOB64_HEAP *heap,BOB64_FILESYSTEM *filesystem, + BOB64_SHELL_WRITE write, + BOB64_SHELL_CLEAR clear,void *context); +void bob64_shell_input(BOB64_SHELL *shell,int character); +void bob64_shell_set_runner(BOB64_SHELL *shell,BOB64_SHELL_RUN run); +void bob64_shell_set_compiler(BOB64_SHELL *shell,BOB64_SHELL_COMPILE compile); + +#endif diff --git a/bob64/snapshot.c b/bob64/snapshot.c new file mode 100644 index 0000000..a0113c5 --- /dev/null +++ b/bob64/snapshot.c @@ -0,0 +1,147 @@ +#include "snapshot.h" + +#define BOB64_SNAPSHOT_RECORD_HEADER_SIZE 12u +#define BOB64_SNAPSHOT_CHECKSUM_OFFSET 20u + +static u16 read16(const u8 *bytes) { + return (u16)((u16)bytes[0]|((u16)bytes[1]<<8)); +} + +static u32 read32(const u8 *bytes) { + return (u32)bytes[0]|((u32)bytes[1]<<8)|((u32)bytes[2]<<16)|((u32)bytes[3]<<24); +} + +static u64 read64(const u8 *bytes) { + return (u64)read32(bytes)|((u64)read32(bytes+4)<<32); +} + +static void write16(u8 *bytes,u16 value) { + bytes[0]=(u8)value;bytes[1]=(u8)(value>>8); +} + +static void write32(u8 *bytes,u32 value) { + for(u32 i=0;i<4;i++)bytes[i]=(u8)(value>>(i*8)); +} + +static void write64(u8 *bytes,u64 value) { + write32(bytes,(u32)value);write32(bytes+4,(u32)(value>>32)); +} + +static usize name_length(const char *name) { + usize length=0; + while(name[length])length++; + return length; +} + +static u32 snapshot_checksum(const u8 *bytes,usize length) { + u32 value=0xffffffffu; + for(usize i=0;i=BOB64_SNAPSHOT_CHECKSUM_OFFSET&& + i>1)^(0xedb88320u&-(value&1u)); + } + return ~value; +} + +int bob64_fs_snapshot_size(const BOB64_FILESYSTEM *filesystem,usize *size) { + usize total=BOB64_SNAPSHOT_HEADER_SIZE,count=0; + if(!filesystem||!size)return -1; + for(BOB64_FS_FILE *file=filesystem->First;file;file=file->Next) { + usize name_size=name_length(file->Name); + if(!name_size||name_size>=BOB64_FS_NAME_CAPACITY|| + total>~(usize)0-BOB64_SNAPSHOT_RECORD_HEADER_SIZE-name_size|| + file->Length>~(usize)0-total-BOB64_SNAPSHOT_RECORD_HEADER_SIZE-name_size) + return -1; + total+=BOB64_SNAPSHOT_RECORD_HEADER_SIZE+name_size+file->Length; + if(count==0xffffffffu)return -1; + count++; + } + if(count!=filesystem->FileCount)return -1; + *size=total; + return 0; +} + +int bob64_fs_snapshot_write(const BOB64_FILESYSTEM *filesystem, + void *output,usize capacity,usize *written) { + usize required,offset=BOB64_SNAPSHOT_HEADER_SIZE; + u8 *bytes=(u8 *)output; + if(!output||!written||bob64_fs_snapshot_size(filesystem,&required)||capacityFileCount); + write32(bytes+BOB64_SNAPSHOT_CHECKSUM_OFFSET,0); + for(BOB64_FS_FILE *file=filesystem->First;file;file=file->Next) { + usize name_size=name_length(file->Name); + write16(bytes+offset,(u16)name_size);write16(bytes+offset+2,0); + write64(bytes+offset+4,(u64)file->Length);offset+=BOB64_SNAPSHOT_RECORD_HEADER_SIZE; + for(usize i=0;iName[i]; + offset+=name_size; + for(usize i=0;iLength;i++)bytes[offset+i]=(u8)file->Data[i]; + offset+=file->Length; + } + if(offset!=required)return -1; + write32(bytes+BOB64_SNAPSHOT_CHECKSUM_OFFSET,snapshot_checksum(bytes,required)); + *written=required; + return 0; +} + +static int clear_filesystem(BOB64_FILESYSTEM *filesystem) { + while(filesystem->First) { + char name[BOB64_FS_NAME_CAPACITY]; + usize length=name_length(filesystem->First->Name); + if(!length||length>=sizeof(name))return -1; + for(usize i=0;iFirst->Name[i]; + name[length]=0; + if(bob64_fs_delete(filesystem,name))return -1; + } + return 0; +} + +int bob64_fs_snapshot_restore(BOB64_FILESYSTEM *filesystem, + const void *snapshot,usize snapshot_size) { + const u8 *bytes=(const u8 *)snapshot; + BOB64_FILESYSTEM replacement,old; + usize offset=BOB64_SNAPSHOT_HEADER_SIZE; + u32 file_count; + if(!filesystem||!filesystem->Heap||!bytes||snapshot_size((u64)snapshot_size-BOB64_SNAPSHOT_HEADER_SIZE)/ + BOB64_SNAPSHOT_RECORD_HEADER_SIZE||bob64_fs_init(&replacement,filesystem->Heap)) + return -1; + for(u32 i=0;isnapshot_size||snapshot_size-offset=sizeof(name))goto invalid; + data_size=read64(bytes+offset+4);offset+=BOB64_SNAPSHOT_RECORD_HEADER_SIZE; + if((u64)name_size>(u64)snapshot_size-offset)goto invalid; + for(usize n=0;n(u64)snapshot_size-offset)goto invalid; + usize previous_count=replacement.FileCount; + if(bob64_fs_write(&replacement,name,bytes+offset,(usize)data_size)|| + replacement.FileCount!=previous_count+1)goto invalid; + offset+=(usize)data_size; + } + if(offset!=snapshot_size)goto invalid; + old=*filesystem;*filesystem=replacement; + if(clear_filesystem(&old))return -1; + return 0; +invalid: + clear_filesystem(&replacement); + return -1; +} diff --git a/bob64/snapshot.h b/bob64/snapshot.h new file mode 100644 index 0000000..ac4b7c1 --- /dev/null +++ b/bob64/snapshot.h @@ -0,0 +1,15 @@ +#ifndef BOB64_SNAPSHOT_H +#define BOB64_SNAPSHOT_H + +#include "filesystem.h" + +#define BOB64_SNAPSHOT_VERSION 1 +#define BOB64_SNAPSHOT_HEADER_SIZE 24 + +int bob64_fs_snapshot_size(const BOB64_FILESYSTEM *filesystem,usize *size); +int bob64_fs_snapshot_write(const BOB64_FILESYSTEM *filesystem, + void *output,usize capacity,usize *written); +int bob64_fs_snapshot_restore(BOB64_FILESYSTEM *filesystem, + const void *snapshot,usize snapshot_size); + +#endif diff --git a/bob64/syscall.c b/bob64/syscall.c new file mode 100644 index 0000000..b1a1cfc --- /dev/null +++ b/bob64/syscall.c @@ -0,0 +1,545 @@ +#include "syscall.h" +#include "process.h" +#include "console.h" + +volatile u64 bob64_user_active; +volatile u64 bob64_user_depth; +BOB64_USER_RETURN_FRAME bob64_user_return_frames[BOB64_USER_ENTRY_MAX_DEPTH]; +volatile s64 bob64_user_return_value; +#define BOB64_SYSCALL_OPEN_HANDLES 16 +#define BOB64_SYSCALL_CONTEXT_DEPTH BOB64_SYSCALL_CONTEXT_MAX_DEPTH +typedef struct { + u64 Id,Position; + u32 Flags; + char Name[BOB64_SYSCALL_MAX_FILENAME+1]; +} BOB64_SYSCALL_HANDLE; +typedef struct { + BOB64_SYSCALL_WRITE WriteCharacter; + void *WriteContext; + BOB64_SYSCALL_READ_USER ReadUser; + void *ReadUserContext; + BOB64_SYSCALL_WRITE_USER WriteUser; + void *WriteUserContext; + BOB64_SYSCALL_FILE_READ FileRead; + BOB64_SYSCALL_FILE_WRITE FileWrite; + void *FilesystemContext; + BOB64_SYSCALL_FILE_LIST FileList; + BOB64_SYSCALL_FILE_DELETE FileDelete; + void *FileManagerContext; + BOB64_SYSCALL_FILE_OPEN FileOpen; + BOB64_SYSCALL_FILE_READ_AT FileReadAt; + BOB64_SYSCALL_FILE_WRITE_AT FileWriteAt; + void *FileStreamContext; + BOB64_SYSCALL_EVENT_WAIT WaitEvent; + void *WaitEventContext; + BOB64_WINDOW_SERVER *WindowServer; + u64 WindowOwner; + const BOB64_PAGE_TABLE *PageTable; + u32 SurfaceChunk[BOB64_SYSCALL_COPY_CHUNK_BYTES/sizeof(u32)]; + u8 Buffer[BOB64_SYSCALL_MAX_BUFFER]; + BOB64_FILE_INFO FileEntries[BOB64_SYSCALL_MAX_FILES]; + BOB64_SYSCALL_HANDLE Handles[BOB64_SYSCALL_OPEN_HANDLES]; + u64 NextHandle; +} BOB64_SYSCALL_CONTEXT; + +/* Keep per-app dispatch state, scratch buffers, and streaming handles together. */ +static BOB64_SYSCALL_CONTEXT syscall_context={.NextHandle=1}; +static BOB64_SYSCALL_CONTEXT syscall_context_stack[BOB64_SYSCALL_CONTEXT_DEPTH]; +static u32 syscall_context_depth; +#define syscall_write_character syscall_context.WriteCharacter +#define syscall_write_context syscall_context.WriteContext +#define syscall_read_user syscall_context.ReadUser +#define syscall_read_user_context syscall_context.ReadUserContext +#define syscall_write_user syscall_context.WriteUser +#define syscall_write_user_context syscall_context.WriteUserContext +#define syscall_file_read syscall_context.FileRead +#define syscall_file_write syscall_context.FileWrite +#define syscall_filesystem_context syscall_context.FilesystemContext +#define syscall_file_list syscall_context.FileList +#define syscall_file_delete syscall_context.FileDelete +#define syscall_file_manager_context syscall_context.FileManagerContext +#define syscall_file_open syscall_context.FileOpen +#define syscall_file_read_at syscall_context.FileReadAt +#define syscall_file_write_at syscall_context.FileWriteAt +#define syscall_file_stream_context syscall_context.FileStreamContext +#define syscall_wait_event syscall_context.WaitEvent +#define syscall_wait_event_context syscall_context.WaitEventContext +#define syscall_window_server syscall_context.WindowServer +#define syscall_window_owner syscall_context.WindowOwner +#define syscall_page_table syscall_context.PageTable +#define syscall_surface_chunk syscall_context.SurfaceChunk +#define syscall_buffer syscall_context.Buffer +#define syscall_file_entries syscall_context.FileEntries +#define syscall_handles syscall_context.Handles +#define syscall_next_handle syscall_context.NextHandle + +static void copy_context(BOB64_SYSCALL_CONTEXT *destination, + const BOB64_SYSCALL_CONTEXT *source) { + u8 *out=(u8 *)destination; + const u8 *in=(const u8 *)source; + for(usize i=0;i=BOB64_SYSCALL_CONTEXT_DEPTH)return -1; + copy_context(&syscall_context_stack[syscall_context_depth],&syscall_context); + syscall_context_depth++; + return 0; +} + +int bob64_syscall_context_pop(void) { + if(!syscall_context_depth)return -1; + syscall_context_depth--; + copy_context(&syscall_context, + &syscall_context_stack[syscall_context_depth]); + return 0; +} + +void bob64_user_request_return(s64 value) { + if(bob64_user_depth&&bob64_user_depth<=BOB64_USER_ENTRY_MAX_DEPTH) + bob64_user_return_frames[bob64_user_depth-1].ReturnValue=value; + bob64_user_return_value=value; + bob64_user_active=0; +} + +static BOB64_SYSCALL_HANDLE *find_handle(u64 id) { + if(!id)return 0; + for(usize i=0;imaximum_length|| + address=arena_end|| + length>arena_end-address)return -1; + if(!length)return 0; + end=address+length-1; + first_page=address&~(BOB64_PAGE_SIZE-1); + last_page=end&~(BOB64_PAGE_SIZE-1); + for(u64 page=first_page;;page+=BOB64_PAGE_SIZE) { + if(bob64_page_translate(page_table,page,&physical,&flags)!=1|| + (flags&required_flags)!=required_flags)return -1; + if(page==last_page)break; + } + return 0; +} + +int bob64_syscall_validate_user_range(const BOB64_PAGE_TABLE *page_table, + u64 address,u64 length) { + return syscall_validate_user_range(page_table,address,length,BOB64_PAGE_USER, + BOB64_SYSCALL_MAX_BUFFER); +} + +u64 BOB64_MS_ABI bob64_syscall_dispatch(BOB64_INTERRUPT_FRAME *frame) { + if(!frame)return 0; + if((frame->CS&3)!=3||!bob64_user_active) { + frame->RAX=(u64)-1; + return 0; + } + if(frame->RAX==BOB64_SYSCALL_QUERY_ABI) { + frame->RAX=BOB64_SYSCALL_ABI_VERSION; + return 0; + } + if(frame->RAX==BOB64_SYSCALL_GET_TICKS) { + frame->RAX=bob64_timer_ticks(); + return 0; + } + if(frame->RAX==BOB64_SYSCALL_WRITE_CHAR) { + if(!syscall_write_character) { + frame->RAX=(u64)-1; + return 0; + } + syscall_write_character(syscall_write_context,(u8)frame->RCX); + frame->RAX=0; + return 0; + } + if(frame->RAX==BOB64_SYSCALL_WRITE_BUFFER) { + u64 address=frame->RCX,length=frame->RDX; + if(!syscall_write_character||!syscall_read_user|| + bob64_syscall_validate_user_range(syscall_page_table,address,length)|| + syscall_read_user(syscall_read_user_context,address,syscall_buffer,(usize)length)) { + frame->RAX=(u64)-14; + return 0; + } + for(u64 i=0;iRAX=length; + return 0; + } + if(frame->RAX==BOB64_SYSCALL_GET_DISPLAY) { + u32 width,height; + if(bob64_framebuffer_resolution(&width,&height)) { + frame->RAX=(u64)-19;frame->RDX=0; + } else { + frame->RAX=width;frame->RDX=height; + } + return 0; + } + if(frame->RAX==BOB64_SYSCALL_PRESENT) { + u64 address=frame->RCX,width=frame->RDX,height=frame->R8; + u32 display_width,display_height; + u64 pixels,bytes,offset=0; + if(bob64_framebuffer_resolution(&display_width,&display_height)) { + frame->RAX=(u64)-19;return 0; + } + if(width!=display_width||height!=display_height||!height|| + width>~(u64)0/height|| + (pixels=width*height)>~(u64)0/sizeof(u32)|| + (bytes=pixels*sizeof(u32))>BOB64_SYSCALL_MAX_SURFACE_BYTES|| + syscall_validate_user_range(syscall_page_table,address,bytes, + BOB64_PAGE_USER,BOB64_SYSCALL_MAX_SURFACE_BYTES)||!syscall_read_user) { + frame->RAX=(u64)-14;return 0; + } + while(offset + sizeof(syscall_surface_chunk)/sizeof(syscall_surface_chunk[0])? + sizeof(syscall_surface_chunk)/sizeof(syscall_surface_chunk[0]): + pixels-offset); + if(syscall_read_user(syscall_read_user_context,address+offset*sizeof(u32), + syscall_surface_chunk,(usize)count*sizeof(u32))|| + bob64_framebuffer_write_pixels(offset,syscall_surface_chunk,count)) { + frame->RAX=(u64)-14;return 0; + } + offset+=count; + } + frame->RAX=pixels;return 0; + } + if(frame->RAX==BOB64_SYSCALL_WAIT_EVENT) { + BOB64_EVENT event; + BOB64_EVENT routed; + u64 address=frame->RCX; + if(!syscall_wait_event||!syscall_write_user|| + syscall_validate_user_range(syscall_page_table,address,sizeof(event), + BOB64_PAGE_USER|BOB64_PAGE_WRITE,sizeof(event))|| + syscall_wait_event(syscall_wait_event_context,&event)) { + frame->RAX=(u64)-14; + return 0; + } + if(syscall_window_server) { + if(bob64_window_server_route_event(syscall_window_server, + syscall_window_owner,&event,&routed)<0) { + frame->RAX=(u64)-14;return 0; + } + event=routed; + } + if(syscall_write_user(syscall_write_user_context,address,&event,sizeof(event))) + frame->RAX=(u64)-14; + else frame->RAX=0; + return 0; + } + if(frame->RAX==BOB64_SYSCALL_LIST_FILES) { + u64 address=frame->RCX,capacity=frame->RDX; + u64 bytes; + s64 count; + if(!capacity||capacity>BOB64_SYSCALL_MAX_FILES|| + capacity>~(u64)0/sizeof(BOB64_FILE_INFO)) { + frame->RAX=(u64)-22;return 0; + } + bytes=capacity*sizeof(BOB64_FILE_INFO); + if(syscall_validate_user_range(syscall_page_table,address,bytes, + BOB64_PAGE_USER|BOB64_PAGE_WRITE,BOB64_SYSCALL_MAX_FILES*sizeof(BOB64_FILE_INFO))) { + frame->RAX=(u64)-14;return 0; + } + if(!syscall_file_list||!syscall_write_user) { + frame->RAX=(u64)-38;return 0; + } + for(usize i=0;i<(usize)capacity;i++) + for(usize j=0;jcapacity) { + frame->RAX=(u64)(count<0?count:-5);return 0; + } + bytes=(u64)count*sizeof(BOB64_FILE_INFO); + if(bytes&&syscall_write_user(syscall_write_user_context,address, + syscall_file_entries,(usize)bytes)) { + frame->RAX=(u64)-14;return 0; + } + frame->RAX=(u64)count;return 0; + } + if(frame->RAX==BOB64_SYSCALL_DELETE_FILE) { + u64 name_address=frame->RCX,name_length=frame->RDX; + char name[BOB64_SYSCALL_MAX_FILENAME+1]; + if(!name_length||name_length>BOB64_SYSCALL_MAX_FILENAME) { + frame->RAX=(u64)-22;return 0; + } + if(bob64_syscall_validate_user_range(syscall_page_table,name_address,name_length)|| + !syscall_read_user||syscall_read_user(syscall_read_user_context,name_address, + name,(usize)name_length)) { + frame->RAX=(u64)-14;return 0; + } + for(u64 i=0;iRAX=(u64)-22;return 0; + } + name[name_length]=0; + if(!syscall_file_delete)frame->RAX=(u64)-38; + else { + s64 result=syscall_file_delete(syscall_file_manager_context,name); + if(!result)for(usize i=0;iRAX=(u64)result; + } + return 0; + } + if(frame->RAX==BOB64_SYSCALL_CREATE_WINDOW) { + s64 x=(s64)frame->RCX,y=(s64)frame->RDX; + if(!syscall_window_server||x<(-2147483647LL-1)||x>2147483647LL|| + y<(-2147483647LL-1)||y>2147483647LL|| + frame->R8>0xffffffffULL||frame->R9>0xffffffffULL||!frame->R8||!frame->R9) { + frame->RAX=(u64)-22;return 0; + } + BOB64_WINDOW_HANDLE handle=bob64_window_server_create(syscall_window_server, + syscall_window_owner,(s32)x,(s32)y,(u32)frame->R8,(u32)frame->R9); + frame->RAX=handle?handle:(u64)-12; + return 0; + } + if(frame->RAX==BOB64_SYSCALL_DESTROY_WINDOW) { + if(!syscall_window_server||bob64_window_server_destroy(syscall_window_server, + syscall_window_owner,frame->RCX))frame->RAX=(u64)-22; + else frame->RAX=0; + return 0; + } + if(frame->RAX==BOB64_SYSCALL_FOCUS_WINDOW) { + if(!syscall_window_server||bob64_window_server_focus(syscall_window_server, + syscall_window_owner,frame->RCX))frame->RAX=(u64)-22; + else frame->RAX=0; + return 0; + } + if(frame->RAX==BOB64_SYSCALL_PRESENT_WINDOW) { + u64 handle=frame->RCX,address=frame->RDX,width=frame->R8,height=frame->R9; + u32 expected_width,expected_height; + u64 pixels,bytes,offset=0; + if(!syscall_window_server||width>0xffffffffULL||height>0xffffffffULL|| + !width||!height||width>~(u64)0/height|| + (pixels=width*height)>~(u64)0/sizeof(u32)|| + (bytes=pixels*sizeof(u32))>BOB64_WINDOW_SERVER_SURFACE_LIMIT|| + bob64_window_server_surface_size(syscall_window_server,syscall_window_owner, + handle,&expected_width,&expected_height)|| + width!=expected_width||height!=expected_height|| + syscall_validate_user_range(syscall_page_table,address,bytes, + BOB64_PAGE_USER,BOB64_WINDOW_SERVER_SURFACE_LIMIT)||!syscall_read_user) { + frame->RAX=(u64)-14;return 0; + } + while(offset + sizeof(syscall_surface_chunk)/sizeof(syscall_surface_chunk[0])? + sizeof(syscall_surface_chunk)/sizeof(syscall_surface_chunk[0]): + pixels-offset); + if(syscall_read_user(syscall_read_user_context,address+offset*sizeof(u32), + syscall_surface_chunk,(usize)count*sizeof(u32))|| + bob64_window_server_write_pixels(syscall_window_server, + syscall_window_owner,handle,offset,syscall_surface_chunk,count)) { + frame->RAX=(u64)-14;return 0; + } + offset+=count; + } + frame->RAX=bob64_window_server_present(syscall_window_server, + syscall_window_owner,handle)?(u64)-14:pixels; + return 0; + } + if(frame->RAX==BOB64_SYSCALL_READ_FILE|| + frame->RAX==BOB64_SYSCALL_WRITE_FILE) { + u64 name_address=frame->RCX,name_length=frame->RDX; + u64 buffer_address=frame->R8,buffer_length=frame->R9; + char name[BOB64_SYSCALL_MAX_FILENAME+1]; + s64 result; + if(!name_length||name_length>BOB64_SYSCALL_MAX_FILENAME|| + buffer_length>BOB64_SYSCALL_MAX_BUFFER) { + frame->RAX=(u64)-22; + return 0; + } + if(bob64_syscall_validate_user_range(syscall_page_table,name_address,name_length)|| + syscall_validate_user_range(syscall_page_table,buffer_address,buffer_length, + BOB64_PAGE_USER|(frame->RAX==BOB64_SYSCALL_READ_FILE?BOB64_PAGE_WRITE:0), + BOB64_SYSCALL_MAX_BUFFER)|| + !syscall_read_user|| + syscall_read_user(syscall_read_user_context,name_address,name,(usize)name_length)) { + frame->RAX=(u64)-14; + return 0; + } + for(u64 i=0;iRAX=(u64)-22; + return 0; + } + name[name_length]=0; + if(frame->RAX==BOB64_SYSCALL_WRITE_FILE) { + if(!syscall_file_write)result=-38; + else if(syscall_read_user(syscall_read_user_context,buffer_address, + syscall_buffer,(usize)buffer_length))result=-14; + else result=syscall_file_write(syscall_filesystem_context,name,syscall_buffer, + (usize)buffer_length); + } else if(!syscall_file_read)result=-38; + else { + result=syscall_file_read(syscall_filesystem_context,name,syscall_buffer, + (usize)buffer_length); + if(result>=0&&((u64)result>buffer_length||(result&&(!syscall_write_user|| + syscall_write_user(syscall_write_user_context,buffer_address,syscall_buffer, + (usize)result)))))result=-14; + } + frame->RAX=(u64)result; + return 0; + } + if(frame->RAX==BOB64_SYSCALL_OPEN_FILE) { + u64 name_address=frame->RCX,name_length=frame->RDX; + u32 flags=(u32)frame->R8; + char name[BOB64_SYSCALL_MAX_FILENAME+1]; + BOB64_SYSCALL_HANDLE *slot=0; + s64 size;u64 new_id=0; + if(!name_length||name_length>BOB64_SYSCALL_MAX_FILENAME|| + frame->R8>BOB64_FILE_OPEN_FLAGS||!(flags&(BOB64_FILE_OPEN_READ|BOB64_FILE_OPEN_WRITE))|| + ((flags&BOB64_FILE_OPEN_TRUNCATE)&&!(flags&BOB64_FILE_OPEN_WRITE))|| + ((flags&BOB64_FILE_OPEN_APPEND)&&!(flags&BOB64_FILE_OPEN_WRITE))) { + frame->RAX=(u64)-22;return 0; + } + if(bob64_syscall_validate_user_range(syscall_page_table,name_address,name_length)|| + !syscall_read_user||syscall_read_user(syscall_read_user_context,name_address, + name,(usize)name_length)) { + frame->RAX=(u64)-14;return 0; + } + for(u64 i=0;iRAX=(u64)-22;return 0;} + name[name_length]=0; + if(!syscall_file_open) {frame->RAX=(u64)-38;return 0;} + for(usize i=0;iRAX=(u64)-24;return 0;} + size=syscall_file_open(syscall_file_stream_context,name,flags); + if(size<0) {frame->RAX=(u64)size;return 0;} + for(usize attempt=0;attempt<=BOB64_SYSCALL_OPEN_HANDLES;attempt++) { + u64 candidate=syscall_next_handle++; + if(candidate&&!find_handle(candidate)){new_id=candidate;break;} + } + if(!new_id){frame->RAX=(u64)-24;return 0;} + slot->Id=new_id; + slot->Flags=flags;slot->Position=(flags&BOB64_FILE_OPEN_APPEND)?(u64)size:0; + for(usize i=0;i<=name_length;i++)slot->Name[i]=name[i]; + frame->RAX=slot->Id;return 0; + } + if(frame->RAX==BOB64_SYSCALL_READ_HANDLE|| + frame->RAX==BOB64_SYSCALL_WRITE_HANDLE) { + u64 id=frame->RCX,address=frame->RDX,length=frame->R8; + BOB64_SYSCALL_HANDLE *handle=find_handle(id); + s64 result; + int writing=frame->RAX==BOB64_SYSCALL_WRITE_HANDLE; + if(length>BOB64_SYSCALL_MAX_BUFFER) {frame->RAX=(u64)-22;return 0;} + if(!handle||!(handle->Flags&(writing?BOB64_FILE_OPEN_WRITE:BOB64_FILE_OPEN_READ))) { + frame->RAX=(u64)-9;return 0; + } + if(syscall_validate_user_range(syscall_page_table,address,length, + BOB64_PAGE_USER|(writing?0:BOB64_PAGE_WRITE),BOB64_SYSCALL_MAX_BUFFER)|| + (length&&!syscall_read_user)) {frame->RAX=(u64)-14;return 0;} + if(writing) { + if(!syscall_file_write_at) {frame->RAX=(u64)-38;return 0;} + if(handle->Flags&BOB64_FILE_OPEN_APPEND) { + s64 end=syscall_file_open(syscall_file_stream_context,handle->Name, + handle->Flags&(BOB64_FILE_OPEN_READ|BOB64_FILE_OPEN_WRITE)); + if(end<0) {frame->RAX=(u64)end;return 0;} + handle->Position=(u64)end; + } + if(handle->Position>0x7fffffffffffffffULL|| + length>0x7fffffffffffffffULL-handle->Position) { + frame->RAX=(u64)-75;return 0; + } + if(length&&syscall_read_user(syscall_read_user_context,address,syscall_buffer, + (usize)length)) { + frame->RAX=(u64)-14;return 0; + } + result=syscall_file_write_at(syscall_file_stream_context,handle->Name, + handle->Position,syscall_buffer,(usize)length); + if(result>=0&&(u64)result<=length&& + (u64)result<=0x7fffffffffffffffULL-handle->Position) + handle->Position+=(u64)result; + else if(result>=0)result=-5; + } else { + if(!syscall_file_read_at||!syscall_write_user) {frame->RAX=(u64)-38;return 0;} + if(handle->Position>0x7fffffffffffffffULL|| + length>0x7fffffffffffffffULL-handle->Position) { + frame->RAX=(u64)-75;return 0; + } + result=syscall_file_read_at(syscall_file_stream_context,handle->Name, + handle->Position,syscall_buffer,(usize)length); + if(result>=0&&(u64)result<=length) { + if(result&&syscall_write_user(syscall_write_user_context,address, + syscall_buffer,(usize)result))result=-14; + else handle->Position+=(u64)result; + } else if(result>=0)result=-5; + } + frame->RAX=(u64)result;return 0; + } + if(frame->RAX==BOB64_SYSCALL_SEEK_HANDLE) { + BOB64_SYSCALL_HANDLE *handle=find_handle(frame->RCX); + if(!handle)frame->RAX=(u64)-9; + else {handle->Position=frame->RDX;frame->RAX=handle->Position;} + return 0; + } + if(frame->RAX==BOB64_SYSCALL_CLOSE_HANDLE) { + BOB64_SYSCALL_HANDLE *handle=find_handle(frame->RCX); + if(!handle)frame->RAX=(u64)-9; + else {handle->Id=0;frame->RAX=0;} + return 0; + } + if(frame->RAX==BOB64_SYSCALL_EXIT)bob64_user_request_return((s64)frame->RCX); + else bob64_user_request_return(-38); + return 1; +} diff --git a/bob64/syscall.h b/bob64/syscall.h new file mode 100644 index 0000000..08627ec --- /dev/null +++ b/bob64/syscall.h @@ -0,0 +1,73 @@ +#ifndef BOB64_SYSCALL_H +#define BOB64_SYSCALL_H + +#include "abi.h" +#include "interrupts.h" +#include "paging.h" +#include "event.h" +#include "window_server.h" + +#define BOB64_SYSCALL_CONTEXT_MAX_DEPTH 8u +#define BOB64_USER_ENTRY_MAX_DEPTH 8u + +typedef struct { + u64 KernelRsp; + s64 ReturnValue; + s64 PreviousReturnValue; + u64 PreviousInterruptState; + u64 PreviousActive; +} BOB64_USER_RETURN_FRAME; + +_Static_assert(sizeof(BOB64_USER_RETURN_FRAME)==40, + "assembly user-return frame layout"); + +typedef void (*BOB64_SYSCALL_WRITE)(void *context,u8 character); +typedef int (*BOB64_SYSCALL_READ_USER)(void *context,u64 address, + void *destination,usize length); +typedef int (*BOB64_SYSCALL_WRITE_USER)(void *context,u64 address, + const void *source,usize length); +typedef s64 (*BOB64_SYSCALL_FILE_READ)(void *context,const char *name, + u8 *buffer,usize capacity); +typedef s64 (*BOB64_SYSCALL_FILE_WRITE)(void *context,const char *name, + const u8 *buffer,usize length); +typedef s64 (*BOB64_SYSCALL_FILE_LIST)(void *context,BOB64_FILE_INFO *entries, + usize capacity); +typedef s64 (*BOB64_SYSCALL_FILE_DELETE)(void *context,const char *name); +typedef s64 (*BOB64_SYSCALL_FILE_OPEN)(void *context,const char *name,u32 flags); +typedef s64 (*BOB64_SYSCALL_FILE_READ_AT)(void *context,const char *name,u64 offset, + u8 *buffer,usize capacity); +typedef s64 (*BOB64_SYSCALL_FILE_WRITE_AT)(void *context,const char *name,u64 offset, + const u8 *buffer,usize length); +typedef int (*BOB64_SYSCALL_EVENT_WAIT)(void *context,BOB64_EVENT *event); + +extern volatile u64 bob64_user_active; +extern volatile u64 bob64_user_depth; +extern BOB64_USER_RETURN_FRAME bob64_user_return_frames[BOB64_USER_ENTRY_MAX_DEPTH]; +extern volatile s64 bob64_user_return_value; + +void bob64_syscall_set_write(BOB64_SYSCALL_WRITE write_character,void *context); +void bob64_syscall_set_read_user(BOB64_SYSCALL_READ_USER read_user,void *context); +void bob64_syscall_set_write_user(BOB64_SYSCALL_WRITE_USER write_user,void *context); +void bob64_syscall_set_filesystem(BOB64_SYSCALL_FILE_READ read_file, + BOB64_SYSCALL_FILE_WRITE write_file,void *context); +void bob64_syscall_set_file_manager(BOB64_SYSCALL_FILE_LIST list_files, + BOB64_SYSCALL_FILE_DELETE delete_file, + void *context); +void bob64_syscall_set_file_stream(BOB64_SYSCALL_FILE_OPEN open_file, + BOB64_SYSCALL_FILE_READ_AT read_at, + BOB64_SYSCALL_FILE_WRITE_AT write_at, + void *context); +void bob64_syscall_set_wait_event(BOB64_SYSCALL_EVENT_WAIT wait_event,void *context); +void bob64_syscall_set_window_server(BOB64_WINDOW_SERVER *server,u64 owner); +void bob64_syscall_set_address_space(const BOB64_PAGE_TABLE *page_table); +/* Nested kernel app runs save and restore the complete syscall service state. */ +int bob64_syscall_context_push(void); +int bob64_syscall_context_pop(void); +void bob64_user_request_return(s64 value); +int bob64_syscall_validate_user_range(const BOB64_PAGE_TABLE *page_table, + u64 address,u64 length); +/* Returns zero to resume the app, one to return from bob64_enter_user. */ +u64 BOB64_MS_ABI bob64_syscall_dispatch(BOB64_INTERRUPT_FRAME *frame); +s64 BOB64_MS_ABI bob64_enter_user(u64 entry,u64 startup,u64 stack); + +#endif diff --git a/bob64/types.h b/bob64/types.h new file mode 100644 index 0000000..b82e58b --- /dev/null +++ b/bob64/types.h @@ -0,0 +1,28 @@ +#ifndef BOB64_TYPES_H +#define BOB64_TYPES_H + +/* bob64's freestanding C types. Addresses and pointers are always 64-bit. */ +typedef unsigned char u8; +typedef signed char s8; +typedef unsigned short u16; +typedef signed short s16; +typedef unsigned int u32; +typedef signed int s32; +typedef unsigned long long u64; +typedef signed long long s64; +typedef __UINTPTR_TYPE__ uintptr_t; +typedef __INTPTR_TYPE__ intptr_t; +typedef __SIZE_TYPE__ usize; +typedef __PTRDIFF_TYPE__ isize; + +_Static_assert(sizeof(u8)==1,"u8 must be 8 bits"); +_Static_assert(sizeof(u16)==2,"u16 must be 16 bits"); +_Static_assert(sizeof(u32)==4,"u32 must be 32 bits"); +_Static_assert(sizeof(u64)==8,"u64 must be 64 bits"); +_Static_assert(sizeof(uintptr_t)==8,"bob64 requires 64-bit pointers"); +_Static_assert(sizeof(usize)==8,"bob64 requires 64-bit sizes"); +#ifdef BOB64_UEFI_ABI +_Static_assert(sizeof(long)==4,"x64 UEFI target uses the LLP64 data model"); +#endif + +#endif diff --git a/bob64/window.h b/bob64/window.h new file mode 100644 index 0000000..15c9770 --- /dev/null +++ b/bob64/window.h @@ -0,0 +1,270 @@ +#ifndef BOB64_WINDOW_H +#define BOB64_WINDOW_H + +#include "event.h" + +typedef u64 BOB64_WINDOW_HANDLE; + +#define BOB64_WINDOW_VISIBLE 1u +#define BOB64_WINDOW_DIRTY 2u +#define BOB64_WINDOW_TITLE_BAR_HEIGHT 24u + +/* App-owned state. Context is a full-width app pointer and is never a kernel pointer. */ +typedef struct { + BOB64_WINDOW_HANDLE Handle; + void *Context; + s32 X,Y; + u32 Width,Height,Flags; +} BOB64_WINDOW; + +typedef struct { + BOB64_WINDOW *Windows; + BOB64_WINDOW_HANDLE *ZOrder; + u32 Capacity,Count,ScreenWidth,ScreenHeight,LastButtons; + BOB64_WINDOW_HANDLE Focused,Dragging,NextHandle; + s32 DragOffsetX,DragOffsetY; + u32 FullDirty,DrawIndex; +} BOB64_WINDOW_MANAGER; + +static inline BOB64_WINDOW *bob64_wm_find(BOB64_WINDOW_MANAGER *manager, + BOB64_WINDOW_HANDLE handle) { + if(!manager||!handle)return 0; + for(u32 i=0;iCapacity;i++) + if(manager->Windows[i].Handle==handle)return &manager->Windows[i]; + return 0; +} + +static inline int bob64_wm_intersects(const BOB64_WINDOW *a,const BOB64_WINDOW *b) { + return (s64)a->X+a->Width>b->X&&(s64)b->X+b->Width>a->X&& + (s64)a->Y+a->Height>b->Y&&(s64)b->Y+b->Height>a->Y; +} + +static inline void bob64_wm_clamp(BOB64_WINDOW_MANAGER *manager,BOB64_WINDOW *window) { + s32 max_x=(s32)(manager->ScreenWidth-window->Width); + s32 max_y=(s32)(manager->ScreenHeight-window->Height); + if(window->X<0)window->X=0; + if(window->Y<0)window->Y=0; + if(window->X>max_x)window->X=max_x; + if(window->Y>max_y)window->Y=max_y; +} + +static inline void bob64_wm_dirty_all(BOB64_WINDOW_MANAGER *manager) { + for(u32 i=0;iCount;i++) { + BOB64_WINDOW *window=bob64_wm_find(manager,manager->ZOrder[i]); + if(window&&(window->Flags&BOB64_WINDOW_VISIBLE))window->Flags|=BOB64_WINDOW_DIRTY; + } + manager->FullDirty=1; +} + +static inline int bob64_wm_init(BOB64_WINDOW_MANAGER *manager, + BOB64_WINDOW *windows,u32 capacity, + BOB64_WINDOW_HANDLE *z_order, + u32 screen_width,u32 screen_height) { + if(!manager||!windows||!z_order||!capacity||capacity>64||!screen_width|| + !screen_height||screen_width>0x7fffffffu||screen_height>0x7fffffffu)return -1; + manager->Windows=windows;manager->ZOrder=z_order; + manager->Capacity=capacity;manager->Count=0; + manager->ScreenWidth=screen_width;manager->ScreenHeight=screen_height; + manager->LastButtons=0;manager->Focused=0;manager->Dragging=0; + manager->NextHandle=1;manager->DragOffsetX=0;manager->DragOffsetY=0; + manager->FullDirty=1;manager->DrawIndex=0; + for(u32 i=0;iCount:0; + if(!manager||!bob64_wm_find(manager,handle))return -1; + for(u32 i=0;iCount;i++)if(manager->ZOrder[i]==handle){index=i;break;} + if(index==manager->Count)return -1; + if(index+1==manager->Count)return 0; + for(u32 i=index;i+1Count;i++)manager->ZOrder[i]=manager->ZOrder[i+1]; + manager->ZOrder[manager->Count-1]=handle; + bob64_wm_dirty_all(manager); + return 1; +} + +static inline int bob64_wm_focus(BOB64_WINDOW_MANAGER *manager, + BOB64_WINDOW_HANDLE handle) { + BOB64_WINDOW *window=bob64_wm_find(manager,handle); + if(!window||!(window->Flags&BOB64_WINDOW_VISIBLE))return -1; + bob64_wm_raise(manager,handle); + manager->Focused=handle;window->Flags|=BOB64_WINDOW_DIRTY; + return 0; +} + +static inline BOB64_WINDOW_HANDLE bob64_wm_create(BOB64_WINDOW_MANAGER *manager, + s32 x,s32 y,u32 width,u32 height,void *context) { + BOB64_WINDOW *window=0; + if(!manager||!width||!height||width>manager->ScreenWidth|| + height>manager->ScreenHeight||manager->Count>=manager->Capacity|| + !manager->NextHandle||manager->NextHandle>0x7fffffffffffffffULL)return 0; + for(u32 i=0;iCapacity;i++)if(!manager->Windows[i].Handle) { + window=&manager->Windows[i];break; + } + if(!window)return 0; + window->Handle=manager->NextHandle++; + window->Context=context;window->X=x;window->Y=y; + window->Width=width;window->Height=height; + window->Flags=BOB64_WINDOW_VISIBLE|BOB64_WINDOW_DIRTY; + bob64_wm_clamp(manager,window); + manager->ZOrder[manager->Count++]=window->Handle; + manager->Focused=window->Handle;manager->Dragging=0; + bob64_wm_dirty_all(manager); + return window->Handle; +} + +static inline int bob64_wm_move(BOB64_WINDOW_MANAGER *manager, + BOB64_WINDOW_HANDLE handle,s32 x,s32 y) { + BOB64_WINDOW *window=bob64_wm_find(manager,handle); + if(!window)return -1; + window->X=x;window->Y=y;bob64_wm_clamp(manager,window); + bob64_wm_dirty_all(manager); + return 0; +} + +static inline int bob64_wm_show(BOB64_WINDOW_MANAGER *manager, + BOB64_WINDOW_HANDLE handle,int visible) { + BOB64_WINDOW *window=bob64_wm_find(manager,handle); + if(!window)return -1; + visible=visible!=0; + if(((window->Flags&BOB64_WINDOW_VISIBLE)!=0)==visible)return 0; + if(visible) { + window->Flags|=BOB64_WINDOW_VISIBLE; + bob64_wm_focus(manager,handle); + } else { + window->Flags&=~BOB64_WINDOW_VISIBLE; + if(manager->Dragging==handle)manager->Dragging=0; + if(manager->Focused==handle) { + manager->Focused=0; + for(u32 i=manager->Count;i>0;i--) { + BOB64_WINDOW *candidate=bob64_wm_find(manager,manager->ZOrder[i-1]); + if(candidate&&(candidate->Flags&BOB64_WINDOW_VISIBLE)) { + manager->Focused=candidate->Handle;break; + } + } + } + } + bob64_wm_dirty_all(manager); + return 1; +} + +static inline int bob64_wm_destroy(BOB64_WINDOW_MANAGER *manager, + BOB64_WINDOW_HANDLE handle) { + BOB64_WINDOW *window=bob64_wm_find(manager,handle); + u32 index; + if(!window)return -1; + for(index=0;indexCount;index++)if(manager->ZOrder[index]==handle)break; + if(index==manager->Count)return -1; + for(u32 i=index;i+1Count;i++)manager->ZOrder[i]=manager->ZOrder[i+1]; + manager->ZOrder[--manager->Count]=0; + if(manager->Focused==handle)manager->Focused=0; + if(manager->Dragging==handle)manager->Dragging=0; + window->Handle=0;window->Context=0;window->Flags=0; + window->X=window->Y=0;window->Width=window->Height=0; + if(!manager->Focused)for(u32 i=manager->Count;i>0;i--) { + BOB64_WINDOW *candidate=bob64_wm_find(manager,manager->ZOrder[i-1]); + if(candidate&&(candidate->Flags&BOB64_WINDOW_VISIBLE)) { + manager->Focused=candidate->Handle;break; + } + } + bob64_wm_dirty_all(manager); + return 0; +} + +static inline void bob64_wm_invalidate(BOB64_WINDOW_MANAGER *manager, + BOB64_WINDOW_HANDLE handle) { + BOB64_WINDOW *window=bob64_wm_find(manager,handle); + if(!window)return; + window->Flags|=BOB64_WINDOW_DIRTY; + for(u32 i=0;iCount;i++) { + BOB64_WINDOW *other=bob64_wm_find(manager,manager->ZOrder[i]); + if(other&&other!=window&&(other->Flags&BOB64_WINDOW_VISIBLE)&& + bob64_wm_intersects(window,other))other->Flags|=BOB64_WINDOW_DIRTY; + } +} + +static inline int bob64_wm_begin_draw(BOB64_WINDOW_MANAGER *manager) { + if(!manager)return -1; + if(manager->FullDirty)bob64_wm_dirty_all(manager); + manager->FullDirty=0;manager->DrawIndex=0; + return 0; +} + +static inline BOB64_WINDOW_HANDLE bob64_wm_next_dirty(BOB64_WINDOW_MANAGER *manager) { + if(!manager)return 0; + while(manager->DrawIndexCount) { + BOB64_WINDOW_HANDLE handle=manager->ZOrder[manager->DrawIndex++]; + BOB64_WINDOW *window=bob64_wm_find(manager,handle); + if(window&&(window->Flags&BOB64_WINDOW_VISIBLE)&& + (window->Flags&BOB64_WINDOW_DIRTY)) { + window->Flags&=~BOB64_WINDOW_DIRTY;return handle; + } + } + return 0; +} + +static inline BOB64_WINDOW_HANDLE bob64_wm_hit_test(const BOB64_WINDOW_MANAGER *manager, + s32 x,s32 y) { + if(!manager)return 0; + for(u32 i=manager->Count;i>0;i--) { + BOB64_WINDOW *window=bob64_wm_find((BOB64_WINDOW_MANAGER *)manager, + manager->ZOrder[i-1]); + if(window&&(window->Flags&BOB64_WINDOW_VISIBLE)&&x>=window->X&&y>=window->Y&& + (s64)x<=(s64)window->X+window->Width-1&& + (s64)y<=(s64)window->Y+window->Height-1)return window->Handle; + } + return 0; +} + +/* Returns the target handle, zero for unhandled input, or -1 for invalid arguments. */ +static inline s64 bob64_wm_dispatch(BOB64_WINDOW_MANAGER *manager, + const BOB64_EVENT *event,BOB64_EVENT *routed) { + BOB64_WINDOW_HANDLE target=0; + u32 pressed,released; + if(!manager||!event||!routed)return -1; + *routed=*event; + pressed=event->Buttons&~manager->LastButtons; + released=manager->LastButtons&~event->Buttons; + if(event->Type==BOB64_EVENT_KEY_DOWN||event->Type==BOB64_EVENT_KEY_UP) { + BOB64_WINDOW *focused=bob64_wm_find(manager,manager->Focused); + if(focused&&(focused->Flags&BOB64_WINDOW_VISIBLE))target=focused->Handle; + } else if(event->Type==BOB64_EVENT_MOUSE_MOVE|| + event->Type==BOB64_EVENT_MOUSE_BUTTON|| + event->Type==BOB64_EVENT_MOUSE_WHEEL) { + if(manager->Dragging)target=manager->Dragging; + else target=bob64_wm_hit_test(manager,event->X,event->Y); + BOB64_WINDOW *window=bob64_wm_find(manager,target); + if(window) { + if(event->Type==BOB64_EVENT_MOUSE_BUTTON&&pressed) { + bob64_wm_focus(manager,target);window=bob64_wm_find(manager,target); + if((pressed&1u)&&event->Y>=window->Y&& + (u32)(event->Y-window->Y)Dragging=target; + manager->DragOffsetX=event->X-window->X; + manager->DragOffsetY=event->Y-window->Y; + } + } + if(manager->Dragging&& + (event->Type==BOB64_EVENT_MOUSE_MOVE||event->Type==BOB64_EVENT_MOUSE_BUTTON)) { + if((event->Type==BOB64_EVENT_MOUSE_MOVE&&(event->Buttons&1u))|| + event->Type==BOB64_EVENT_MOUSE_BUTTON) + bob64_wm_move(manager,target,event->X-manager->DragOffsetX, + event->Y-manager->DragOffsetY); + if(released&1u)manager->Dragging=0; + window=bob64_wm_find(manager,target); + } + routed->X=event->X-window->X;routed->Y=event->Y-window->Y; + } + } + if(event->Type==BOB64_EVENT_MOUSE_MOVE||event->Type==BOB64_EVENT_MOUSE_BUTTON|| + event->Type==BOB64_EVENT_MOUSE_WHEEL)manager->LastButtons=event->Buttons; + return (s64)target; +} + +#endif diff --git a/bob64/window_server.c b/bob64/window_server.c new file mode 100644 index 0000000..c066df5 --- /dev/null +++ b/bob64/window_server.c @@ -0,0 +1,176 @@ +#include "window_server.h" + +/* The compositor runs on the single kernel CPU with interrupts disabled. */ +static u32 server_composite_chunk[1024]; + +static int server_has_owner(const BOB64_WINDOW_SERVER *server,u64 owner) { + return server&&server->Active&&owner&&owner==server->Owner; +} + +static int server_slot(const BOB64_WINDOW_SERVER *server, + BOB64_WINDOW_HANDLE handle) { + if(!server||!handle)return -1; + for(u32 i=0;iWindows[i].Handle==handle)return (int)i; + return -1; +} + +static u32 server_pixel(const BOB64_WINDOW_SERVER *server,u32 x,u32 y) { + for(u32 i=server->Manager.Count;i>0;i--) { + BOB64_WINDOW_HANDLE handle=server->Manager.ZOrder[i-1]; + BOB64_WINDOW *window=bob64_wm_find((BOB64_WINDOW_MANAGER *)&server->Manager, + handle); + if(window&&(window->Flags&BOB64_WINDOW_VISIBLE)&&x>=(u32)window->X&& + y>=(u32)window->Y&&x-(u32)window->XWidth&& + y-(u32)window->YHeight) { + const u32 *surface=(const u32 *)window->Context; + return surface[(usize)(y-(u32)window->Y)*window->Width+ + (x-(u32)window->X)]; + } + } + return 0x000d1723u; +} + +static int server_composite(BOB64_WINDOW_SERVER *server) { + u32 width,height; + u64 total,offset=0; + if(!server||bob64_framebuffer_resolution(&width,&height))return -1; + total=(u64)width*height; + while(offset + sizeof(server_composite_chunk)/sizeof(server_composite_chunk[0])? + sizeof(server_composite_chunk)/sizeof(server_composite_chunk[0]):total-offset); + for(u32 i=0;iManager,server->Windows, + BOB64_WINDOW_SERVER_CAPACITY,server->ZOrder,screen_width,screen_height))return -1; + server->Heap=heap;server->Owner=owner;server->Active=1; + return server_composite(server); +} + +void bob64_window_server_close(BOB64_WINDOW_SERVER *server) { + if(!server||!server->Active)return; + while(server->Manager.Count) { + BOB64_WINDOW_HANDLE handle=server->Manager.ZOrder[server->Manager.Count-1]; + if(bob64_window_server_destroy(server,server->Owner,handle))break; + } + server->Active=0;server->Owner=0;server->BytesAllocated=0; +} + +BOB64_WINDOW_HANDLE bob64_window_server_create(BOB64_WINDOW_SERVER *server, + u64 owner,s32 x,s32 y,u32 width,u32 height) { + u64 pixels,bytes; + u32 *surface; + BOB64_WINDOW_HANDLE handle; + int slot; + if(!server_has_owner(server,owner)||!width||!height|| + (u64)width>~(u64)0/height)return 0; + pixels=(u64)width*height; + if(pixels>~(u64)0/sizeof(u32))return 0; + bytes=pixels*sizeof(u32); + if(bytes>BOB64_WINDOW_SERVER_SURFACE_LIMIT-server->BytesAllocated|| + bytes>(u64)~(usize)0)return 0; + surface=(u32 *)bob64_heap_calloc(server->Heap,1,(usize)bytes); + if(!surface)return 0; + handle=bob64_wm_create(&server->Manager,x,y,width,height,surface); + slot=server_slot(server,handle); + if(!handle||slot<0) { + bob64_heap_free(server->Heap,surface);return 0; + } + server->Owners[slot]=owner;server->SurfaceBytes[slot]=(usize)bytes; + server->BytesAllocated+=bytes; + if(server_composite(server)) { + bob64_window_server_destroy(server,owner,handle);return 0; + } + return handle; +} + +int bob64_window_server_destroy(BOB64_WINDOW_SERVER *server,u64 owner, + BOB64_WINDOW_HANDLE handle) { + int slot; + u32 *surface; + if(!server_has_owner(server,owner)||(slot=server_slot(server,handle))<0|| + server->Owners[slot]!=owner)return -1; + surface=(u32 *)server->Windows[slot].Context; + if(bob64_wm_destroy(&server->Manager,handle))return -1; + if(surface) { + server->BytesAllocated-=server->SurfaceBytes[slot]; + if(bob64_heap_free(server->Heap,surface))return -1; + } + server->Owners[slot]=0;server->SurfaceBytes[slot]=0; + return server_composite(server); +} + +int bob64_window_server_move(BOB64_WINDOW_SERVER *server,u64 owner, + BOB64_WINDOW_HANDLE handle,s32 x,s32 y) { + int slot=server_slot(server,handle); + if(!server_has_owner(server,owner)||slot<0||server->Owners[slot]!=owner|| + bob64_wm_move(&server->Manager,handle,x,y))return -1; + return server_composite(server); +} + +int bob64_window_server_focus(BOB64_WINDOW_SERVER *server,u64 owner, + BOB64_WINDOW_HANDLE handle) { + int slot=server_slot(server,handle); + if(!server_has_owner(server,owner)||slot<0||server->Owners[slot]!=owner|| + bob64_wm_focus(&server->Manager,handle))return -1; + return server_composite(server); +} + +int bob64_window_server_write_pixels(BOB64_WINDOW_SERVER *server,u64 owner, + BOB64_WINDOW_HANDLE handle,u64 first_pixel,const u32 *pixels,u32 count) { + int slot=server_slot(server,handle); + u64 total; + u32 *surface; + if(!server_has_owner(server,owner)||slot<0||server->Owners[slot]!=owner|| + (!pixels&&count))return -1; + BOB64_WINDOW *window=&server->Windows[slot]; + total=(u64)window->Width*window->Height; + if(first_pixel>total||(u64)count>total-first_pixel)return -1; + surface=(u32 *)window->Context; + for(u32 i=0;iOwners[slot]!=owner|| + !width||!height)return -1; + *width=server->Windows[slot].Width;*height=server->Windows[slot].Height; + return 0; +} + +int bob64_window_server_present(BOB64_WINDOW_SERVER *server,u64 owner, + BOB64_WINDOW_HANDLE handle) { + int slot=server_slot(server,handle); + if(!server_has_owner(server,owner)||slot<0||server->Owners[slot]!=owner)return -1; + return server_composite(server); +} + +s64 bob64_window_server_route_event(BOB64_WINDOW_SERVER *server,u64 owner, + const BOB64_EVENT *event,BOB64_EVENT *routed) { + s64 target; + if(!server_has_owner(server,owner)||!event||!routed)return -1; + target=bob64_wm_dispatch(&server->Manager,event,routed); + if(target<0)return target; + routed->WindowHandle=(u64)target; + routed->ScreenX=event->X;routed->ScreenY=event->Y; + if(event->Type==BOB64_EVENT_MOUSE_MOVE||event->Type==BOB64_EVENT_MOUSE_BUTTON|| + event->Type==BOB64_EVENT_MOUSE_WHEEL) + if(server_composite(server))return -1; + return target; +} diff --git a/bob64/window_server.h b/bob64/window_server.h new file mode 100644 index 0000000..f021579 --- /dev/null +++ b/bob64/window_server.h @@ -0,0 +1,43 @@ +#ifndef BOB64_WINDOW_SERVER_H +#define BOB64_WINDOW_SERVER_H + +#include "window.h" +#include "heap.h" +#include "console.h" + +#define BOB64_WINDOW_SERVER_CAPACITY 16u +#define BOB64_WINDOW_SERVER_SURFACE_LIMIT (16u*1024u*1024u) + +typedef struct { + BOB64_HEAP *Heap; + BOB64_WINDOW_MANAGER Manager; + BOB64_WINDOW Windows[BOB64_WINDOW_SERVER_CAPACITY]; + BOB64_WINDOW_HANDLE ZOrder[BOB64_WINDOW_SERVER_CAPACITY]; + u64 Owners[BOB64_WINDOW_SERVER_CAPACITY]; + usize SurfaceBytes[BOB64_WINDOW_SERVER_CAPACITY]; + u64 Owner; + u64 BytesAllocated; + u8 Active; +} BOB64_WINDOW_SERVER; + +int bob64_window_server_init(BOB64_WINDOW_SERVER *server,BOB64_HEAP *heap, + u64 owner,u32 screen_width,u32 screen_height); +void bob64_window_server_close(BOB64_WINDOW_SERVER *server); +BOB64_WINDOW_HANDLE bob64_window_server_create(BOB64_WINDOW_SERVER *server, + u64 owner,s32 x,s32 y,u32 width,u32 height); +int bob64_window_server_destroy(BOB64_WINDOW_SERVER *server,u64 owner, + BOB64_WINDOW_HANDLE handle); +int bob64_window_server_move(BOB64_WINDOW_SERVER *server,u64 owner, + BOB64_WINDOW_HANDLE handle,s32 x,s32 y); +int bob64_window_server_focus(BOB64_WINDOW_SERVER *server,u64 owner, + BOB64_WINDOW_HANDLE handle); +int bob64_window_server_write_pixels(BOB64_WINDOW_SERVER *server,u64 owner, + BOB64_WINDOW_HANDLE handle,u64 first_pixel,const u32 *pixels,u32 count); +int bob64_window_server_surface_size(const BOB64_WINDOW_SERVER *server,u64 owner, + BOB64_WINDOW_HANDLE handle,u32 *width,u32 *height); +int bob64_window_server_present(BOB64_WINDOW_SERVER *server,u64 owner, + BOB64_WINDOW_HANDLE handle); +s64 bob64_window_server_route_event(BOB64_WINDOW_SERVER *server,u64 owner, + const BOB64_EVENT *event,BOB64_EVENT *routed); + +#endif diff --git a/build-tool.exe b/build-tool.exe index 071c71b..9ed3031 100644 Binary files a/build-tool.exe and b/build-tool.exe differ diff --git a/kernel.basm b/kernel.basm index 0974fe6..dd905bc 100644 --- a/kernel.basm +++ b/kernel.basm @@ -773,7 +773,7 @@ .fill 2b80 .fill 4601 .fill ae01 -.fill 78d6 +.fill 7a18 .fill c300 .fill f000 .fill 1dff @@ -889,7 +889,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -986,7 +986,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -1068,7 +1068,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -1218,7 +1218,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7b36 +.fill 7c78 .fill c300 .fill 1d82 .fill 6380 @@ -1248,7 +1248,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a67 +.fill 7ba9 .fill c300 .fill 1d82 .fill 6380 @@ -1311,7 +1311,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -1354,7 +1354,7 @@ .fill 1dfd .fill 4001 .fill ae01 -.fill 7e99 +.fill 7fdb .fill 1dff .fill 9180 .fill cf09 @@ -1382,7 +1382,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -1418,7 +1418,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -1430,7 +1430,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7d97 +.fill 7ed9 .fill 1dff .fill 9180 .fill 10d0 @@ -1448,7 +1448,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a67 +.fill 7ba9 .fill c300 .fill 1d82 .fill 1dff @@ -1479,7 +1479,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7da7 +.fill 7ee9 .fill 1dff .fill 9180 .fill 10d0 @@ -1523,7 +1523,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -1601,7 +1601,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -1656,7 +1656,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -1676,7 +1676,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -1710,7 +1710,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -1731,7 +1731,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -1781,7 +1781,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 @@ -1811,7 +1811,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -1896,7 +1896,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -1915,7 +1915,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -1967,7 +1967,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -1984,7 +1984,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7d96 +.fill 7ed8 .fill 6000 .fill 6380 .fill 1d81 @@ -1999,7 +1999,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ab +.fill 7aed .fill c300 .fill 1d82 .fill 2380 @@ -2030,7 +2030,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7d96 +.fill 7ed8 .fill 6000 .fill 6380 .fill 1d81 @@ -2040,12 +2040,12 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7d96 +.fill 7ed8 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7d96 +.fill 7ed8 .fill 6000 .fill 1dff .fill 9180 @@ -2094,6 +2094,104 @@ .fill 1ae0 .fill 1dfb .fill 10d0 +.fill 11fb +.fill 1dff +.fill 9180 +.fill 2180 +.fill 6380 +.fill 1d81 +.fill 1010 +.fill 1dff +.fill 9180 +.fill 2180 +.fill 6380 +.fill 1d81 +.fill 9040 +.fill 10d0 +.fill 11fb +.fill 1dff +.fill 9180 +.fill 2180 +.fill 1181 +.fill 6380 +.fill 1d81 +.fill 1010 +.fill 1dff +.fill 9180 +.fill 4001 +.fill ae01 +.fill 7eed +.fill 6380 +.fill 1d81 +.fill 9040 +.fill 10d0 +.fill 11fb +.fill 1dff +.fill 9180 +.fill 2180 +.fill 1182 +.fill 6380 +.fill 1d81 +.fill 1010 +.fill 1dff +.fill 9180 +.fill 4001 +.fill ae01 +.fill 7fad +.fill 6380 +.fill 1d81 +.fill 9040 +.fill 10d0 +.fill 11fb +.fill 1dff +.fill 9180 +.fill 2180 +.fill 1183 +.fill 6380 +.fill 1d81 +.fill 1010 +.fill 1dff +.fill 9180 +.fill 4001 +.fill ae01 +.fill 7fb5 +.fill 6380 +.fill 1d81 +.fill 9040 +.fill 10d0 +.fill 11fb +.fill 1dff +.fill 9180 +.fill 2180 +.fill 1184 +.fill 6380 +.fill 1d81 +.fill 1010 +.fill 1dff +.fill 9180 +.fill 4001 +.fill ae01 +.fill 7fbd +.fill 6380 +.fill 1d81 +.fill 9040 +.fill 10d0 +.fill 11fb +.fill ff00 +.fill 2180 +.fill 1cd0 +.fill 6b80 +.fill 1d81 +.fill 6f80 +.fill 1d81 +.fill e000 +.fill 1dff +.fill 9f80 +.fill 1dff +.fill 9b80 +.fill 1ae0 +.fill 1dfb +.fill 10d0 .fill 11fc .fill 1dff .fill 9180 @@ -2105,7 +2203,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7dab +.fill 7eed .fill 6380 .fill 1d81 .fill 9040 @@ -2122,7 +2220,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e6b +.fill 7fad .fill 6380 .fill 1d81 .fill 9040 @@ -2139,7 +2237,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e73 +.fill 7fb5 .fill 6380 .fill 1d81 .fill 9040 @@ -2156,7 +2254,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e7b +.fill 7fbd .fill 6380 .fill 1d81 .fill 9040 @@ -2192,14 +2290,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 7e9c +.fill 7fde .fill 1dff .fill 9180 .fill 4601 @@ -2222,14 +2320,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 7eee +.fill 8030 .fill 1dff .fill 9180 .fill 4601 @@ -2252,14 +2350,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 7f18 +.fill 805a .fill 1dff .fill 9180 .fill 4601 @@ -2270,7 +2368,7 @@ .fill ae29 .fill 4001 .fill ae01 -.fill 7f49 +.fill 808b .fill 1dff .fill 9180 .fill 4601 @@ -2293,14 +2391,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 7f76 +.fill 80b8 .fill 1dff .fill 9180 .fill 4601 @@ -2323,7 +2421,7 @@ .fill 1ae0 .fill 4001 .fill ae01 -.fill 7dab +.fill 7eed .fill 1dff .fill 9180 .fill 10d0 @@ -2341,7 +2439,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a67 +.fill 7ba9 .fill c300 .fill 1d82 .fill 6380 @@ -2381,7 +2479,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a67 +.fill 7ba9 .fill c300 .fill 1d82 .fill 6380 @@ -2424,14 +2522,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a44d .fill 4001 .fill ae01 -.fill 7e7b +.fill 7fbd .fill 1dff .fill 9180 .fill 10d0 @@ -2473,7 +2571,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -2553,7 +2651,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -2573,7 +2671,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 2380 @@ -2594,7 +2692,7 @@ .fill 11ff .fill 4601 .fill ae01 -.fill 0b47 +.fill 0ba9 .fill b600 .fill ae00 .fill 10d0 @@ -2621,7 +2719,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -2650,7 +2748,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -2680,7 +2778,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ab +.fill 7aed .fill c300 .fill 1d82 .fill 2380 @@ -2741,7 +2839,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 @@ -2774,14 +2872,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a467 .fill 4001 .fill ae01 -.fill 7e7b +.fill 7fbd .fill 1dff .fill 9180 .fill 10d0 @@ -2849,7 +2947,7 @@ .fill 1d83 .fill 4001 .fill ae01 -.fill 7e7b +.fill 7fbd .fill 1dff .fill 9180 .fill 10d0 @@ -2944,7 +3042,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 2380 @@ -2979,7 +3077,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 2380 @@ -3000,7 +3098,7 @@ .fill 11ff .fill 4601 .fill ae01 -.fill 0d8e +.fill 0df0 .fill b600 .fill ae00 .fill 10d0 @@ -3027,7 +3125,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -3056,7 +3154,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -3086,7 +3184,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ab +.fill 7aed .fill c300 .fill 1d82 .fill 2380 @@ -3107,7 +3205,7 @@ .fill 11ff .fill 4601 .fill ae01 -.fill 0d8e +.fill 0df0 .fill b600 .fill ae00 .fill 10d0 @@ -3153,14 +3251,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a4b2 .fill 4001 .fill ae01 -.fill 7e7b +.fill 7fbd .fill 1dff .fill 9180 .fill 10d0 @@ -3188,7 +3286,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 @@ -3222,7 +3320,7 @@ .fill 1d83 .fill 4001 .fill ae01 -.fill 7e6b +.fill 7fad .fill 1dff .fill 9180 .fill 10d0 @@ -3235,7 +3333,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e6b +.fill 7fad .fill 1dff .fill 9180 .fill 10d0 @@ -3250,7 +3348,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e73 +.fill 7fb5 .fill 1dff .fill 9180 .fill 10d0 @@ -3263,7 +3361,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e73 +.fill 7fb5 .fill 1dff .fill 9180 .fill 10d0 @@ -3278,7 +3376,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e7b +.fill 7fbd .fill 1dff .fill 9180 .fill 10d0 @@ -3296,7 +3394,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e7b +.fill 7fbd .fill 1dff .fill 9180 .fill 10d0 @@ -3351,7 +3449,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -3374,7 +3472,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 090d +.fill 096f .fill c300 .fill 1d81 .fill 1dff @@ -3401,7 +3499,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 090d +.fill 096f .fill c300 .fill 1d81 .fill 1dff @@ -3413,7 +3511,7 @@ .fill 1d83 .fill 4001 .fill ae01 -.fill 7e6b +.fill 7fad .fill 1dff .fill 9180 .fill 10d0 @@ -3430,7 +3528,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e73 +.fill 7fb5 .fill 1dff .fill 9180 .fill 10d0 @@ -3448,7 +3546,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e7b +.fill 7fbd .fill 1dff .fill 9180 .fill 10d0 @@ -3495,7 +3593,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -3516,7 +3614,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 2380 @@ -3548,7 +3646,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 09d5 +.fill 0a37 .fill c300 .fill 1d81 .fill 6380 @@ -3568,7 +3666,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -3594,7 +3692,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 0934 +.fill 0996 .fill c300 .fill 1d81 .fill 1dff @@ -3611,7 +3709,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 0934 +.fill 0996 .fill c300 .fill 1d81 .fill 1dff @@ -3630,7 +3728,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e6b +.fill 7fad .fill 1dff .fill 9180 .fill 10d0 @@ -3649,7 +3747,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e73 +.fill 7fb5 .fill 1dff .fill 9180 .fill 10d0 @@ -3714,14 +3812,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a49f .fill 4001 .fill ae01 -.fill 7e7b +.fill 7fbd .fill 1dff .fill 9180 .fill 10d0 @@ -3740,7 +3838,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 090d +.fill 096f .fill c300 .fill 1d81 .fill 1dff @@ -3752,7 +3850,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 7fbe +.fill 8100 .fill 1dff .fill 9180 .fill 4601 @@ -3762,7 +3860,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 7e6b +.fill 7fad .fill 1dff .fill 9180 .fill 10d0 @@ -3781,7 +3879,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 7e73 +.fill 7fb5 .fill 1dff .fill 9180 .fill 10d0 @@ -3803,14 +3901,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 7fc1 +.fill 8103 .fill 1dff .fill 9180 .fill 4601 @@ -3821,7 +3919,7 @@ .fill ae23 .fill 4001 .fill ae01 -.fill 7e73 +.fill 7fb5 .fill 1dff .fill 9180 .fill 10d0 @@ -3835,7 +3933,7 @@ .fill a40b .fill 4001 .fill ae01 -.fill 7fdd +.fill 811f .fill 1dff .fill 9180 .fill 4601 @@ -3846,7 +3944,7 @@ .fill ae0a .fill 4001 .fill ae01 -.fill 7fee +.fill 8130 .fill 1dff .fill 9180 .fill 4601 @@ -3894,7 +3992,7 @@ .fill a40b .fill 4001 .fill ae01 -.fill 7ffc +.fill 813e .fill 1dff .fill 9180 .fill 4601 @@ -3905,7 +4003,7 @@ .fill ae00 .fill 4001 .fill ae01 -.fill 8006 +.fill 8148 .fill 1dff .fill 9180 .fill 4601 @@ -3925,7 +4023,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 800c +.fill 814e .fill 1dff .fill 9180 .fill 4601 @@ -3963,7 +4061,7 @@ .fill a410 .fill 4001 .fill ae01 -.fill 8045 +.fill 8187 .fill 1dff .fill 9180 .fill 4601 @@ -3974,7 +4072,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 1167 +.fill 11c9 .fill b600 .fill ae00 .fill 10d0 @@ -3988,7 +4086,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 095c +.fill 09be .fill c300 .fill 1d81 .fill 6380 @@ -4008,14 +4106,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a410 .fill 4001 .fill ae01 -.fill 8078 +.fill 81ba .fill 1dff .fill 9180 .fill 4601 @@ -4026,12 +4124,12 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 1167 +.fill 11c9 .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 809d +.fill 81df .fill 1dff .fill 9180 .fill 10d0 @@ -4055,14 +4153,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a45b .fill 4001 .fill ae01 -.fill 7e7b +.fill 7fbd .fill 1dff .fill 9180 .fill 10d0 @@ -4079,7 +4177,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e6b +.fill 7fad .fill 1dff .fill 9180 .fill 10d0 @@ -4096,7 +4194,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e73 +.fill 7fb5 .fill 1dff .fill 9180 .fill 10d0 @@ -4125,7 +4223,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 090d +.fill 096f .fill c300 .fill 1d81 .fill 1dff @@ -4137,7 +4235,7 @@ .fill 1d83 .fill 4001 .fill ae01 -.fill 80a4 +.fill 81e6 .fill 1dff .fill 9180 .fill 4601 @@ -4148,7 +4246,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 1167 +.fill 11c9 .fill b600 .fill ae00 .fill 10d0 @@ -4188,7 +4286,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 2380 @@ -4207,7 +4305,7 @@ .fill a40d .fill 4001 .fill ae01 -.fill 80ad +.fill 81ef .fill 1dff .fill 9180 .fill 4601 @@ -4225,7 +4323,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 095c +.fill 09be .fill c300 .fill 1d81 .fill 1dff @@ -4239,14 +4337,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 .fill a40d .fill 4001 .fill ae01 -.fill 80d1 +.fill 8213 .fill 1dff .fill 9180 .fill 4601 @@ -4259,7 +4357,7 @@ .fill ae00 .fill 4001 .fill ae01 -.fill 810d +.fill 824f .fill 1dff .fill 9180 .fill 10d0 @@ -4283,7 +4381,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -4302,7 +4400,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 090d +.fill 096f .fill c300 .fill 1d81 .fill 1dff @@ -4336,7 +4434,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 090d +.fill 096f .fill c300 .fill 1d81 .fill 1dff @@ -4348,7 +4446,7 @@ .fill 1d83 .fill 4001 .fill ae01 -.fill 8114 +.fill 8256 .fill 1dff .fill 9180 .fill 4601 @@ -4365,7 +4463,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e73 +.fill 7fb5 .fill 1dff .fill 9180 .fill 10d0 @@ -4379,7 +4477,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e6b +.fill 7fad .fill 1dff .fill 9180 .fill 10d0 @@ -4398,7 +4496,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 0934 +.fill 0996 .fill c300 .fill 1d81 .fill 1dff @@ -4427,14 +4525,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 811d +.fill 825f .fill 1dff .fill 9180 .fill 4601 @@ -4445,7 +4543,7 @@ .fill ae0a .fill 4001 .fill ae01 -.fill 814b +.fill 828d .fill 1dff .fill 9180 .fill 4601 @@ -4481,7 +4579,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 @@ -4502,7 +4600,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79d5 +.fill 7b17 .fill c300 .fill 1d82 .fill 2380 @@ -4534,7 +4632,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 @@ -4555,7 +4653,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79d5 +.fill 7b17 .fill c300 .fill 1d82 .fill 2380 @@ -4599,7 +4697,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -4642,7 +4740,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 @@ -4662,7 +4760,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79d5 +.fill 7b17 .fill c300 .fill 1d82 .fill 2380 @@ -4688,7 +4786,7 @@ .fill 9f80 .fill 4001 .fill ae01 -.fill 7e86 +.fill 7fc8 .fill 6000 .fill 2380 .fill 3100 @@ -4703,18 +4801,18 @@ .fill a418 .fill 4001 .fill ae01 -.fill 7e89 +.fill 7fcb .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e8b +.fill 7fcd .fill 6000 .fill 6380 .fill 1d81 @@ -4727,7 +4825,7 @@ .fill ae00 .fill 4001 .fill ae01 -.fill 7e86 +.fill 7fc8 .fill 1dff .fill 9180 .fill 2180 @@ -4737,7 +4835,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 2180 @@ -4760,11 +4858,11 @@ .fill aa04 .fill 4601 .fill ae01 -.fill 1491 +.fill 14f3 .fill b600 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6000 .fill 1dff @@ -4779,14 +4877,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa1e .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6000 .fill 1dff @@ -4801,7 +4899,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -4820,7 +4918,7 @@ .fill aa1e .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6000 .fill 1dff @@ -4835,7 +4933,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -4854,7 +4952,7 @@ .fill aa1e .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6000 .fill 1dff @@ -4869,7 +4967,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -4888,7 +4986,7 @@ .fill a40d .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 1dff .fill 9180 .fill 6000 @@ -4901,7 +4999,7 @@ .fill af77 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 1dff .fill 9180 @@ -4922,14 +5020,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a425 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 1dff .fill 9180 @@ -4951,7 +5049,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -4969,14 +5067,14 @@ .fill a436 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6000 .fill 1080 .fill a41e .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6000 .fill 1dff @@ -4991,7 +5089,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 2380 @@ -5009,7 +5107,7 @@ .fill a40d .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 1dff .fill 9180 .fill 6000 @@ -5023,7 +5121,7 @@ .fill aeef .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 1dff .fill 9180 @@ -5044,14 +5142,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a425 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 1dff .fill 9180 @@ -5073,7 +5171,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -5091,12 +5189,12 @@ .fill a4aa .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 1dff .fill 9180 @@ -5110,14 +5208,14 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6000 .fill 1080 .fill a455 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 1dff .fill 9180 @@ -5138,14 +5236,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a425 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 1dff .fill 9180 @@ -5167,7 +5265,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -5205,7 +5303,7 @@ .fill a40d .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 1dff .fill 9180 .fill 6000 @@ -5218,7 +5316,7 @@ .fill af94 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6000 .fill 2380 @@ -5236,17 +5334,17 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 1f20 +.fill 1f82 .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 1dff .fill 9180 @@ -5262,7 +5360,7 @@ .fill ae04 .fill 4601 .fill ae01 -.fill 1293 +.fill 12f5 .fill b600 .fill 10d0 .fill 11ff @@ -5270,7 +5368,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6000 .fill 6380 @@ -5305,14 +5403,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40f .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 2180 @@ -5322,7 +5420,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 1f20 +.fill 1f82 .fill b600 .fill ae00 .fill 10d0 @@ -5344,7 +5442,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6000 .fill 1dff @@ -5355,7 +5453,7 @@ .fill aa13 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6000 .fill 1dff @@ -5391,7 +5489,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -5400,7 +5498,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 1f20 +.fill 1f82 .fill b600 .fill ae00 .fill 4001 @@ -5426,7 +5524,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 1dff .fill 9180 .fill 6000 @@ -5460,7 +5558,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -5472,7 +5570,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 1f20 +.fill 1f82 .fill b600 .fill ae00 .fill 10d0 @@ -5486,11 +5584,11 @@ .fill aa04 .fill 4601 .fill ae01 -.fill 18c2 +.fill 1924 .fill b600 .fill 4001 .fill ae01 -.fill 7e85 +.fill 7fc7 .fill 1dff .fill 9180 .fill 2180 @@ -5516,7 +5614,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 1dff .fill 9180 @@ -5537,14 +5635,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a450 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 1dff .fill 9180 @@ -5567,14 +5665,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa26 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 1dff .fill 9180 @@ -5597,7 +5695,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -5636,12 +5734,12 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 1dff .fill 9180 @@ -5669,7 +5767,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -5690,7 +5788,7 @@ .fill aa04 .fill 4601 .fill ae01 -.fill 189e +.fill 1900 .fill b600 .fill 10d0 .fill 11fd @@ -5698,7 +5796,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6000 .fill 6380 @@ -5711,7 +5809,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 120f +.fill 1271 .fill c300 .fill 1d81 .fill 1080 @@ -5751,7 +5849,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -5772,7 +5870,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 2380 @@ -5804,7 +5902,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79d5 +.fill 7b17 .fill c300 .fill 1d82 .fill 2380 @@ -5863,7 +5961,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -5884,7 +5982,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 2380 @@ -5916,7 +6014,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79d5 +.fill 7b17 .fill c300 .fill 1d82 .fill 2380 @@ -5962,7 +6060,7 @@ .fill ae04 .fill 4601 .fill ae01 -.fill 189e +.fill 1900 .fill b600 .fill 10d0 .fill 11fd @@ -5980,14 +6078,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 .fill a405 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill ae00 .fill 10d0 @@ -6005,14 +6103,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a45f .fill 4001 .fill ae01 -.fill 7e85 +.fill 7fc7 .fill 6000 .fill 1dff .fill 9180 @@ -6027,14 +6125,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ab +.fill 7aed .fill c300 .fill 1d82 .fill 1080 .fill aa3d .fill 4001 .fill ae01 -.fill 7e85 +.fill 7fc7 .fill 6000 .fill 1dff .fill 9180 @@ -6049,7 +6147,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -6069,7 +6167,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ab +.fill 7aed .fill c300 .fill 1d82 .fill 2380 @@ -6123,7 +6221,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -6143,7 +6241,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -6186,14 +6284,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a416 .fill 4001 .fill ae01 -.fill 7e85 +.fill 7fc7 .fill 6000 .fill 1dff .fill 9180 @@ -6230,22 +6328,22 @@ .fill a40a .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 2180 .fill 4601 .fill ae01 -.fill 1f20 +.fill 1f82 .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 7e85 +.fill 7fc7 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e85 +.fill 7fc7 .fill 6000 .fill 1dff .fill 9180 @@ -6260,7 +6358,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a67 +.fill 7ba9 .fill c300 .fill 1d82 .fill 1dff @@ -6276,7 +6374,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 1dff .fill 9180 .fill 6000 @@ -6299,7 +6397,7 @@ .fill 10c0 .fill 4601 .fill ae01 -.fill 1635 +.fill 1697 .fill b600 .fill 10d0 .fill 11fe @@ -6317,12 +6415,12 @@ .fill a405 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill ae00 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -6334,7 +6432,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 1f20 +.fill 1f82 .fill b600 .fill ae00 .fill 10d0 @@ -6352,7 +6450,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -6372,7 +6470,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -6391,11 +6489,11 @@ .fill aa04 .fill 4601 .fill ae01 -.fill 1c13 +.fill 1c75 .fill b600 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 1dff .fill 9180 .fill 6000 @@ -6415,14 +6513,14 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6000 .fill 1080 .fill a41f .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6000 .fill 1dff @@ -6438,7 +6536,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 2380 @@ -6456,7 +6554,7 @@ .fill aa04 .fill 4601 .fill ae01 -.fill 1b7e +.fill 1be0 .fill b600 .fill 10d0 .fill 11fd @@ -6464,7 +6562,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 1dff .fill 9180 .fill 6000 @@ -6493,7 +6591,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -6513,7 +6611,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -6532,7 +6630,7 @@ .fill a405 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill ae00 .fill 10d0 @@ -6551,18 +6649,18 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa04 .fill 4601 .fill ae01 -.fill 1b26 +.fill 1b88 .fill b600 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6000 .fill 2380 @@ -6578,11 +6676,11 @@ .fill a409 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 4601 .fill ae01 -.fill 1b7e +.fill 1be0 .fill b600 .fill ae00 .fill 10d0 @@ -6591,7 +6689,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 1dff .fill 9180 .fill 6000 @@ -6621,7 +6719,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -6637,7 +6735,7 @@ .fill 9040 .fill 4601 .fill ae01 -.fill 1b25 +.fill 1b87 .fill b600 .fill 10d0 .fill 11fd @@ -6655,7 +6753,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -6671,7 +6769,7 @@ .fill 9040 .fill 4601 .fill ae01 -.fill 1b25 +.fill 1b87 .fill b600 .fill 10d0 .fill 11fd @@ -6689,7 +6787,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -6720,7 +6818,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -6751,7 +6849,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -6782,7 +6880,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -6813,7 +6911,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -6844,7 +6942,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 @@ -6864,7 +6962,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 2380 @@ -6895,7 +6993,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 2380 @@ -6926,7 +7024,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 2380 @@ -6944,7 +7042,7 @@ .fill a406 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill ae5a .fill ae00 @@ -6964,7 +7062,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -6983,7 +7081,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -7002,7 +7100,7 @@ .fill a406 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill ae20 .fill ae00 @@ -7035,11 +7133,11 @@ .fill 9040 .fill 4601 .fill ae01 -.fill 190e +.fill 1970 .fill b600 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6000 .fill 1dff @@ -7055,19 +7153,19 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 .fill a405 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill ae0c .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 1dff .fill 9180 .fill 6000 @@ -7109,7 +7207,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -7129,19 +7227,19 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 .fill a405 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill ae00 .fill 4001 .fill ae01 -.fill 7e85 +.fill 7fc7 .fill 1dff .fill 9180 .fill 4001 @@ -7159,7 +7257,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7171,7 +7269,7 @@ .fill ae0b .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7183,7 +7281,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 1f20 +.fill 1f82 .fill b600 .fill ae00 .fill 4001 @@ -7221,7 +7319,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 1dff .fill 9180 .fill 6000 @@ -7233,7 +7331,7 @@ .fill 10c0 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 10d0 @@ -7244,7 +7342,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6000 .fill 1dff @@ -7260,14 +7358,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa04 .fill 4601 .fill ae01 -.fill 1d68 +.fill 1dca .fill b600 .fill 10d0 .fill 11ff @@ -7284,14 +7382,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40c .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7317,14 +7415,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40c .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7349,14 +7447,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40c .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7381,14 +7479,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40c .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7413,14 +7511,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40c .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7445,14 +7543,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40c .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7477,7 +7575,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 @@ -7485,7 +7583,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 1f20 +.fill 1f82 .fill b600 .fill ae00 .fill 10d0 @@ -7503,14 +7601,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 .fill a412 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 1dff .fill 9180 .fill 6000 @@ -7523,13 +7621,13 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 1f20 +.fill 1f82 .fill b600 .fill ae00 .fill ae00 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6000 .fill 1dff @@ -7544,14 +7642,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa04 .fill 4601 .fill ae01 -.fill 1f1f +.fill 1f81 .fill b600 .fill 10d0 .fill 11ff @@ -7568,14 +7666,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40f .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7586,7 +7684,7 @@ .fill 9040 .fill 4601 .fill ae01 -.fill 1f12 +.fill 1f74 .fill b600 .fill 10d0 .fill 11ff @@ -7603,14 +7701,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40f .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7621,7 +7719,7 @@ .fill 9040 .fill 4601 .fill ae01 -.fill 1f12 +.fill 1f74 .fill b600 .fill 10d0 .fill 11ff @@ -7638,14 +7736,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40f .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7656,7 +7754,7 @@ .fill 9040 .fill 4601 .fill ae01 -.fill 1f12 +.fill 1f74 .fill b600 .fill 10d0 .fill 11ff @@ -7673,14 +7771,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40f .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7691,7 +7789,7 @@ .fill 9040 .fill 4601 .fill ae01 -.fill 1f12 +.fill 1f74 .fill b600 .fill 10d0 .fill 11ff @@ -7708,14 +7806,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40c .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7740,14 +7838,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40c .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7772,14 +7870,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40c .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7804,14 +7902,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40c .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7836,14 +7934,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40c .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7868,14 +7966,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40c .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7901,14 +7999,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40c .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7934,14 +8032,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40c .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 1dff .fill 9180 .fill 4001 @@ -7955,7 +8053,7 @@ .fill ae0e .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 1dff .fill 9180 .fill 6000 @@ -7980,7 +8078,7 @@ .fill 1ae0 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -7995,7 +8093,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -8026,7 +8124,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -8055,7 +8153,7 @@ .fill 1ae0 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -8070,21 +8168,21 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 .fill a407 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 2180 .fill ae06 .fill ae00 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 2180 .fill 1cd0 @@ -8100,7 +8198,7 @@ .fill 1ae0 .fill 4001 .fill ae01 -.fill 7e86 +.fill 7fc8 .fill 6000 .fill 1080 .fill a403 @@ -8109,7 +8207,7 @@ .fill ae00 .fill 4001 .fill ae01 -.fill 7e87 +.fill 7fc9 .fill 6000 .fill 1dff .fill 9180 @@ -8124,14 +8222,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 .fill a407 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 2180 .fill ae1e @@ -8143,7 +8241,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e87 +.fill 7fc9 .fill 1dff .fill 9180 .fill 6000 @@ -8197,7 +8295,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a67 +.fill 7ba9 .fill c300 .fill 1d82 .fill 6380 @@ -8280,7 +8378,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e87 +.fill 7fc9 .fill 6000 .fill 1dff .fill 9180 @@ -8336,7 +8434,7 @@ .fill 1ae0 .fill 4001 .fill ae01 -.fill 7e86 +.fill 7fc8 .fill 6000 .fill 2380 .fill 3100 @@ -8369,7 +8467,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e87 +.fill 7fc9 .fill 6000 .fill 6380 .fill 1d81 @@ -8477,7 +8575,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e88 +.fill 7fca .fill 6000 .fill 6380 .fill 1d81 @@ -8487,7 +8585,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -8517,7 +8615,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a67 +.fill 7ba9 .fill c300 .fill 1d82 .fill 6380 @@ -8541,7 +8639,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -8669,7 +8767,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill ae01 @@ -8701,7 +8799,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ab +.fill 7aed .fill c300 .fill 1d82 .fill ae01 @@ -8733,7 +8831,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79d5 +.fill 7b17 .fill c300 .fill 1d82 .fill ae01 @@ -8765,7 +8863,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill ae01 @@ -8797,7 +8895,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill ae01 @@ -8829,7 +8927,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill ae01 @@ -8861,7 +8959,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a67 +.fill 7ba9 .fill c300 .fill 1d82 .fill ae01 @@ -8893,7 +8991,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7b36 +.fill 7c78 .fill c300 .fill 1d82 .fill ae01 @@ -8925,7 +9023,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7bd5 +.fill 7d17 .fill c300 .fill 1d82 .fill ae01 @@ -9000,7 +9098,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7c14 +.fill 7d56 .fill c300 .fill 1d82 .fill ae01 @@ -9032,7 +9130,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7c2f +.fill 7d71 .fill c300 .fill 1d82 .fill ae01 @@ -9064,7 +9162,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7c59 +.fill 7d9b .fill c300 .fill 1d82 .fill ae01 @@ -9096,7 +9194,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7cc7 +.fill 7e09 .fill c300 .fill 1d82 .fill ae01 @@ -9168,7 +9266,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -9177,7 +9275,7 @@ .fill 1181 .fill 4601 .fill ae01 -.fill 25d0 +.fill 2632 .fill b600 .fill ae00 .fill 10d0 @@ -9196,7 +9294,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -9205,7 +9303,7 @@ .fill 1182 .fill 4601 .fill ae01 -.fill 25d0 +.fill 2632 .fill b600 .fill ae00 .fill 10d0 @@ -9224,7 +9322,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -9233,7 +9331,7 @@ .fill 1183 .fill 4601 .fill ae01 -.fill 25d0 +.fill 2632 .fill b600 .fill ae00 .fill 10d0 @@ -9252,7 +9350,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -9261,7 +9359,7 @@ .fill 1184 .fill 4601 .fill ae01 -.fill 25d0 +.fill 2632 .fill b600 .fill ae00 .fill 10d0 @@ -9279,7 +9377,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -9288,7 +9386,7 @@ .fill 1185 .fill 4601 .fill ae01 -.fill 25d0 +.fill 2632 .fill b600 .fill ae00 .fill 10d0 @@ -9307,7 +9405,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -9328,7 +9426,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -9349,7 +9447,7 @@ .fill 1186 .fill 4601 .fill ae01 -.fill 25d0 +.fill 2632 .fill b600 .fill ae00 .fill 10d0 @@ -9367,7 +9465,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -9387,7 +9485,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -9420,7 +9518,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -9453,7 +9551,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -9490,7 +9588,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -9511,7 +9609,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -9547,7 +9645,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -9567,7 +9665,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -9603,7 +9701,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -9623,7 +9721,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -9655,7 +9753,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -9706,7 +9804,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -9726,7 +9824,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -9758,7 +9856,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -9770,7 +9868,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -9780,7 +9878,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill ae00 @@ -9791,13 +9889,13 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 2180 .fill 4601 .fill ae01 -.fill 2825 +.fill 2887 .fill b600 .fill ae00 .fill 10d0 @@ -9815,7 +9913,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -9827,18 +9925,18 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 2180 .fill 4601 .fill ae01 -.fill 2825 +.fill 2887 .fill b600 .fill ae00 .fill 4601 .fill ae01 -.fill 2025 +.fill 2087 .fill c300 .fill 4001 .fill ae01 @@ -9847,7 +9945,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -9857,7 +9955,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 10d0 @@ -9875,7 +9973,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -9886,13 +9984,13 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 2289 +.fill 22eb .fill 6380 .fill 1d81 .fill 9040 .fill 4601 .fill ae01 -.fill 2816 +.fill 2878 .fill b600 .fill 10d0 .fill 1182 @@ -9909,7 +10007,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -9920,13 +10018,13 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 22a9 +.fill 230b .fill 6380 .fill 1d81 .fill 9040 .fill 4601 .fill ae01 -.fill 2816 +.fill 2878 .fill b600 .fill 10d0 .fill 1182 @@ -9943,7 +10041,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -9954,13 +10052,13 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 22c9 +.fill 232b .fill 6380 .fill 1d81 .fill 9040 .fill 4601 .fill ae01 -.fill 2816 +.fill 2878 .fill b600 .fill 10d0 .fill 1182 @@ -9978,7 +10076,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -9989,13 +10087,13 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 2314 +.fill 2376 .fill 6380 .fill 1d81 .fill 9040 .fill 4601 .fill ae01 -.fill 2816 +.fill 2878 .fill b600 .fill 10d0 .fill 1182 @@ -10013,7 +10111,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -10024,7 +10122,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 2334 +.fill 2396 .fill 6380 .fill 1d81 .fill 9040 @@ -10045,7 +10143,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -10056,7 +10154,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 2354 +.fill 23b6 .fill 6380 .fill 1d81 .fill 9040 @@ -10077,7 +10175,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -10088,7 +10186,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 2374 +.fill 23d6 .fill 6380 .fill 1d81 .fill 9040 @@ -10109,7 +10207,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -10120,7 +10218,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 2249 +.fill 22ab .fill 6380 .fill 1d81 .fill 9040 @@ -10141,7 +10239,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -10152,7 +10250,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 2269 +.fill 22cb .fill 6380 .fill 1d81 .fill 9040 @@ -10172,7 +10270,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -10183,7 +10281,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 21c9 +.fill 222b .fill 6380 .fill 1d81 .fill 9040 @@ -10203,7 +10301,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -10214,7 +10312,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 21e9 +.fill 224b .fill 6380 .fill 1d81 .fill 9040 @@ -10235,7 +10333,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -10246,7 +10344,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 2209 +.fill 226b .fill 6380 .fill 1d81 .fill 9040 @@ -10257,7 +10355,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 2229 +.fill 228b .fill 6380 .fill 1d81 .fill 9040 @@ -10272,7 +10370,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 20c2 +.fill 2124 .fill c300 .fill 1d82 .fill 2180 @@ -10290,19 +10388,19 @@ .fill 1dfa .fill 4001 .fill ae01 -.fill 7e86 +.fill 7fc8 .fill 6000 .fill 1080 .fill a406 .fill 2180 .fill 4601 .fill ae01 -.fill 2d72 +.fill 2dd4 .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 7e8a +.fill 7fcc .fill 1dff .fill 9180 .fill 6000 @@ -10314,7 +10412,7 @@ .fill 10c0 .fill 4001 .fill ae01 -.fill 7e8a +.fill 7fcc .fill 6000 .fill 1dff .fill 9180 @@ -10328,24 +10426,24 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ab +.fill 7aed .fill c300 .fill 1d82 .fill 1080 .fill a40a .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 2180 .fill 4601 .fill ae01 -.fill 2d72 +.fill 2dd4 .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 7e8d +.fill 7fcf .fill 1dff .fill 9180 .fill 2180 @@ -10354,7 +10452,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -10369,14 +10467,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a416 .fill 4001 .fill ae01 -.fill 7e85 +.fill 7fc7 .fill 6000 .fill 1dff .fill 9180 @@ -10385,20 +10483,20 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1fec +.fill 204e .fill c300 .fill 1d82 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 4601 .fill ae01 -.fill 2d65 +.fill 2dc7 .fill b600 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -10413,7 +10511,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -10427,7 +10525,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 204d +.fill 20af .fill c300 .fill 1d81 .fill 6380 @@ -10439,7 +10537,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e87 +.fill 7fc9 .fill 6000 .fill 6380 .fill 1d81 @@ -10485,7 +10583,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -10506,7 +10604,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 10d0 @@ -10523,11 +10621,11 @@ .fill afcc .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -10542,7 +10640,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -10552,7 +10650,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 10d0 @@ -10562,7 +10660,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 208a +.fill 20ec .fill c300 .fill 1d81 .fill 4001 @@ -10583,16 +10681,16 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1fec +.fill 204e .fill c300 .fill 1d82 .fill 4601 .fill ae01 -.fill 2d65 +.fill 2dc7 .fill b600 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -10606,18 +10704,18 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a415 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 4601 .fill ae01 -.fill 2f06 +.fill 2f68 .fill c300 .fill 2180 .fill 11a9 @@ -10625,16 +10723,16 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f71 +.fill 1fd3 .fill c300 .fill 1d81 .fill 4601 .fill ae01 -.fill 2d65 +.fill 2dc7 .fill b600 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -10648,14 +10746,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa1d .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -10669,7 +10767,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -10688,7 +10786,7 @@ .fill aa1d .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -10702,7 +10800,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -10721,7 +10819,7 @@ .fill aa1e .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -10736,7 +10834,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -10759,19 +10857,19 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill ce19 .fill 4601 .fill ae01 -.fill 2025 +.fill 2087 .fill c300 .fill 10d0 .fill 11fb @@ -10788,7 +10886,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -10799,12 +10897,12 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 22e9 +.fill 234b .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 20c2 +.fill 2124 .fill c300 .fill 1d82 .fill ae57 @@ -10823,7 +10921,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -10834,12 +10932,12 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 22fb +.fill 235d .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 20c2 +.fill 2124 .fill c300 .fill 1d82 .fill ae34 @@ -10850,7 +10948,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -10860,7 +10958,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 10d0 @@ -10879,7 +10977,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -10891,13 +10989,13 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill ae00 .fill 4001 .fill ae01 -.fill 7e8d +.fill 7fcf .fill 1dff .fill 9180 .fill 2180 @@ -10906,11 +11004,11 @@ .fill 9040 .fill 4601 .fill ae01 -.fill 2d65 +.fill 2dc7 .fill b600 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -10925,14 +11023,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa1e .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -10947,7 +11045,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -10970,14 +11068,14 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 10d0 .fill 11ff @@ -10990,7 +11088,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 2109 +.fill 216b .fill c300 .fill 1d81 .fill 6380 @@ -10998,7 +11096,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -11013,7 +11111,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 @@ -11032,7 +11130,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 2380 @@ -11051,17 +11149,17 @@ .fill a40a .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 2180 .fill 4601 .fill ae01 -.fill 2d72 +.fill 2dd4 .fill b600 .fill ae00 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 10d0 .fill 11ff @@ -11070,7 +11168,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 217e +.fill 21e0 .fill c300 .fill 1d81 .fill 10d0 @@ -11089,7 +11187,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -11101,7 +11199,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill ae0a @@ -11112,7 +11210,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 10d0 @@ -11122,16 +11220,16 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 21a3 +.fill 2205 .fill c300 .fill 1d81 .fill 4601 .fill ae01 -.fill 2d65 +.fill 2dc7 .fill b600 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -11146,14 +11244,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa04 .fill 4601 .fill ae01 -.fill 2d61 +.fill 2dc3 .fill b600 .fill 10d0 .fill 11ff @@ -11166,7 +11264,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 2109 +.fill 216b .fill c300 .fill 1d81 .fill 6380 @@ -11186,14 +11284,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 .fill aa04 .fill 4601 .fill ae01 -.fill 2d5c +.fill 2dbe .fill b600 .fill 10d0 .fill 11fa @@ -11205,7 +11303,7 @@ .fill 9040 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 10d0 .fill 11ff @@ -11214,12 +11312,12 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 217e +.fill 21e0 .fill c300 .fill 1d81 .fill 4001 .fill ae01 -.fill 7e86 +.fill 7fc8 .fill 6000 .fill 2380 .fill 3100 @@ -11250,7 +11348,7 @@ .fill a440 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -11265,14 +11363,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa1e .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -11287,7 +11385,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -11321,18 +11419,18 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 4601 .fill ae01 -.fill 2025 +.fill 2087 .fill c300 .fill 10d0 .fill 11fb @@ -11350,7 +11448,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -11362,7 +11460,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill ae0a @@ -11373,7 +11471,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -11383,12 +11481,12 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4601 .fill ae01 -.fill 2039 +.fill 209b .fill c300 .fill 4001 .fill ae01 @@ -11397,7 +11495,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -11407,13 +11505,13 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill ae00 .fill 4001 .fill ae01 -.fill 7e86 +.fill 7fc8 .fill 6000 .fill 2380 .fill 3100 @@ -11453,7 +11551,7 @@ .fill a440 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -11468,14 +11566,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa1e .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -11490,7 +11588,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -11524,18 +11622,18 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 4601 .fill ae01 -.fill 2025 +.fill 2087 .fill c300 .fill 10d0 .fill 11fb @@ -11553,7 +11651,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -11565,7 +11663,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill ae0a @@ -11576,7 +11674,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 10d0 @@ -11586,7 +11684,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 21a3 +.fill 2205 .fill c300 .fill 1d81 .fill 4001 @@ -11596,7 +11694,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -11606,23 +11704,23 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill ae00 .fill ae04 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill ae04 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 4001 .fill ae01 -.fill 7e8a +.fill 7fcc .fill 1dff .fill 9180 .fill 6000 @@ -11647,7 +11745,7 @@ .fill 1dfc .fill 4601 .fill ae01 -.fill 282b +.fill 288d .fill c300 .fill 10d0 .fill 11fe @@ -11655,13 +11753,13 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 23bc +.fill 241e .fill c300 .fill 1d81 .fill 6380 @@ -11669,7 +11767,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e86 +.fill 7fc8 .fill 6000 .fill 2380 .fill 3100 @@ -11698,7 +11796,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 2380 @@ -11732,7 +11830,7 @@ .fill aa04 .fill 4601 .fill ae01 -.fill 2eff +.fill 2f61 .fill b600 .fill 10d0 .fill 11ff @@ -11740,18 +11838,18 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 4001 .fill ae01 -.fill 7e8d +.fill 7fcf .fill 1dff .fill 9180 .fill 2180 @@ -11774,7 +11872,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -11795,7 +11893,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -11819,7 +11917,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 10d0 @@ -11838,7 +11936,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -11850,7 +11948,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill ae0a @@ -11861,7 +11959,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 10d0 @@ -11873,7 +11971,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 204d +.fill 20af .fill c300 .fill 1d81 .fill 6380 @@ -11895,7 +11993,7 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 2025 +.fill 2087 .fill c300 .fill 2180 .fill 1181 @@ -11903,12 +12001,12 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 2394 +.fill 23f6 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 20c2 +.fill 2124 .fill c300 .fill 1d82 .fill 10d0 @@ -11920,7 +12018,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 204d +.fill 20af .fill c300 .fill 1d81 .fill 6380 @@ -11933,7 +12031,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 208a +.fill 20ec .fill c300 .fill 1d81 .fill 10d0 @@ -11952,7 +12050,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1dff @@ -11962,7 +12060,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1fec +.fill 204e .fill c300 .fill 1d82 .fill 10d0 @@ -11972,13 +12070,13 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 208a +.fill 20ec .fill c300 .fill 1d81 .fill ae20 .fill 4601 .fill ae01 -.fill 2025 +.fill 2087 .fill c300 .fill 10d0 .fill 11fe @@ -11996,7 +12094,7 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 2039 +.fill 209b .fill c300 .fill 10d0 .fill 11ff @@ -12005,7 +12103,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 25d6 +.fill 2638 .fill c300 .fill 1d81 .fill 10d0 @@ -12014,13 +12112,13 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 23bc +.fill 241e .fill c300 .fill 1d81 .fill 6380 @@ -12028,7 +12126,7 @@ .fill 9040 .fill 4601 .fill ae01 -.fill 2d94 +.fill 2df6 .fill b600 .fill 2180 .fill 1cd0 @@ -12069,14 +12167,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 .fill a417 .fill 4001 .fill ae01 -.fill 7e86 +.fill 7fc8 .fill 6000 .fill 2380 .fill 3100 @@ -12172,7 +12270,7 @@ .fill 1de5 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -12187,14 +12285,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa1e .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -12209,7 +12307,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -12228,17 +12326,17 @@ .fill a40a .fill 4601 .fill ae01 -.fill 282b +.fill 288d .fill c300 .fill 2180 .fill 4601 .fill ae01 -.fill 33f9 +.fill 345b .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -12253,7 +12351,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 @@ -12280,7 +12378,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 2380 @@ -12299,12 +12397,12 @@ .fill a40a .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 2180 .fill 4601 .fill ae01 -.fill 33f9 +.fill 345b .fill b600 .fill ae00 .fill 4001 @@ -12342,7 +12440,7 @@ .fill 1d83 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 10d0 .fill 11e5 @@ -12350,7 +12448,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 6380 .fill 1d81 @@ -12371,7 +12469,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -12392,7 +12490,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -12419,7 +12517,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 2109 +.fill 216b .fill c300 .fill 1d81 .fill 6380 @@ -12439,24 +12537,24 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a40a .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 2180 .fill 4601 .fill ae01 -.fill 33f9 +.fill 345b .fill b600 .fill ae00 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 10d0 .fill 11e7 @@ -12465,7 +12563,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 217e +.fill 21e0 .fill c300 .fill 1d81 .fill 10d0 @@ -12484,7 +12582,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -12496,7 +12594,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill ae0a @@ -12507,7 +12605,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 10d0 @@ -12517,12 +12615,12 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 21a3 +.fill 2205 .fill c300 .fill 1d81 .fill 4601 .fill ae01 -.fill 33f8 +.fill 345a .fill b600 .fill 10d0 .fill 11e5 @@ -12539,7 +12637,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -12560,7 +12658,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 @@ -12581,7 +12679,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79d5 +.fill 7b17 .fill c300 .fill 1d82 .fill 2380 @@ -12611,7 +12709,7 @@ .fill aa04 .fill 4601 .fill ae01 -.fill 32b0 +.fill 3312 .fill b600 .fill 10d0 .fill 11e7 @@ -12623,7 +12721,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 2109 +.fill 216b .fill c300 .fill 1d81 .fill 6380 @@ -12643,19 +12741,19 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a40a .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 2180 .fill 4601 .fill ae01 -.fill 33f9 +.fill 345b .fill b600 .fill ae00 .fill 10d0 @@ -12673,7 +12771,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 @@ -12685,17 +12783,17 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 217e +.fill 21e0 .fill c300 .fill 1d81 .fill 4601 .fill ae01 -.fill 2025 +.fill 2087 .fill c300 .fill ae00 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill cd6b .fill 10d0 @@ -12713,14 +12811,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 .fill a4f3 .fill 4601 .fill ae01 -.fill 2039 +.fill 209b .fill c300 .fill 10d0 .fill 11e5 @@ -12738,7 +12836,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -12769,7 +12867,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -12800,7 +12898,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -12831,7 +12929,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -12862,7 +12960,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -12893,7 +12991,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -12924,7 +13022,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -12957,7 +13055,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 25d6 +.fill 2638 .fill c300 .fill 1d81 .fill ae00 @@ -12968,12 +13066,12 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 21a3 +.fill 2205 .fill c300 .fill 1d81 .fill 4601 .fill ae01 -.fill 33f8 +.fill 345a .fill b600 .fill 10d0 .fill 11e5 @@ -12990,14 +13088,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa04 .fill 4601 .fill ae01 -.fill 33f4 +.fill 3456 .fill b600 .fill 10d0 .fill 11e6 @@ -13009,7 +13107,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 8153 +.fill 8295 .fill 1dff .fill 9180 .fill 10d0 @@ -13032,7 +13130,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -13050,7 +13148,7 @@ .fill aea3 .fill 4001 .fill ae01 -.fill 8159 +.fill 829b .fill 1dff .fill 9180 .fill 10d0 @@ -13073,7 +13171,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -13091,7 +13189,7 @@ .fill ae7a .fill 4001 .fill ae01 -.fill 8161 +.fill 82a3 .fill 1dff .fill 9180 .fill 10d0 @@ -13114,7 +13212,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -13132,7 +13230,7 @@ .fill ae51 .fill 4001 .fill ae01 -.fill 816b +.fill 82ad .fill 1dff .fill 9180 .fill 10d0 @@ -13155,7 +13253,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -13173,7 +13271,7 @@ .fill ae28 .fill 4001 .fill ae01 -.fill 8175 +.fill 82b7 .fill 1dff .fill 9180 .fill 10d0 @@ -13196,7 +13294,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -13227,18 +13325,18 @@ .fill a407 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 2180 .fill ae49 .fill ae00 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 4601 .fill ae01 -.fill 2f06 +.fill 2f68 .fill c300 .fill 2180 .fill 11a9 @@ -13246,7 +13344,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f71 +.fill 1fd3 .fill c300 .fill 1d81 .fill 10d0 @@ -13264,7 +13362,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -13276,13 +13374,13 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill ae12 .fill 4601 .fill ae01 -.fill 2025 +.fill 2087 .fill c300 .fill 2180 .fill 1181 @@ -13295,13 +13393,13 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 20c2 +.fill 2124 .fill c300 .fill 1d82 .fill ae04 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 2180 .fill 1cd0 @@ -13318,19 +13416,19 @@ .fill 1de2 .fill 4001 .fill ae01 -.fill 7e86 +.fill 7fc8 .fill 6000 .fill 1080 .fill a406 .fill 2180 .fill 4601 .fill ae01 -.fill 3b08 +.fill 3b6a .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 7e8a +.fill 7fcc .fill 1dff .fill 9180 .fill 6000 @@ -13342,7 +13440,7 @@ .fill 10c0 .fill 4001 .fill ae01 -.fill 7e8a +.fill 7fcc .fill 6000 .fill 1dff .fill 9180 @@ -13356,24 +13454,24 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ab +.fill 7aed .fill c300 .fill 1d82 .fill 1080 .fill a40a .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 2180 .fill 4601 .fill ae01 -.fill 3b08 +.fill 3b6a .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -13388,18 +13486,18 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a455 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 4001 .fill ae01 -.fill 7e86 +.fill 7fc8 .fill 6000 .fill 2380 .fill 3100 @@ -13414,7 +13512,7 @@ .fill a40e .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 2380 .fill 3100 @@ -13431,7 +13529,7 @@ .fill a41e .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -13446,7 +13544,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 2380 @@ -13471,36 +13569,36 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f71 +.fill 1fd3 .fill c300 .fill 1d81 .fill 4601 .fill ae01 -.fill 3afb +.fill 3b5d .fill b600 .fill 4001 .fill ae01 -.fill 817e +.fill 82c0 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 1f26 +.fill 1f88 .fill c300 .fill 1d81 .fill 1080 .fill aa04 .fill 4601 .fill ae01 -.fill 3623 +.fill 3685 .fill b600 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -13515,7 +13613,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 @@ -13542,7 +13640,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 2380 @@ -13561,12 +13659,12 @@ .fill a40a .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 2180 .fill 4601 .fill ae01 -.fill 3b08 +.fill 3b6a .fill b600 .fill ae00 .fill 4001 @@ -13604,11 +13702,11 @@ .fill 1d83 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 4001 .fill ae01 -.fill 7e88 +.fill 7fca .fill 6000 .fill 1dff .fill 9180 @@ -13622,7 +13720,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -13633,7 +13731,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 2109 +.fill 216b .fill c300 .fill 1d81 .fill 1dff @@ -13647,7 +13745,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 2380 @@ -13666,12 +13764,12 @@ .fill a40a .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 2180 .fill 4601 .fill ae01 -.fill 3b08 +.fill 3b6a .fill b600 .fill ae00 .fill 10d0 @@ -13680,7 +13778,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e88 +.fill 7fca .fill 1dff .fill 9180 .fill 6000 @@ -13735,7 +13833,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a67 +.fill 7ba9 .fill c300 .fill 1d82 .fill 6380 @@ -13750,7 +13848,7 @@ .fill 1d83 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -13764,18 +13862,18 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a409 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 4601 .fill ae01 -.fill 2f06 +.fill 2f68 .fill c300 .fill ae0b .fill 2180 @@ -13786,7 +13884,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1fec +.fill 204e .fill c300 .fill 1d82 .fill 10d0 @@ -13796,12 +13894,12 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 21a3 +.fill 2205 .fill c300 .fill 1d81 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -13815,7 +13913,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 @@ -13824,11 +13922,11 @@ .fill ae00 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 4001 .fill ae01 -.fill 7e86 +.fill 7fc8 .fill 6000 .fill 2380 .fill 3100 @@ -13843,7 +13941,7 @@ .fill a404 .fill 4601 .fill ae01 -.fill 34bb +.fill 351d .fill b600 .fill 2180 .fill 11bb @@ -13851,32 +13949,32 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f71 +.fill 1fd3 .fill c300 .fill 1d81 .fill 4601 .fill ae01 -.fill 3afb +.fill 3b5d .fill b600 .fill 4001 .fill ae01 -.fill 8182 +.fill 82c4 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 1f26 +.fill 1f88 .fill c300 .fill 1d81 .fill 1080 .fill a472 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -13890,7 +13988,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -13903,13 +14001,13 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1fec +.fill 204e .fill c300 .fill 1d82 .fill ae04 .fill 4601 .fill ae01 -.fill 2f06 +.fill 2f68 .fill c300 .fill 4001 .fill ae01 @@ -13918,7 +14016,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -13928,7 +14026,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -13938,7 +14036,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -13948,7 +14046,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -13958,7 +14056,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -13968,7 +14066,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 2180 @@ -13977,33 +14075,33 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f71 +.fill 1fd3 .fill c300 .fill 1d81 .fill 4601 .fill ae01 -.fill 3afb +.fill 3b5d .fill b600 .fill 4001 .fill ae01 -.fill 8189 +.fill 82cb .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 1f26 +.fill 1f88 .fill c300 .fill 1d81 .fill 1080 .fill aa14 .fill 4001 .fill ae01 -.fill 818f +.fill 82d1 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 1f26 +.fill 1f88 .fill c300 .fill 1d81 .fill 2380 @@ -14026,12 +14124,12 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 818f +.fill 82d1 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 1f26 +.fill 1f88 .fill c300 .fill 1d81 .fill 6380 @@ -14039,7 +14137,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 6000 .fill 2380 .fill 3100 @@ -14054,17 +14152,17 @@ .fill a40a .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 2180 .fill 4601 .fill ae01 -.fill 3b08 +.fill 3b6a .fill b600 .fill ae00 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 10d0 .fill 11fd @@ -14075,7 +14173,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 204d +.fill 20af .fill c300 .fill 1d81 .fill 6380 @@ -14106,7 +14204,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 6000 .fill 1dff .fill 9180 @@ -14131,7 +14229,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 6000 .fill 1dff .fill 9180 @@ -14174,7 +14272,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 6000 .fill 1dff .fill 9180 @@ -14199,7 +14297,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 6000 .fill 1dff .fill 9180 @@ -14227,32 +14325,32 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f71 +.fill 1fd3 .fill c300 .fill 1d81 .fill 4601 .fill ae01 -.fill 3afb +.fill 3b5d .fill b600 .fill 4001 .fill ae01 -.fill 8198 +.fill 82da .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 1f26 +.fill 1f88 .fill c300 .fill 1d81 .fill 1080 .fill aa04 .fill 4601 .fill ae01 -.fill 3915 +.fill 3977 .fill b600 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 6000 .fill 1dff .fill 9180 @@ -14266,24 +14364,24 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40a .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 2180 .fill 4601 .fill ae01 -.fill 3b08 +.fill 3b6a .fill b600 .fill ae00 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 2180 .fill 11a8 @@ -14291,12 +14389,12 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f71 +.fill 1fd3 .fill c300 .fill 1d81 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -14310,14 +14408,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a405 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill ae01 .fill cc0d @@ -14327,14 +14425,14 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e87 +.fill 7fc9 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -14348,7 +14446,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -14362,13 +14460,13 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1fec +.fill 204e .fill c300 .fill 1d82 .fill ae04 .fill 4601 .fill ae01 -.fill 2f06 +.fill 2f68 .fill c300 .fill 2180 .fill 11bb @@ -14376,7 +14474,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f71 +.fill 1fd3 .fill c300 .fill 1d81 .fill 10d0 @@ -14385,7 +14483,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 20ef +.fill 2151 .fill c300 .fill 6380 .fill 1d81 @@ -14399,7 +14497,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 204d +.fill 20af .fill c300 .fill 1d81 .fill 6380 @@ -14411,14 +14509,14 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e87 +.fill 7fc9 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -14432,14 +14530,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 .fill a405 .fill 4601 .fill ae01 -.fill 2f85 +.fill 2fe7 .fill c300 .fill ae00 .fill 2180 @@ -14448,7 +14546,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f71 +.fill 1fd3 .fill c300 .fill 1d81 .fill 10d0 @@ -14458,7 +14556,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 204d +.fill 20af .fill c300 .fill 1d81 .fill 10d0 @@ -14468,7 +14566,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 208a +.fill 20ec .fill c300 .fill 1d81 .fill 4001 @@ -14478,7 +14576,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 6000 .fill 6380 .fill 1d81 @@ -14497,7 +14595,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 6000 .fill 6380 .fill 1d81 @@ -14511,7 +14609,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 1dff .fill 9180 .fill 6000 @@ -14523,11 +14621,11 @@ .fill 10c0 .fill 4601 .fill ae01 -.fill 33ff +.fill 3461 .fill c300 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 1dff .fill 9180 .fill 6000 @@ -14544,7 +14642,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 204d +.fill 20af .fill c300 .fill 1d81 .fill 10d0 @@ -14554,12 +14652,12 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 208a +.fill 20ec .fill c300 .fill 1d81 .fill 4001 .fill ae01 -.fill 7e87 +.fill 7fc9 .fill 6000 .fill 1dff .fill 9180 @@ -14570,7 +14668,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 6000 .fill 6380 .fill 1d81 @@ -14580,7 +14678,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 2f12 +.fill 2f74 .fill c300 .fill 1d82 .fill 10d0 @@ -14595,7 +14693,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 6000 .fill 6380 .fill 1d81 @@ -14605,33 +14703,33 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 2f12 +.fill 2f74 .fill c300 .fill 1d82 .fill 4601 .fill ae01 -.fill 3afb +.fill 3b5d .fill b600 .fill 4001 .fill ae01 -.fill 819c +.fill 82de .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 1f26 +.fill 1f88 .fill c300 .fill 1d81 .fill 1080 .fill aa14 .fill 4001 .fill ae01 -.fill 819f +.fill 82e1 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 1f26 +.fill 1f88 .fill c300 .fill 1d81 .fill 2380 @@ -14650,7 +14748,7 @@ .fill aa04 .fill 4601 .fill ae01 -.fill 3a75 +.fill 3ad7 .fill b600 .fill 10d0 .fill 11ff @@ -14658,12 +14756,12 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 819f +.fill 82e1 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 1f26 +.fill 1f88 .fill c300 .fill 1d81 .fill 6380 @@ -14671,7 +14769,7 @@ .fill 9040 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 2180 .fill 11a8 @@ -14679,7 +14777,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f71 +.fill 1fd3 .fill c300 .fill 1d81 .fill 10d0 @@ -14688,14 +14786,14 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e87 +.fill 7fc9 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4601 .fill ae01 -.fill 2f06 +.fill 2f68 .fill c300 .fill 2180 .fill 11a9 @@ -14703,7 +14801,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f71 +.fill 1fd3 .fill c300 .fill 1d81 .fill 10d0 @@ -14712,7 +14810,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 20ef +.fill 2151 .fill c300 .fill 6380 .fill 1d81 @@ -14724,7 +14822,7 @@ .fill a452 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 6000 .fill 1dff .fill 9180 @@ -14738,19 +14836,19 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40a .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 2180 .fill 4601 .fill ae01 -.fill 3b08 +.fill 3b6a .fill b600 .fill ae00 .fill 4001 @@ -14760,7 +14858,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 6000 .fill 6380 .fill 1d81 @@ -14779,7 +14877,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 6000 .fill 6380 .fill 1d81 @@ -14793,7 +14891,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 1dff .fill 9180 .fill 6000 @@ -14806,7 +14904,7 @@ .fill ae00 .fill 4601 .fill ae01 -.fill 33ff +.fill 3461 .fill c300 .fill 10d0 .fill 11ff @@ -14815,7 +14913,7 @@ .fill a454 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 1dff .fill 9180 .fill 6000 @@ -14832,7 +14930,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 204d +.fill 20af .fill c300 .fill 1d81 .fill 10d0 @@ -14842,12 +14940,12 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 208a +.fill 20ec .fill c300 .fill 1d81 .fill 4001 .fill ae01 -.fill 7e87 +.fill 7fc9 .fill 6000 .fill 1dff .fill 9180 @@ -14858,7 +14956,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 6000 .fill 6380 .fill 1d81 @@ -14868,7 +14966,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 2f12 +.fill 2f74 .fill c300 .fill 1d82 .fill 10d0 @@ -14883,7 +14981,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 6000 .fill 6380 .fill 1d81 @@ -14893,18 +14991,18 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 2f12 +.fill 2f74 .fill c300 .fill 1d82 .fill ae42 .fill 4001 .fill ae01 -.fill 81a5 +.fill 82e7 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 1f26 +.fill 1f88 .fill c300 .fill 1d81 .fill 1080 @@ -14918,7 +15016,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 204d +.fill 20af .fill c300 .fill 1d81 .fill 6380 @@ -14931,16 +15029,16 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 208a +.fill 20ec .fill c300 .fill 1d81 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 4601 .fill ae01 -.fill 33ff +.fill 3461 .fill c300 .fill 10d0 .fill 11fc @@ -14949,7 +15047,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 208a +.fill 20ec .fill c300 .fill 1d81 .fill ae0a @@ -14960,13 +15058,13 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 208a +.fill 20ec .fill c300 .fill 1d81 .fill ae86 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -14981,14 +15079,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa1e .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -15003,7 +15101,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -15022,7 +15120,7 @@ .fill aa1e .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -15037,7 +15135,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -15056,7 +15154,7 @@ .fill a40e .fill 4601 .fill ae01 -.fill 2f85 +.fill 2fe7 .fill c300 .fill 2180 .fill 11bb @@ -15064,13 +15162,13 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f71 +.fill 1fd3 .fill c300 .fill 1d81 .fill ae1e .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -15084,23 +15182,23 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a405 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill ae04 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill 4001 .fill ae01 -.fill 7e8a +.fill 7fcc .fill 1dff .fill 9180 .fill 6000 @@ -15134,7 +15232,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 095c +.fill 09be .fill c300 .fill 1d81 .fill 6380 @@ -15154,14 +15252,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill aa16 .fill 4001 .fill ae01 -.fill 7e73 +.fill 7fb5 .fill 1dff .fill 9180 .fill 10d0 @@ -15187,7 +15285,7 @@ .fill a410 .fill 4001 .fill ae01 -.fill 81aa +.fill 82ec .fill 1dff .fill 9180 .fill 4601 @@ -15198,7 +15296,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 3eb9 +.fill 3f1b .fill b600 .fill ae00 .fill 10d0 @@ -15238,7 +15336,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 2380 @@ -15257,7 +15355,7 @@ .fill a410 .fill 4001 .fill ae01 -.fill 81c3 +.fill 8305 .fill 1dff .fill 9180 .fill 4601 @@ -15268,7 +15366,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 3eb9 +.fill 3f1b .fill b600 .fill ae00 .fill 10d0 @@ -15297,14 +15395,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a410 .fill 4001 .fill ae01 -.fill 81db +.fill 831d .fill 1dff .fill 9180 .fill 4601 @@ -15315,12 +15413,12 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 3eb9 +.fill 3f1b .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 1dff .fill 9180 .fill 10d0 @@ -15330,7 +15428,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 0934 +.fill 0996 .fill c300 .fill 1d81 .fill 6380 @@ -15338,19 +15436,19 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e8b +.fill 7fcd .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e83 +.fill 7fc5 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4001 .fill ae01 -.fill 7e86 +.fill 7fc8 .fill 1dff .fill 9180 .fill 2180 @@ -15359,7 +15457,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e87 +.fill 7fc9 .fill 1dff .fill 9180 .fill 2180 @@ -15368,7 +15466,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e88 +.fill 7fca .fill 1dff .fill 9180 .fill 2180 @@ -15377,7 +15475,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e89 +.fill 7fcb .fill 1dff .fill 9180 .fill 2180 @@ -15386,7 +15484,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e8a +.fill 7fcc .fill 1dff .fill 9180 .fill 2180 @@ -15395,7 +15493,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e8c +.fill 7fce .fill 1dff .fill 9180 .fill 2180 @@ -15422,16 +15520,16 @@ .fill 1d83 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 4001 .fill ae01 -.fill 817e +.fill 82c0 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 1f26 +.fill 1f88 .fill c300 .fill 1d81 .fill 2380 @@ -15447,21 +15545,21 @@ .fill a405 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill ae04 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 4001 .fill ae01 -.fill 8210 +.fill 8352 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 1f26 +.fill 1f88 .fill c300 .fill 1d81 .fill 2380 @@ -15477,12 +15575,12 @@ .fill a405 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill ae04 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill 2180 .fill 11a8 @@ -15490,24 +15588,24 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f71 +.fill 1fd3 .fill c300 .fill 1d81 .fill 4001 .fill ae01 -.fill 8215 +.fill 8357 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 1f26 +.fill 1f88 .fill c300 .fill 1d81 .fill 1080 .fill a405 .fill 4601 .fill ae01 -.fill 128d +.fill 12ef .fill c300 .fill ae00 .fill 2180 @@ -15516,12 +15614,12 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f71 +.fill 1fd3 .fill c300 .fill 1d81 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1dff .fill 9180 @@ -15536,14 +15634,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 .fill a405 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill ae00 .fill 4001 @@ -15553,7 +15651,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -15563,7 +15661,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -15573,7 +15671,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -15583,7 +15681,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -15593,22 +15691,22 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4601 .fill ae01 -.fill 33ff +.fill 3461 .fill c300 .fill 4001 .fill ae01 -.fill 7e84 +.fill 7fc6 .fill 6000 .fill 1080 .fill a405 .fill 4601 .fill ae01 -.fill 124d +.fill 12af .fill c300 .fill ae00 .fill 2180 @@ -15619,7 +15717,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1fec +.fill 204e .fill c300 .fill 1d82 .fill 4001 @@ -15629,7 +15727,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -15639,7 +15737,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -15649,7 +15747,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -15659,7 +15757,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -15669,7 +15767,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 @@ -15679,18 +15777,18 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 1f9e +.fill 2000 .fill c300 .fill 1d81 .fill 4001 .fill ae01 -.fill 7e86 +.fill 7fc8 .fill 6000 .fill 1080 .fill a4ec .fill 4001 .fill ae01 -.fill 821a +.fill 835c .fill 1dff .fill 9180 .fill 4601 @@ -15700,7 +15798,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 7e89 +.fill 7fcb .fill 6000 .fill 1dff .fill 9180 @@ -15711,7 +15809,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 823a +.fill 837c .fill 1dff .fill 9180 .fill 4601 @@ -15731,7 +15829,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 8277 +.fill 83b9 .fill 1dff .fill 9180 .fill 4601 @@ -15772,7 +15870,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e89 +.fill 7fcb .fill 6000 .fill 6380 .fill 1d81 @@ -15782,14 +15880,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a44a .fill 4001 .fill ae01 -.fill 7e8b +.fill 7fcd .fill 6000 .fill 1dff .fill 9180 @@ -15812,7 +15910,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -15873,7 +15971,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 827a +.fill 83bc .fill 1dff .fill 9180 .fill 4601 @@ -15893,7 +15991,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 8282 +.fill 83c4 .fill 1dff .fill 9180 .fill 4601 @@ -15913,7 +16011,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 828c +.fill 83ce .fill 1dff .fill 9180 .fill 4601 @@ -15934,7 +16032,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e87 +.fill 7fc9 .fill 6000 .fill 1dff .fill 9180 @@ -15950,7 +16048,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 0d94 +.fill 0df6 .fill c300 .fill 1d84 .fill 6380 @@ -15970,14 +16068,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 82aa +.fill 83ec .fill 1dff .fill 9180 .fill 4601 @@ -16000,14 +16098,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 .fill a420 .fill 4001 .fill ae01 -.fill 82d8 +.fill 841a .fill 1dff .fill 9180 .fill 4601 @@ -16017,7 +16115,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 7e87 +.fill 7fc9 .fill 6000 .fill 1dff .fill 9180 @@ -16028,7 +16126,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 82e2 +.fill 8424 .fill 1dff .fill 9180 .fill 4601 @@ -16051,7 +16149,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill ae01 @@ -16070,7 +16168,7 @@ .fill 1dff .fill 4001 .fill ae01 -.fill 7e91 +.fill 7fd3 .fill 6000 .fill 6000 .fill 1dff @@ -16085,14 +16183,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40d .fill 4001 .fill ae01 -.fill 7e91 +.fill 7fd3 .fill 1dff .fill 9180 .fill 6000 @@ -16109,21 +16207,21 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e91 +.fill 7fd3 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4001 .fill ae01 -.fill 7e91 +.fill 7fd3 .fill 6000 .fill 6000 .fill 1080 .fill a41e .fill 4001 .fill ae01 -.fill 7e91 +.fill 7fd3 .fill 6000 .fill 6000 .fill 1dff @@ -16138,7 +16236,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 2380 @@ -16156,7 +16254,7 @@ .fill a40d .fill 4001 .fill ae01 -.fill 7e91 +.fill 7fd3 .fill 1dff .fill 9180 .fill 6000 @@ -16169,14 +16267,14 @@ .fill afcb .fill 4001 .fill ae01 -.fill 7e91 +.fill 7fd3 .fill 6000 .fill 6000 .fill 1080 .fill a417 .fill 4001 .fill ae01 -.fill 7e91 +.fill 7fd3 .fill 6000 .fill 1dff .fill 9180 @@ -16186,7 +16284,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e91 +.fill 7fd3 .fill 1dff .fill 9180 .fill 6000 @@ -16212,7 +16310,7 @@ .fill 9f80 .fill 4001 .fill ae01 -.fill 7e91 +.fill 7fd3 .fill 6000 .fill 6000 .fill 1dff @@ -16227,14 +16325,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40d .fill 4001 .fill ae01 -.fill 7e91 +.fill 7fd3 .fill 1dff .fill 9180 .fill 6000 @@ -16247,7 +16345,7 @@ .fill afdd .fill 4001 .fill ae01 -.fill 7e91 +.fill 7fd3 .fill 6000 .fill ae01 .fill 2180 @@ -16262,7 +16360,7 @@ .fill 1dfa .fill 4001 .fill ae01 -.fill 7e92 +.fill 7fd4 .fill 1dff .fill 9180 .fill 2180 @@ -16318,7 +16416,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -16366,7 +16464,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -16395,7 +16493,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -16424,7 +16522,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -16487,7 +16585,7 @@ .fill aa04 .fill 4601 .fill ae01 -.fill 4329 +.fill 438b .fill b600 .fill 10d0 .fill 11fd @@ -16515,7 +16613,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 @@ -16535,7 +16633,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79d5 +.fill 7b17 .fill c300 .fill 1d82 .fill 2380 @@ -16587,7 +16685,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 @@ -16608,7 +16706,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79d5 +.fill 7b17 .fill c300 .fill 1d82 .fill 2380 @@ -16668,7 +16766,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 @@ -16689,7 +16787,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79d5 +.fill 7b17 .fill c300 .fill 1d82 .fill 2380 @@ -16736,7 +16834,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 4378 +.fill 43da .fill b600 .fill 10d0 .fill 11fd @@ -16754,7 +16852,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 @@ -16762,7 +16860,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 4378 +.fill 43da .fill b600 .fill ae00 .fill 10d0 @@ -16780,7 +16878,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -16800,7 +16898,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -16808,7 +16906,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 4378 +.fill 43da .fill b600 .fill ae00 .fill 10d0 @@ -16830,7 +16928,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a67 +.fill 7ba9 .fill c300 .fill 1d82 .fill 1dff @@ -16846,7 +16944,7 @@ .fill 9040 .fill 4601 .fill ae01 -.fill 430f +.fill 4371 .fill b600 .fill 10d0 .fill 11ff @@ -16876,7 +16974,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -16897,7 +16995,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ab +.fill 7aed .fill c300 .fill 1d82 .fill 2380 @@ -16930,7 +17028,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -16950,7 +17048,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ab +.fill 7aed .fill c300 .fill 1d82 .fill 2380 @@ -16981,7 +17079,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 4378 +.fill 43da .fill b600 .fill ae00 .fill 10d0 @@ -17003,7 +17101,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a67 +.fill 7ba9 .fill c300 .fill 1d82 .fill 1dff @@ -17058,7 +17156,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -17079,7 +17177,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -17100,7 +17198,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ab +.fill 7aed .fill c300 .fill 1d82 .fill 2380 @@ -17150,7 +17248,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a67 +.fill 7ba9 .fill c300 .fill 1d82 .fill 1dff @@ -17190,7 +17288,7 @@ .fill 10c0 .fill 4601 .fill ae01 -.fill 4060 +.fill 40c2 .fill b600 .fill 10d0 .fill 11fb @@ -17211,7 +17309,7 @@ .fill ae00 .fill 4001 .fill ae01 -.fill 7e92 +.fill 7fd4 .fill 1dff .fill 9180 .fill 2180 @@ -17234,7 +17332,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -17298,7 +17396,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -17331,7 +17429,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -17341,7 +17439,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -17362,7 +17460,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 2380 @@ -17402,7 +17500,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -17447,7 +17545,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -17479,7 +17577,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -17489,7 +17587,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -17518,7 +17616,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 2380 @@ -17553,7 +17651,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -17563,7 +17661,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -17621,7 +17719,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -17631,7 +17729,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -17648,7 +17746,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 82ea +.fill 842c .fill 1dff .fill 9180 .fill 4601 @@ -17663,7 +17761,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -17673,7 +17771,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -17702,7 +17800,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 2380 @@ -17747,7 +17845,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -17757,7 +17855,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -17791,7 +17889,7 @@ .fill af51 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 2380 .fill 3100 @@ -17806,7 +17904,7 @@ .fill a40b .fill 4001 .fill ae01 -.fill 82ed +.fill 842f .fill 1dff .fill 9180 .fill 4601 @@ -17839,7 +17937,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 095c +.fill 09be .fill c300 .fill 1d81 .fill 6380 @@ -17859,14 +17957,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a414 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 1dff .fill 9180 @@ -17879,7 +17977,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill ae27 @@ -17891,7 +17989,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 0934 +.fill 0996 .fill c300 .fill 1d81 .fill 1dff @@ -17917,7 +18015,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill ae01 @@ -17991,7 +18089,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 1dff .fill 9180 @@ -18014,14 +18112,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 .fill a410 .fill 4001 .fill ae01 -.fill 82f5 +.fill 8437 .fill 1dff .fill 9180 .fill 4601 @@ -18032,12 +18130,12 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 47c1 +.fill 4823 .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 1dff .fill 9180 @@ -18065,19 +18163,19 @@ .fill 1d83 .fill 4001 .fill ae01 -.fill 7e8f +.fill 7fd1 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4001 .fill ae01 -.fill 7e90 +.fill 7fd2 .fill 1dff .fill 9180 .fill 2180 @@ -18099,7 +18197,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ab +.fill 7aed .fill c300 .fill 1d82 .fill 1080 @@ -18110,7 +18208,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -18131,7 +18229,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 @@ -18202,7 +18300,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -18212,7 +18310,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79d5 +.fill 7b17 .fill c300 .fill 1d82 .fill 1080 @@ -18346,12 +18444,12 @@ .fill ae00 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 1dff .fill 9180 @@ -18384,7 +18482,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 1dff .fill 9180 @@ -18400,7 +18498,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 0d94 +.fill 0df6 .fill c300 .fill 1d84 .fill 1dff @@ -18414,14 +18512,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a40d .fill 4001 .fill ae01 -.fill 8316 +.fill 8458 .fill 1dff .fill 9180 .fill 4601 @@ -18434,7 +18532,7 @@ .fill ae00 .fill 4001 .fill ae01 -.fill 8328 +.fill 846a .fill 1dff .fill 9180 .fill 4601 @@ -18483,7 +18581,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 1080 .fill a42f @@ -18494,7 +18592,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 1dff .fill 9180 @@ -18521,7 +18619,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 2380 @@ -18607,13 +18705,13 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 1dff .fill 9180 @@ -18631,13 +18729,13 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 1dff .fill 9180 @@ -18693,7 +18791,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 2380 @@ -18712,7 +18810,7 @@ .fill a410 .fill 4001 .fill ae01 -.fill 832f +.fill 8471 .fill 1dff .fill 9180 .fill 4601 @@ -18723,7 +18821,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 4fe1 +.fill 5043 .fill b600 .fill ae00 .fill 10d0 @@ -18737,7 +18835,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 095c +.fill 09be .fill c300 .fill 1d81 .fill 6380 @@ -18757,14 +18855,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 .fill a416 .fill 4001 .fill ae01 -.fill 7e73 +.fill 7fb5 .fill 1dff .fill 9180 .fill 10d0 @@ -18789,7 +18887,7 @@ .fill a410 .fill 4001 .fill ae01 -.fill 8342 +.fill 8484 .fill 1dff .fill 9180 .fill 4601 @@ -18800,12 +18898,12 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 4fe1 +.fill 5043 .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 1dff .fill 9180 .fill 2180 @@ -18814,7 +18912,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e90 +.fill 7fd2 .fill 1dff .fill 9180 .fill 2180 @@ -18835,19 +18933,19 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 .fill a431 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e6b +.fill 7fad .fill 1dff .fill 9180 .fill 10d0 @@ -18862,7 +18960,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 1dff .fill 9180 @@ -18873,7 +18971,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 0934 +.fill 0996 .fill c300 .fill 1d81 .fill 1dff @@ -18896,7 +18994,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -18917,18 +19015,18 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 728e +.fill 73d0 .fill c300 .fill 1d81 .fill 2180 .fill 4601 .fill ae01 -.fill 4fe1 +.fill 5043 .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 8360 +.fill 84a2 .fill 1dff .fill 9180 .fill 4601 @@ -18938,7 +19036,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 83a7 +.fill 84e9 .fill 1dff .fill 9180 .fill 4601 @@ -18948,7 +19046,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 83f4 +.fill 8536 .fill 1dff .fill 9180 .fill 4601 @@ -18958,7 +19056,7 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 44b8 +.fill 451a .fill c300 .fill 2180 .fill 1181 @@ -18966,11 +19064,11 @@ .fill aa04 .fill 4601 .fill ae01 -.fill 4fe0 +.fill 5042 .fill b600 .fill 4001 .fill ae01 -.fill 843a +.fill 857c .fill 1dff .fill 9180 .fill 4601 @@ -19015,14 +19113,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a410 .fill 4001 .fill ae01 -.fill 8441 +.fill 8583 .fill 1dff .fill 9180 .fill 4601 @@ -19033,7 +19131,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 4fe1 +.fill 5043 .fill b600 .fill ae00 .fill 10d0 @@ -19050,14 +19148,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a40f .fill 4001 .fill ae01 -.fill 8458 +.fill 859a .fill 1dff .fill 9180 .fill 4601 @@ -19067,12 +19165,12 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 4fdc +.fill 503e .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 8478 +.fill 85ba .fill 1dff .fill 9180 .fill 4001 @@ -19096,14 +19194,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa27 .fill 4001 .fill ae01 -.fill 847a +.fill 85bc .fill 1dff .fill 9180 .fill 4001 @@ -19127,7 +19225,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -19156,16 +19254,16 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 4fe1 +.fill 5043 .fill b600 .fill ae00 .fill 4601 .fill ae01 -.fill 4fdc +.fill 503e .fill b600 .fill 4001 .fill ae01 -.fill 847e +.fill 85c0 .fill 1dff .fill 9180 .fill 4001 @@ -19189,14 +19287,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a413 .fill 4001 .fill ae01 -.fill 8482 +.fill 85c4 .fill 1dff .fill 9180 .fill 4601 @@ -19207,15 +19305,15 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 4fe1 +.fill 5043 .fill b600 .fill 4601 .fill ae01 -.fill 4fdc +.fill 503e .fill b600 .fill 4001 .fill ae01 -.fill 849d +.fill 85df .fill 1dff .fill 9180 .fill 4001 @@ -19239,7 +19337,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -19251,14 +19349,14 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 459f +.fill 4601 .fill c300 .fill 1d81 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 84a0 +.fill 85e2 .fill 1dff .fill 9180 .fill 4601 @@ -19270,15 +19368,15 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 4fe1 +.fill 5043 .fill b600 .fill 4601 .fill ae01 -.fill 4fdc +.fill 503e .fill b600 .fill 4001 .fill ae01 -.fill 84d4 +.fill 8616 .fill 1dff .fill 9180 .fill 4001 @@ -19302,22 +19400,22 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a408 .fill 4601 .fill ae01 -.fill 44b8 +.fill 451a .fill c300 .fill 4601 .fill ae01 -.fill 4fdc +.fill 503e .fill b600 .fill 4001 .fill ae01 -.fill 84d7 +.fill 8619 .fill 1dff .fill 9180 .fill 4001 @@ -19341,7 +19439,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -19355,11 +19453,11 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 4fdc +.fill 503e .fill b600 .fill 4001 .fill ae01 -.fill 84da +.fill 861c .fill 1dff .fill 9180 .fill 4001 @@ -19383,14 +19481,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a4e2 .fill 4001 .fill ae01 -.fill 7e90 +.fill 7fd2 .fill 6000 .fill 2380 .fill 3100 @@ -19405,7 +19503,7 @@ .fill a40b .fill 4001 .fill ae01 -.fill 84dd +.fill 861f .fill 1dff .fill 9180 .fill 4601 @@ -19420,14 +19518,14 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4001 .fill ae01 -.fill 7e8f +.fill 7fd1 .fill 6000 .fill 1dff .fill 9180 @@ -19442,7 +19540,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ab +.fill 7aed .fill c300 .fill 1d82 .fill 1080 @@ -19453,7 +19551,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8f +.fill 7fd1 .fill 6000 .fill 6380 .fill 1d81 @@ -19483,7 +19581,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79d5 +.fill 7b17 .fill c300 .fill 1d82 .fill 1080 @@ -19572,26 +19670,26 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e8f +.fill 7fd1 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4001 .fill ae01 -.fill 7e8f +.fill 7fd1 .fill 1dff .fill 9180 .fill 10d0 @@ -19602,7 +19700,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 84ee +.fill 8630 .fill 1dff .fill 9180 .fill 4601 @@ -19612,7 +19710,7 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 4fdc +.fill 503e .fill b600 .fill 4001 .fill ae01 @@ -19636,18 +19734,18 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa04 .fill 4601 .fill ae01 -.fill 4fd2 +.fill 5034 .fill b600 .fill 4001 .fill ae01 -.fill 7e91 +.fill 7fd3 .fill 1dff .fill 9180 .fill 4001 @@ -19662,14 +19760,14 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 6380 .fill 1d81 .fill 9040 .fill 4001 .fill ae01 -.fill 84d4 +.fill 8616 .fill 1dff .fill 9180 .fill 10d0 @@ -19693,14 +19791,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa04 .fill 4601 .fill ae01 -.fill 4e28 +.fill 4e8a .fill b600 .fill 10d0 .fill 11fd @@ -19708,13 +19806,13 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 3f7f +.fill 3fe1 .fill c300 .fill 1d81 .fill 6380 @@ -19731,7 +19829,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 437e +.fill 43e0 .fill c300 .fill 1d81 .fill 6380 @@ -19739,7 +19837,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e92 +.fill 7fd4 .fill 6000 .fill 2380 .fill 3100 @@ -19766,7 +19864,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 2380 @@ -19790,7 +19888,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -19800,7 +19898,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -19819,7 +19917,7 @@ .fill aa0f .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 6000 .fill 2380 @@ -19838,7 +19936,7 @@ .fill a40f .fill 4001 .fill ae01 -.fill 8514 +.fill 8656 .fill 1dff .fill 9180 .fill 4601 @@ -19848,7 +19946,7 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 4fdc +.fill 503e .fill b600 .fill ae00 .fill 10d0 @@ -19863,7 +19961,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 82ea +.fill 842c .fill 1dff .fill 9180 .fill 4601 @@ -19882,7 +19980,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 443c +.fill 449e .fill c300 .fill 1d81 .fill 6380 @@ -19914,7 +20012,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -19982,7 +20080,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 2380 @@ -20004,12 +20102,12 @@ .fill ae00 .fill 4601 .fill ae01 -.fill 4fdc +.fill 503e .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 853a +.fill 867c .fill 1dff .fill 9180 .fill 10d0 @@ -20033,30 +20131,30 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a410 .fill 4601 .fill ae01 -.fill 3f51 +.fill 3fb3 .fill c300 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 4815 +.fill 4877 .fill c300 .fill 1d81 .fill 4601 .fill ae01 -.fill 4fdc +.fill 503e .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 853d +.fill 867f .fill 1dff .fill 9180 .fill 10d0 @@ -20073,7 +20171,7 @@ .fill a419 .fill 4001 .fill ae01 -.fill 8540 +.fill 8682 .fill 1dff .fill 9180 .fill 10d0 @@ -20101,7 +20199,7 @@ .fill a419 .fill 4001 .fill ae01 -.fill 8543 +.fill 8685 .fill 1dff .fill 9180 .fill 10d0 @@ -20129,7 +20227,7 @@ .fill a40f .fill 4001 .fill ae01 -.fill 8546 +.fill 8688 .fill 1dff .fill 9180 .fill 4601 @@ -20139,7 +20237,7 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 4fdc +.fill 503e .fill b600 .fill ae00 .fill 10d0 @@ -20148,13 +20246,13 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 3f7f +.fill 3fe1 .fill c300 .fill 1d81 .fill 6380 @@ -20166,7 +20264,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3f51 +.fill 3fb3 .fill c300 .fill 6380 .fill 1d81 @@ -20182,7 +20280,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 437e +.fill 43e0 .fill c300 .fill 1d81 .fill 6380 @@ -20190,7 +20288,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e92 +.fill 7fd4 .fill 6000 .fill 2380 .fill 3100 @@ -20217,7 +20315,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 2380 @@ -20241,7 +20339,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -20251,14 +20349,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a419 .fill 4001 .fill ae01 -.fill 853d +.fill 867f .fill 1dff .fill 9180 .fill 10d0 @@ -20298,7 +20396,7 @@ .fill a40c .fill 4001 .fill ae01 -.fill 855e +.fill 86a0 .fill 1dff .fill 9180 .fill 4601 @@ -20320,7 +20418,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 853d +.fill 867f .fill 1dff .fill 9180 .fill 10d0 @@ -20346,7 +20444,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 443c +.fill 449e .fill c300 .fill 1d81 .fill 6380 @@ -20355,7 +20453,7 @@ .fill ae00 .fill 4001 .fill ae01 -.fill 8543 +.fill 8685 .fill 1dff .fill 9180 .fill 10d0 @@ -20379,7 +20477,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -20389,7 +20487,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 8573 +.fill 86b5 .fill 1dff .fill 9180 .fill 10d0 @@ -20404,7 +20502,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 4609 +.fill 466b .fill c300 .fill 1d84 .fill ae18 @@ -20429,7 +20527,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 4609 +.fill 466b .fill c300 .fill 1d84 .fill ae0a @@ -20440,12 +20538,12 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 4815 +.fill 4877 .fill c300 .fill 1d81 .fill 4601 .fill ae01 -.fill 4a11 +.fill 4a73 .fill b600 .fill 2180 .fill 1cd0 @@ -20484,7 +20582,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 6380 .fill 1d81 @@ -20523,7 +20621,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3f7f +.fill 3fe1 .fill c300 .fill 1d81 .fill 6380 @@ -20531,7 +20629,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e92 +.fill 7fd4 .fill 6000 .fill 2380 .fill 3100 @@ -20560,7 +20658,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -20579,7 +20677,7 @@ .fill a40d .fill 4001 .fill ae01 -.fill 8574 +.fill 86b6 .fill 1dff .fill 9180 .fill 4601 @@ -20636,7 +20734,7 @@ .fill a40d .fill 4001 .fill ae01 -.fill 858b +.fill 86cd .fill 1dff .fill 9180 .fill 4601 @@ -20674,7 +20772,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 0d94 +.fill 0df6 .fill c300 .fill 1d84 .fill 6380 @@ -20694,14 +20792,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 85c0 +.fill 8702 .fill 1dff .fill 9180 .fill 4601 @@ -20712,7 +20810,7 @@ .fill ae0a .fill 4001 .fill ae01 -.fill 85dc +.fill 871e .fill 1dff .fill 9180 .fill 4601 @@ -20744,7 +20842,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 095c +.fill 09be .fill c300 .fill 1d81 .fill 6380 @@ -20764,14 +20862,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill aa1f .fill 4001 .fill ae01 -.fill 7e73 +.fill 7fb5 .fill 1dff .fill 9180 .fill 10d0 @@ -20806,7 +20904,7 @@ .fill a40d .fill 4001 .fill ae01 -.fill 85e4 +.fill 8726 .fill 1dff .fill 9180 .fill 4601 @@ -20847,7 +20945,7 @@ .fill 1d83 .fill 4001 .fill ae01 -.fill 7e6b +.fill 7fad .fill 1dff .fill 9180 .fill 10d0 @@ -20866,7 +20964,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 0934 +.fill 0996 .fill c300 .fill 1d81 .fill 1dff @@ -20907,14 +21005,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 8618 +.fill 875a .fill 1dff .fill 9180 .fill 4601 @@ -20938,14 +21036,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 8637 +.fill 8779 .fill 1dff .fill 9180 .fill 4601 @@ -20956,7 +21054,7 @@ .fill ae17 .fill 4001 .fill ae01 -.fill 865a +.fill 879c .fill 1dff .fill 9180 .fill 4601 @@ -21001,7 +21099,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 0b4d +.fill 0baf .fill c300 .fill 1d81 .fill 6380 @@ -21021,14 +21119,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a410 .fill 4001 .fill ae01 -.fill 8660 +.fill 87a2 .fill 1dff .fill 9180 .fill 4601 @@ -21039,7 +21137,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 540e +.fill 5470 .fill b600 .fill ae00 .fill 10d0 @@ -21073,14 +21171,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a45b .fill 4001 .fill ae01 -.fill 7e7b +.fill 7fbd .fill 1dff .fill 9180 .fill 10d0 @@ -21108,7 +21206,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 2380 @@ -21133,7 +21231,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e6b +.fill 7fad .fill 1dff .fill 9180 .fill 10d0 @@ -21203,7 +21301,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 0934 +.fill 0996 .fill c300 .fill 1d81 .fill 6380 @@ -21260,14 +21358,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a496 .fill 4001 .fill ae01 -.fill 7e7b +.fill 7fbd .fill 1dff .fill 9180 .fill 10d0 @@ -21284,7 +21382,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e6b +.fill 7fad .fill 1dff .fill 9180 .fill 10d0 @@ -21301,7 +21399,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e73 +.fill 7fb5 .fill 1dff .fill 9180 .fill 10d0 @@ -21330,7 +21428,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 090d +.fill 096f .fill c300 .fill 1d81 .fill 1dff @@ -21355,14 +21453,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 86a6 +.fill 87e8 .fill 1dff .fill 9180 .fill 4601 @@ -21386,14 +21484,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 86c7 +.fill 8809 .fill 1dff .fill 9180 .fill 4601 @@ -21404,7 +21502,7 @@ .fill ae0a .fill 4001 .fill ae01 -.fill 86fb +.fill 883d .fill 1dff .fill 9180 .fill 4601 @@ -21422,7 +21520,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 0934 +.fill 0996 .fill c300 .fill 1d81 .fill 1dff @@ -21441,7 +21539,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e6b +.fill 7fad .fill 1dff .fill 9180 .fill 10d0 @@ -21460,7 +21558,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e73 +.fill 7fb5 .fill 1dff .fill 9180 .fill 10d0 @@ -21478,7 +21576,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 8737 +.fill 8879 .fill 1dff .fill 9180 .fill 4601 @@ -21498,7 +21596,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 874f +.fill 8891 .fill 1dff .fill 9180 .fill 4601 @@ -21527,7 +21625,7 @@ .fill 9f80 .fill 4001 .fill ae01 -.fill 8763 +.fill 88a5 .fill 1dff .fill 9180 .fill 4601 @@ -21547,7 +21645,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 8769 +.fill 88ab .fill 1dff .fill 9180 .fill 4601 @@ -21576,7 +21674,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 876c +.fill 88ae .fill 1dff .fill 9180 .fill 4601 @@ -21591,7 +21689,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7d96 +.fill 7ed8 .fill 6000 .fill 6380 .fill 1d81 @@ -21607,7 +21705,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 8774 +.fill 88b6 .fill 1dff .fill 9180 .fill 4601 @@ -21617,7 +21715,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 877b +.fill 88bd .fill 1dff .fill 9180 .fill 4601 @@ -21637,7 +21735,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 8769 +.fill 88ab .fill 1dff .fill 9180 .fill 4601 @@ -21657,7 +21755,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 8573 +.fill 86b5 .fill 1dff .fill 9180 .fill 4601 @@ -21667,7 +21765,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 8785 +.fill 88c7 .fill 1dff .fill 9180 .fill 4601 @@ -21686,7 +21784,7 @@ .fill 1ae0 .fill 4001 .fill ae01 -.fill 87b9 +.fill 88fb .fill 1dff .fill 9180 .fill 10d0 @@ -21710,14 +21808,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa27 .fill 4001 .fill ae01 -.fill 87be +.fill 8900 .fill 1dff .fill 9180 .fill 10d0 @@ -21741,7 +21839,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -21760,7 +21858,7 @@ .fill a410 .fill 4001 .fill ae01 -.fill 87c6 +.fill 8908 .fill 1dff .fill 9180 .fill 4601 @@ -21771,12 +21869,12 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 58ae +.fill 593a .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 88a0 +.fill 89e2 .fill 1dff .fill 9180 .fill 10d0 @@ -21800,14 +21898,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40e .fill 4001 .fill ae01 -.fill 88a5 +.fill 89e7 .fill 1dff .fill 9180 .fill 4601 @@ -21817,11 +21915,11 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 58ad +.fill 5939 .fill b600 .fill 4001 .fill ae01 -.fill 8936 +.fill 8a78 .fill 1dff .fill 9180 .fill 10d0 @@ -21845,14 +21943,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa27 .fill 4001 .fill ae01 -.fill 8939 +.fill 8a7b .fill 1dff .fill 9180 .fill 10d0 @@ -21876,7 +21974,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -21895,7 +21993,7 @@ .fill a40e .fill 4001 .fill ae01 -.fill 893c +.fill 8a7e .fill 1dff .fill 9180 .fill 4601 @@ -21905,11 +22003,11 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 58ad +.fill 5939 .fill b600 .fill 4001 .fill ae01 -.fill 89ef +.fill 8b31 .fill 1dff .fill 9180 .fill 10d0 @@ -21933,14 +22031,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40e .fill 4001 .fill ae01 -.fill 89f5 +.fill 8b37 .fill 1dff .fill 9180 .fill 4601 @@ -21950,11 +22048,11 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 58ad +.fill 5939 .fill b600 .fill 4001 .fill ae01 -.fill 8a9e +.fill 8be0 .fill 1dff .fill 9180 .fill 10d0 @@ -21978,14 +22076,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40e .fill 4001 .fill ae01 -.fill 8aa3 +.fill 8be5 .fill 1dff .fill 9180 .fill 4601 @@ -21995,11 +22093,11 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 58ad +.fill 5939 .fill b600 .fill 4001 .fill ae01 -.fill 8b00 +.fill 8c42 .fill 1dff .fill 9180 .fill 10d0 @@ -22023,14 +22121,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa27 .fill 4001 .fill ae01 -.fill 8b03 +.fill 8c45 .fill 1dff .fill 9180 .fill 10d0 @@ -22054,7 +22152,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -22073,7 +22171,7 @@ .fill aa27 .fill 4001 .fill ae01 -.fill 8b07 +.fill 8c49 .fill 1dff .fill 9180 .fill 10d0 @@ -22097,7 +22195,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -22116,7 +22214,7 @@ .fill a40e .fill 4001 .fill ae01 -.fill 8b0c +.fill 8c4e .fill 1dff .fill 9180 .fill 4601 @@ -22126,11 +22224,11 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 58ad +.fill 5939 .fill b600 .fill 4001 .fill ae01 -.fill 8b7d +.fill 8cbf .fill 1dff .fill 9180 .fill 10d0 @@ -22154,14 +22252,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa27 .fill 4001 .fill ae01 -.fill 810d +.fill 824f .fill 1dff .fill 9180 .fill 10d0 @@ -22185,7 +22283,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -22204,7 +22302,7 @@ .fill aa27 .fill 4001 .fill ae01 -.fill 809d +.fill 81df .fill 1dff .fill 9180 .fill 10d0 @@ -22228,7 +22326,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -22247,7 +22345,7 @@ .fill a40e .fill 4001 .fill ae01 -.fill 8b82 +.fill 8cc4 .fill 1dff .fill 9180 .fill 4601 @@ -22257,11 +22355,11 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 58ad +.fill 5939 .fill b600 .fill 4001 .fill ae01 -.fill 8c25 +.fill 8d67 .fill 1dff .fill 9180 .fill 10d0 @@ -22285,14 +22383,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40e .fill 4001 .fill ae01 -.fill 8c29 +.fill 8d6b .fill 1dff .fill 9180 .fill 4601 @@ -22302,11 +22400,11 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 58ad +.fill 5939 .fill b600 .fill 4001 .fill ae01 -.fill 8c96 +.fill 8dd8 .fill 1dff .fill 9180 .fill 10d0 @@ -22330,118 +22428,30 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40e .fill 4001 .fill ae01 -.fill 8c9b -.fill 1dff -.fill 9180 -.fill 4601 -.fill ae01 -.fill 0494 -.fill c300 -.fill 1d81 -.fill 4601 -.fill ae01 -.fill 58ad -.fill b600 -.fill 4001 -.fill ae01 -.fill 8d22 -.fill 1dff -.fill 9180 -.fill 10d0 -.fill 1182 -.fill 6000 -.fill 1dff -.fill 9180 -.fill 4601 -.fill ae01 -.fill 033c -.fill c300 -.fill 1d82 -.fill 1dff -.fill 9180 -.fill 2180 -.fill 6380 -.fill 1d81 -.fill 1dff -.fill 9180 -.fill 1dff -.fill 9380 -.fill 4601 -.fill ae01 -.fill 7a29 -.fill c300 -.fill 1d82 -.fill 1080 -.fill aa27 -.fill 4001 -.fill ae01 -.fill 8d27 -.fill 1dff -.fill 9180 -.fill 10d0 -.fill 1182 -.fill 6000 -.fill 1dff -.fill 9180 -.fill 4601 -.fill ae01 -.fill 033c -.fill c300 -.fill 1d82 -.fill 1dff -.fill 9180 -.fill 2180 -.fill 6380 -.fill 1d81 -.fill 1dff -.fill 9180 -.fill 1dff -.fill 9380 -.fill 4601 -.fill ae01 -.fill 7a29 -.fill c300 -.fill 1d82 -.fill 2380 -.fill 3100 -.fill 1181 -.fill 1010 -.fill aa02 -.fill 2180 -.fill ae02 -.fill 2180 -.fill 1181 -.fill ae02 -.fill 2180 -.fill 1181 -.fill 1080 -.fill a40e -.fill 4001 -.fill ae01 -.fill 8d2c -.fill 1dff -.fill 9180 -.fill 4601 -.fill ae01 -.fill 0494 -.fill c300 -.fill 1d81 -.fill 4601 -.fill ae01 -.fill 58ad -.fill b600 -.fill 4001 -.fill ae01 .fill 8ddd .fill 1dff .fill 9180 +.fill 4601 +.fill ae01 +.fill 0494 +.fill c300 +.fill 1d81 +.fill 4601 +.fill ae01 +.fill 5939 +.fill b600 +.fill 4001 +.fill ae01 +.fill 8e64 +.fill 1dff +.fill 9180 .fill 10d0 .fill 1182 .fill 6000 @@ -22463,14 +22473,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa27 .fill 4001 .fill ae01 -.fill 8de3 +.fill 8e69 .fill 1dff .fill 9180 .fill 10d0 @@ -22494,7 +22504,95 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b +.fill c300 +.fill 1d82 +.fill 2380 +.fill 3100 +.fill 1181 +.fill 1010 +.fill aa02 +.fill 2180 +.fill ae02 +.fill 2180 +.fill 1181 +.fill ae02 +.fill 2180 +.fill 1181 +.fill 1080 +.fill a40e +.fill 4001 +.fill ae01 +.fill 8e6e +.fill 1dff +.fill 9180 +.fill 4601 +.fill ae01 +.fill 0494 +.fill c300 +.fill 1d81 +.fill 4601 +.fill ae01 +.fill 5939 +.fill b600 +.fill 4001 +.fill ae01 +.fill 8f1f +.fill 1dff +.fill 9180 +.fill 10d0 +.fill 1182 +.fill 6000 +.fill 1dff +.fill 9180 +.fill 4601 +.fill ae01 +.fill 033c +.fill c300 +.fill 1d82 +.fill 1dff +.fill 9180 +.fill 2180 +.fill 6380 +.fill 1d81 +.fill 1dff +.fill 9180 +.fill 1dff +.fill 9380 +.fill 4601 +.fill ae01 +.fill 7b6b +.fill c300 +.fill 1d82 +.fill 1080 +.fill aa27 +.fill 4001 +.fill ae01 +.fill 8f25 +.fill 1dff +.fill 9180 +.fill 10d0 +.fill 1182 +.fill 6000 +.fill 1dff +.fill 9180 +.fill 4601 +.fill ae01 +.fill 033c +.fill c300 +.fill 1d82 +.fill 1dff +.fill 9180 +.fill 2180 +.fill 6380 +.fill 1d81 +.fill 1dff +.fill 9180 +.fill 1dff +.fill 9380 +.fill 4601 +.fill ae01 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -22513,7 +22611,49 @@ .fill a40b .fill 4001 .fill ae01 -.fill 8de7 +.fill 8f29 +.fill 1dff +.fill 9180 +.fill 4601 +.fill ae01 +.fill 0494 +.fill c300 +.fill 1d81 +.fill aedc +.fill 4001 +.fill ae01 +.fill 8fae +.fill 1dff +.fill 9180 +.fill 10d0 +.fill 1182 +.fill 6000 +.fill 1dff +.fill 9180 +.fill 4601 +.fill ae01 +.fill 033c +.fill c300 +.fill 1d82 +.fill 1dff +.fill 9180 +.fill 2180 +.fill 6380 +.fill 1d81 +.fill 1dff +.fill 9180 +.fill 1dff +.fill 9380 +.fill 4601 +.fill ae01 +.fill 7b6b +.fill c300 +.fill 1d82 +.fill 1080 +.fill a40b +.fill 4001 +.fill ae01 +.fill 8fb3 .fill 1dff .fill 9180 .fill 4601 @@ -22524,7 +22664,7 @@ .fill aeb2 .fill 4001 .fill ae01 -.fill 8e6c +.fill 8fdd .fill 1dff .fill 9180 .fill 10d0 @@ -22548,14 +22688,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 8e71 +.fill 8fe5 .fill 1dff .fill 9180 .fill 4601 @@ -22566,7 +22706,7 @@ .fill ae88 .fill 4001 .fill ae01 -.fill 8e9b +.fill 9033 .fill 1dff .fill 9180 .fill 10d0 @@ -22590,14 +22730,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 8ea1 +.fill 9039 .fill 1dff .fill 9180 .fill 4601 @@ -22608,7 +22748,7 @@ .fill ae5e .fill 4001 .fill ae01 -.fill 8edf +.fill 9077 .fill 1dff .fill 9180 .fill 10d0 @@ -22632,14 +22772,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 8ee4 +.fill 907c .fill 1dff .fill 9180 .fill 4601 @@ -22650,7 +22790,7 @@ .fill ae34 .fill 4001 .fill ae01 -.fill 8f3f +.fill 90d7 .fill 1dff .fill 9180 .fill 10d0 @@ -22674,14 +22814,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 8f44 +.fill 90dc .fill 1dff .fill 9180 .fill 4601 @@ -22692,7 +22832,7 @@ .fill ae0a .fill 4001 .fill ae01 -.fill 8f9c +.fill 9134 .fill 1dff .fill 9180 .fill 4601 @@ -22715,7 +22855,7 @@ .fill 1dfa .fill 4001 .fill ae01 -.fill 7e91 +.fill 7fd3 .fill 1dff .fill 9180 .fill 10d0 @@ -22730,7 +22870,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 6380 .fill 1d81 @@ -22753,12 +22893,12 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 60fa +.fill 61b9 .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 8f3f +.fill 90d7 .fill 1dff .fill 9180 .fill 10d0 @@ -22782,7 +22922,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -22793,7 +22933,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 6380 .fill 1d81 @@ -22811,18 +22951,18 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 54b0 +.fill 5512 .fill c300 .fill 1d81 .fill 2180 .fill 4601 .fill ae01 -.fill 60fa +.fill 61b9 .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 8fd5 +.fill 916d .fill 1dff .fill 9180 .fill 4601 @@ -22832,7 +22972,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 8ffb +.fill 919d .fill 1dff .fill 9180 .fill 4601 @@ -22842,7 +22982,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 902b +.fill 91cd .fill 1dff .fill 9180 .fill 4601 @@ -22852,7 +22992,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 9065 +.fill 9207 .fill 1dff .fill 9180 .fill 4601 @@ -22862,7 +23002,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 90a4 +.fill 9246 .fill 1dff .fill 9180 .fill 4601 @@ -22872,7 +23012,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 90f8 +.fill 929a .fill 1dff .fill 9180 .fill 4601 @@ -22882,7 +23022,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 913a +.fill 92dc .fill 1dff .fill 9180 .fill 4601 @@ -22892,7 +23032,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 916a +.fill 930c .fill 1dff .fill 9180 .fill 4601 @@ -22902,7 +23042,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 91aa +.fill 934c .fill 1dff .fill 9180 .fill 4601 @@ -22912,7 +23052,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 91f2 +.fill 9394 .fill 1dff .fill 9180 .fill 4601 @@ -22922,11 +23062,11 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 60f9 +.fill 61b8 .fill b600 .fill 4001 .fill ae01 -.fill 87b9 +.fill 88fb .fill 1dff .fill 9180 .fill 10d0 @@ -22950,21 +23090,21 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a41e .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 6000 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 9240 +.fill 93e2 .fill 1dff .fill 9180 .fill 4601 @@ -22978,16 +23118,16 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 0828 +.fill 088a .fill c300 .fill 1d81 .fill 4601 .fill ae01 -.fill 60f9 +.fill 61b8 .fill b600 .fill 4001 .fill ae01 -.fill 87be +.fill 8900 .fill 1dff .fill 9180 .fill 10d0 @@ -23011,19 +23151,19 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a43d .fill 4001 .fill ae01 -.fill 925c +.fill 93fe .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 1dff .fill 9180 @@ -23036,7 +23176,7 @@ .fill aa0f .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 6000 .fill 2380 @@ -23055,7 +23195,7 @@ .fill a40b .fill 4001 .fill ae01 -.fill 9260 +.fill 9402 .fill 1dff .fill 9180 .fill 4601 @@ -23070,16 +23210,16 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 0828 +.fill 088a .fill c300 .fill 1d81 .fill 4601 .fill ae01 -.fill 60f9 +.fill 61b8 .fill b600 .fill 4001 .fill ae01 -.fill 8e6c +.fill 8fae .fill 1dff .fill 9180 .fill 10d0 @@ -23103,14 +23243,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40f .fill 4601 .fill ae01 -.fill 3f51 +.fill 3fb3 .fill c300 .fill 1dff .fill 9180 @@ -23121,11 +23261,11 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 60f9 +.fill 61b8 .fill b600 .fill 4001 .fill ae01 -.fill 8e9b +.fill 9033 .fill 1dff .fill 9180 .fill 10d0 @@ -23149,14 +23289,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40e .fill 4001 .fill ae01 -.fill 92a9 +.fill 944b .fill 1dff .fill 9180 .fill 4601 @@ -23166,11 +23306,11 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 60f9 +.fill 61b8 .fill b600 .fill 4001 .fill ae01 -.fill 8de3 +.fill 8f25 .fill 1dff .fill 9180 .fill 10d0 @@ -23194,22 +23334,22 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a408 .fill 4601 .fill ae01 -.fill 5414 +.fill 5476 .fill c300 .fill 4601 .fill ae01 -.fill 60f9 +.fill 61b8 .fill b600 .fill 4001 .fill ae01 -.fill 8edf +.fill 9077 .fill 1dff .fill 9180 .fill 10d0 @@ -23233,7 +23373,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -23241,11 +23381,11 @@ .fill f000 .fill 4601 .fill ae01 -.fill 60f9 +.fill 61b8 .fill b600 .fill 4001 .fill ae01 -.fill 8b07 +.fill 8c49 .fill 1dff .fill 9180 .fill 10d0 @@ -23269,14 +23409,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa27 .fill 4001 .fill ae01 -.fill 8b00 +.fill 8c42 .fill 1dff .fill 9180 .fill 10d0 @@ -23300,7 +23440,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -23319,7 +23459,7 @@ .fill aa27 .fill 4001 .fill ae01 -.fill 8b03 +.fill 8c45 .fill 1dff .fill 9180 .fill 10d0 @@ -23343,7 +23483,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -23362,15 +23502,15 @@ .fill a408 .fill 4601 .fill ae01 -.fill 0e5e +.fill 0ec0 .fill c300 .fill 4601 .fill ae01 -.fill 60f9 +.fill 61b8 .fill b600 .fill 4001 .fill ae01 -.fill 8b7d +.fill 8cbf .fill 1dff .fill 9180 .fill 10d0 @@ -23394,14 +23534,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa27 .fill 4001 .fill ae01 -.fill 810d +.fill 824f .fill 1dff .fill 9180 .fill 10d0 @@ -23425,7 +23565,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -23444,7 +23584,7 @@ .fill aa27 .fill 4001 .fill ae01 -.fill 809d +.fill 81df .fill 1dff .fill 9180 .fill 10d0 @@ -23468,7 +23608,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -23491,7 +23631,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 6380 .fill 1d81 @@ -23502,21 +23642,21 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 6380 .fill 1d81 .fill 9040 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 6000 .fill 1080 .fill aa38 .fill 4001 .fill ae01 -.fill 809d +.fill 81df .fill 1dff .fill 9180 .fill 10d0 @@ -23540,7 +23680,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -23576,7 +23716,7 @@ .fill a410 .fill 4001 .fill ae01 -.fill 8045 +.fill 8187 .fill 1dff .fill 9180 .fill 4601 @@ -23587,7 +23727,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 60fa +.fill 61b9 .fill b600 .fill ae00 .fill 10d0 @@ -23607,16 +23747,16 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 0f65 +.fill 0fc7 .fill c300 .fill 1d83 .fill 4601 .fill ae01 -.fill 60f9 +.fill 61b8 .fill b600 .fill 4001 .fill ae01 -.fill 8a9e +.fill 8be0 .fill 1dff .fill 9180 .fill 10d0 @@ -23640,7 +23780,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -23651,13 +23791,13 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 095c +.fill 09be .fill c300 .fill 1d81 .fill 6380 @@ -23677,14 +23817,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 92b1 +.fill 9453 .fill 1dff .fill 9180 .fill 4601 @@ -23695,7 +23835,7 @@ .fill ae2a .fill 4001 .fill ae01 -.fill 7e73 +.fill 7fb5 .fill 1dff .fill 9180 .fill 10d0 @@ -23709,7 +23849,7 @@ .fill a40b .fill 4001 .fill ae01 -.fill 92c1 +.fill 9463 .fill 1dff .fill 9180 .fill 4601 @@ -23725,7 +23865,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 0934 +.fill 0996 .fill c300 .fill 1d81 .fill 1dff @@ -23737,11 +23877,11 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 60f9 +.fill 61b8 .fill b600 .fill 4001 .fill ae01 -.fill 89ef +.fill 8b31 .fill 1dff .fill 9180 .fill 10d0 @@ -23765,7 +23905,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -23776,7 +23916,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 6380 .fill 1d81 @@ -23787,7 +23927,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3f51 +.fill 3fb3 .fill c300 .fill 6380 .fill 1d81 @@ -23819,7 +23959,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 0d94 +.fill 0df6 .fill c300 .fill 1d84 .fill 1dff @@ -23833,14 +23973,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 92da +.fill 947c .fill 1dff .fill 9180 .fill 4601 @@ -23851,7 +23991,7 @@ .fill ae0a .fill 4001 .fill ae01 -.fill 8328 +.fill 846a .fill 1dff .fill 9180 .fill 4601 @@ -23861,11 +24001,11 @@ .fill 1d81 .fill 4601 .fill ae01 -.fill 60f9 +.fill 61b8 .fill b600 .fill 4001 .fill ae01 -.fill 88a0 +.fill 89e2 .fill 1dff .fill 9180 .fill 10d0 @@ -23889,29 +24029,29 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40f .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 48db +.fill 493d .fill c300 .fill 1d81 .fill 4601 .fill ae01 -.fill 60f9 +.fill 61b8 .fill b600 .fill 4001 .fill ae01 -.fill 8c96 +.fill 8dd8 .fill 1dff .fill 9180 .fill 10d0 @@ -23935,7 +24075,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -23946,7 +24086,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 6380 .fill 1d81 @@ -23958,16 +24098,16 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 4fe7 +.fill 5049 .fill c300 .fill 1d81 .fill 4601 .fill ae01 -.fill 60f9 +.fill 61b8 .fill b600 .fill 4001 .fill ae01 -.fill 8c25 +.fill 8d67 .fill 1dff .fill 9180 .fill 10d0 @@ -23991,7 +24131,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -24002,14 +24142,14 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 6380 .fill 1d81 .fill 9040 .fill 4601 .fill ae01 -.fill 3f51 +.fill 3fb3 .fill c300 .fill 1dff .fill 9180 @@ -24020,16 +24160,16 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 50f8 +.fill 515a .fill c300 .fill 1d82 .fill 4601 .fill ae01 -.fill 60f9 +.fill 61b8 .fill b600 .fill 4001 .fill ae01 -.fill 8936 +.fill 8a78 .fill 1dff .fill 9180 .fill 10d0 @@ -24053,14 +24193,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa27 .fill 4001 .fill ae01 -.fill 8939 +.fill 8a7b .fill 1dff .fill 9180 .fill 10d0 @@ -24084,7 +24224,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -24107,7 +24247,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 6380 .fill 1d81 @@ -24118,7 +24258,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 6380 .fill 1d81 @@ -24140,7 +24280,7 @@ .fill aa0f .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 6000 .fill 2380 @@ -24159,7 +24299,7 @@ .fill a410 .fill 4001 .fill ae01 -.fill 932f +.fill 94d1 .fill 1dff .fill 9180 .fill 4601 @@ -24170,7 +24310,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 60fa +.fill 61b9 .fill b600 .fill ae00 .fill 10d0 @@ -24194,7 +24334,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 935e +.fill 9500 .fill 6380 .fill 1d81 .fill 9040 @@ -24215,7 +24355,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3b0e +.fill 3b70 .fill c300 .fill 1d82 .fill 6380 @@ -24228,7 +24368,7 @@ .fill a427 .fill 4001 .fill ae01 -.fill 8939 +.fill 8a7b .fill 1dff .fill 9180 .fill 10d0 @@ -24252,7 +24392,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -24270,7 +24410,7 @@ .fill a410 .fill 4001 .fill ae01 -.fill 8573 +.fill 86b5 .fill 1dff .fill 9180 .fill 10d0 @@ -24280,17 +24420,17 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 50f8 +.fill 515a .fill c300 .fill 1d82 .fill ae00 .fill 4601 .fill ae01 -.fill 60f9 +.fill 61b8 .fill b600 .fill 4001 .fill ae01 -.fill 8ddd +.fill 8f1f .fill 1dff .fill 9180 .fill 10d0 @@ -24314,7 +24454,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -24325,13 +24465,13 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 3f7f +.fill 3fe1 .fill c300 .fill 1d81 .fill 6380 @@ -24339,7 +24479,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e92 +.fill 7fd4 .fill 6000 .fill 2380 .fill 3100 @@ -24354,7 +24494,7 @@ .fill a410 .fill 4001 .fill ae01 -.fill 9362 +.fill 9504 .fill 1dff .fill 9180 .fill 4601 @@ -24365,7 +24505,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 60fa +.fill 61b9 .fill b600 .fill ae00 .fill 10d0 @@ -24401,7 +24541,7 @@ .fill a40b .fill 4001 .fill ae01 -.fill 93b1 +.fill 9553 .fill 1dff .fill 9180 .fill 4601 @@ -24425,11 +24565,11 @@ .fill f100 .fill 4601 .fill ae01 -.fill 60f9 +.fill 61b8 .fill b600 .fill 4001 .fill ae01 -.fill 8d22 +.fill 8e64 .fill 1dff .fill 9180 .fill 10d0 @@ -24453,14 +24593,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill aa27 .fill 4001 .fill ae01 -.fill 8d27 +.fill 8e69 .fill 1dff .fill 9180 .fill 10d0 @@ -24484,7 +24624,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -24503,7 +24643,7 @@ .fill aa04 .fill 4601 .fill ae01 -.fill 60ef +.fill 617b .fill b600 .fill 10d0 .fill 11fb @@ -24511,13 +24651,13 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 3f7f +.fill 3fe1 .fill c300 .fill 1d81 .fill 6380 @@ -24525,7 +24665,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e92 +.fill 7fd4 .fill 6000 .fill 2380 .fill 3100 @@ -24540,7 +24680,7 @@ .fill a410 .fill 4001 .fill ae01 -.fill 9405 +.fill 95a7 .fill 1dff .fill 9180 .fill 4601 @@ -24551,7 +24691,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 60fa +.fill 61b9 .fill b600 .fill ae00 .fill 10d0 @@ -24566,7 +24706,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 8d27 +.fill 8e69 .fill 1dff .fill 9180 .fill 10d0 @@ -24590,7 +24730,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -24601,13 +24741,13 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 3ebf +.fill 3f21 .fill c300 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 3f7f +.fill 3fe1 .fill c300 .fill 1d81 .fill 6380 @@ -24615,7 +24755,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e92 +.fill 7fd4 .fill 6000 .fill 2380 .fill 3100 @@ -24630,7 +24770,7 @@ .fill a40d .fill 4001 .fill ae01 -.fill 9442 +.fill 95e4 .fill 1dff .fill 9180 .fill 4601 @@ -24639,7 +24779,7 @@ .fill c300 .fill 1d81 .fill 2180 -.fill aeb9 +.fill aeec .fill ae00 .fill 10d0 .fill 11fb @@ -24655,7 +24795,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 @@ -24676,7 +24816,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 2380 @@ -24709,7 +24849,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 2380 @@ -24728,7 +24868,7 @@ .fill a40d .fill 4001 .fill ae01 -.fill 9476 +.fill 9618 .fill 1dff .fill 9180 .fill 4601 @@ -24737,7 +24877,7 @@ .fill c300 .fill 1d81 .fill 2180 -.fill ae57 +.fill ae8a .fill ae00 .fill 10d0 .fill 11fa @@ -24763,7 +24903,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 82ea +.fill 842c .fill 1dff .fill 9180 .fill 4601 @@ -24784,7 +24924,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 9499 +.fill 963b .fill 1dff .fill 9180 .fill 4601 @@ -24805,7 +24945,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 949c +.fill 963e .fill 1dff .fill 9180 .fill 4601 @@ -24813,10 +24953,61 @@ .fill 0494 .fill c300 .fill 1d81 +.fill ae3d +.fill 4001 +.fill ae01 +.fill 8fdd +.fill 1dff +.fill 9180 +.fill 10d0 +.fill 11ff +.fill 6000 +.fill 1dff +.fill 9180 +.fill 4601 +.fill ae01 +.fill 033c +.fill c300 +.fill 1d82 +.fill 1dff +.fill 9180 +.fill 2180 +.fill 6380 +.fill 1d81 +.fill 1dff +.fill 9180 +.fill 1dff +.fill 9380 +.fill 4601 +.fill ae01 +.fill 7b6b +.fill c300 +.fill 1d82 +.fill 1080 +.fill a414 +.fill 4601 +.fill ae01 +.fill 3f21 +.fill c300 +.fill 6000 +.fill 1080 +.fill a40b +.fill 4001 +.fill ae01 +.fill 9640 +.fill 1dff +.fill 9180 +.fill 4601 +.fill ae01 +.fill 0494 +.fill c300 +.fill 1d81 +.fill ae01 +.fill c812 .fill ae0a .fill 4001 .fill ae01 -.fill 949e +.fill 964f .fill 1dff .fill 9180 .fill 4601 @@ -24836,10 +25027,126 @@ .fill 1dff .fill 9b80 .fill 1ae0 +.fill 1dff +.fill 10d0 +.fill 11ff +.fill 1dff +.fill 9180 +.fill 2180 +.fill 6380 +.fill 1d81 +.fill 9040 +.fill 10d0 +.fill 11ff +.fill 6000 +.fill 1dff +.fill 9180 +.fill 4001 +.fill ae01 +.fill 7fd5 +.fill 6000 +.fill 6380 +.fill 1d81 +.fill 1dff +.fill 9180 +.fill 1dff +.fill 9380 +.fill 4601 +.fill ae01 +.fill 7ac3 +.fill c300 +.fill 1d82 +.fill 1080 +.fill a449 +.fill 10d0 +.fill 11ff +.fill 6000 +.fill 1dff +.fill 9180 +.fill 2180 +.fill 1181 +.fill 6380 +.fill 1d81 +.fill 1010 +.fill 1dff +.fill 9180 +.fill 4601 +.fill ae01 +.fill 050d +.fill c300 +.fill 1d81 +.fill 4001 +.fill ae01 +.fill 966b +.fill 1dff +.fill 9180 +.fill 4601 +.fill ae01 +.fill 0458 +.fill c300 +.fill 1d81 +.fill 4001 +.fill ae01 +.fill e400 +.fill 1dff +.fill 9180 +.fill 10d0 +.fill 11ff +.fill 6000 +.fill 1dff +.fill 9180 +.fill 4001 +.fill ae01 +.fill 0080 +.fill 6380 +.fill 1d81 +.fill 1dff +.fill 9180 +.fill 1dff +.fill 9380 +.fill 4601 +.fill ae01 +.fill 7ba9 +.fill c300 +.fill 1d82 +.fill 6380 +.fill 1d81 +.fill 1010 +.fill 1dff +.fill 9180 +.fill 4601 +.fill ae01 +.fill 0494 +.fill c300 +.fill 1d81 +.fill 10d0 +.fill 11ff +.fill 1dff +.fill 9180 +.fill 6000 +.fill 1880 +.fill 1181 +.fill 6380 +.fill 1d81 +.fill 9040 +.fill 10c0 +.fill afa1 +.fill 2180 +.fill 1cd0 +.fill 6b80 +.fill 1d81 +.fill 6f80 +.fill 1d81 +.fill e000 +.fill 1dff +.fill 9f80 +.fill 1dff +.fill 9b80 +.fill 1ae0 .fill 1dfc .fill 4001 .fill ae01 -.fill 7e96 +.fill 7fd8 .fill 6000 .fill 2380 .fill 3100 @@ -24855,7 +25162,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 6232 +.fill 6365 .fill b600 .fill ae00 .fill 10d0 @@ -24890,7 +25197,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -24915,7 +25222,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 6000 .fill 1dff .fill 9180 @@ -24930,7 +25237,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 @@ -24941,7 +25248,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 6000 .fill 1dff .fill 9180 @@ -24989,7 +25296,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 6000 .fill 6380 .fill 1d81 @@ -24999,7 +25306,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ab +.fill 7aed .fill c300 .fill 1d82 .fill 1080 @@ -25010,7 +25317,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 6000 .fill 6380 .fill 1d81 @@ -25018,7 +25325,7 @@ .fill ae00 .fill 4001 .fill ae01 -.fill 94ba +.fill 966d .fill 1dff .fill 9180 .fill 4601 @@ -25052,7 +25359,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -25088,7 +25395,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 6000 .fill 6380 .fill 1d81 @@ -25109,14 +25416,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a416 .fill 4001 .fill ae01 -.fill 94c5 +.fill 9678 .fill 1dff .fill 9180 .fill 4601 @@ -25172,7 +25479,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 @@ -25184,7 +25491,7 @@ .fill ae00 .fill 4001 .fill ae01 -.fill 7e96 +.fill 7fd8 .fill 6000 .fill 1080 .fill a403 @@ -25205,7 +25512,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 @@ -25237,7 +25544,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -25263,7 +25570,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -25289,7 +25596,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -25315,7 +25622,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -25341,7 +25648,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -25367,7 +25674,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -25392,7 +25699,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -25411,7 +25718,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -25471,7 +25778,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -25541,7 +25848,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 2380 @@ -25595,7 +25902,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 6000 .fill 6380 .fill 1d81 @@ -25638,7 +25945,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 2380 @@ -25672,7 +25979,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 6000 .fill 1dff .fill 9180 @@ -25697,13 +26004,13 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 6000 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 6000 .fill 6380 .fill 1d81 @@ -25713,7 +26020,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 @@ -25721,7 +26028,7 @@ .fill 2180 .fill 4601 .fill ae01 -.fill 66e5 +.fill 6818 .fill b600 .fill ae00 .fill 10d0 @@ -25744,7 +26051,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 94c9 +.fill 967c .fill 6380 .fill 1d81 .fill 9040 @@ -25784,7 +26091,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 2380 @@ -25926,7 +26233,7 @@ .fill 1d83 .fill 4001 .fill ae01 -.fill 7e96 +.fill 7fd8 .fill 6000 .fill 1080 .fill a42c @@ -25945,7 +26252,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -25965,7 +26272,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 7fbe +.fill 8100 .fill 1dff .fill 9180 .fill 4601 @@ -26000,14 +26307,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a4ac .fill 4001 .fill ae01 -.fill 7e7b +.fill 7fbd .fill 1dff .fill 9180 .fill 10d0 @@ -26036,7 +26343,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 090d +.fill 096f .fill c300 .fill 1d81 .fill 1dff @@ -26074,7 +26381,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 090d +.fill 096f .fill c300 .fill 1d81 .fill 1dff @@ -26100,7 +26407,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 090d +.fill 096f .fill c300 .fill 1d81 .fill 1dff @@ -26116,7 +26423,7 @@ .fill 1d83 .fill 4001 .fill ae01 -.fill 7e96 +.fill 7fd8 .fill 6000 .fill 1080 .fill a42c @@ -26135,7 +26442,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -26155,7 +26462,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 7fbe +.fill 8100 .fill 1dff .fill 9180 .fill 4601 @@ -26192,7 +26499,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -26237,7 +26544,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -26278,7 +26585,7 @@ .fill 1d83 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 1dff .fill 9180 .fill 10d0 @@ -26297,12 +26604,12 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 6000 .fill 6380 .fill 1d81 @@ -26311,7 +26618,7 @@ .fill ae00 .fill 4001 .fill ae01 -.fill 7e96 +.fill 7fd8 .fill 6000 .fill 1080 .fill a40d @@ -26337,7 +26644,7 @@ .fill ae00 .fill 4601 .fill ae01 -.fill 6100 +.fill 6233 .fill c300 .fill 2180 .fill 1cd0 @@ -26357,7 +26664,7 @@ .fill 1c64 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 1dff .fill 9180 .fill 2180 @@ -26366,7 +26673,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 1dff .fill 9180 .fill 2180 @@ -26387,14 +26694,14 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e93 +.fill 7fd5 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4001 .fill ae01 -.fill 7e96 +.fill 7fd8 .fill 1dff .fill 9180 .fill f900 @@ -26439,7 +26746,7 @@ .fill aa04 .fill 4601 .fill ae01 -.fill 6cad +.fill 6de0 .fill b600 .fill 10d0 .fill 11ff @@ -26447,7 +26754,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 6238 +.fill 636b .fill c300 .fill 6380 .fill 1d81 @@ -26467,7 +26774,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -26497,7 +26804,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -26517,7 +26824,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -26536,7 +26843,7 @@ .fill a405 .fill 4601 .fill ae01 -.fill 6cad +.fill 6de0 .fill b600 .fill ae00 .fill 10d0 @@ -26554,7 +26861,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -26573,7 +26880,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -26592,7 +26899,7 @@ .fill a405 .fill 4601 .fill ae01 -.fill 6ca9 +.fill 6ddc .fill b600 .fill ae00 .fill 10d0 @@ -26611,7 +26918,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -26632,7 +26939,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -26651,7 +26958,7 @@ .fill aa04 .fill 4601 .fill ae01 -.fill 6977 +.fill 6aaa .fill b600 .fill 10d0 .fill 11fc @@ -26660,7 +26967,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e93 +.fill 7fd5 .fill 6000 .fill 6380 .fill 1d81 @@ -26670,14 +26977,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a41f .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 6000 .fill 1dff .fill 9180 @@ -26722,7 +27029,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -26771,7 +27078,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -26783,7 +27090,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e93 +.fill 7fd5 .fill 6000 .fill 6380 .fill 1d81 @@ -26793,7 +27100,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 2380 @@ -26828,7 +27135,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e93 +.fill 7fd5 .fill 6000 .fill 6380 .fill 1d81 @@ -26838,7 +27145,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -26903,7 +27210,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a67 +.fill 7ba9 .fill c300 .fill 1d82 .fill 6380 @@ -26946,7 +27253,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a67 +.fill 7ba9 .fill c300 .fill 1d82 .fill 6380 @@ -26966,7 +27273,7 @@ .fill 1d83 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 1dff .fill 9180 .fill 4001 @@ -26984,19 +27291,19 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4601 .fill ae01 -.fill 6ca5 +.fill 6dd8 .fill b600 .fill 10d0 .fill 11ff @@ -27014,20 +27321,20 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a417 .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 6000 .fill 1080 .fill a40d .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 1dff .fill 9180 .fill 6000 @@ -27040,7 +27347,7 @@ .fill ae00 .fill 4601 .fill ae01 -.fill 6ca5 +.fill 6dd8 .fill b600 .fill 10d0 .fill 11ff @@ -27058,20 +27365,20 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a428 .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 6000 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 6000 .fill 6380 .fill 1d81 @@ -27081,14 +27388,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a40d .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 1dff .fill 9180 .fill 6000 @@ -27101,7 +27408,7 @@ .fill ae00 .fill 4601 .fill ae01 -.fill 6ca5 +.fill 6dd8 .fill b600 .fill 10d0 .fill 11ff @@ -27119,7 +27426,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -27139,7 +27446,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -27158,7 +27465,7 @@ .fill a40d .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 1dff .fill 9180 .fill 2180 @@ -27167,7 +27474,7 @@ .fill 9040 .fill 4601 .fill ae01 -.fill 6ca5 +.fill 6dd8 .fill b600 .fill 10d0 .fill 11ff @@ -27185,7 +27492,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -27205,7 +27512,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -27224,19 +27531,19 @@ .fill a410 .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4601 .fill ae01 -.fill 6ca5 +.fill 6dd8 .fill b600 .fill 10d0 .fill 11ff @@ -27253,14 +27560,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a425 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 1dff .fill 9180 .fill 2180 @@ -27269,7 +27576,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 1dff .fill 9180 .fill 2180 @@ -27293,7 +27600,7 @@ .fill 9040 .fill 4601 .fill ae01 -.fill 6ca5 +.fill 6dd8 .fill b600 .fill 10d0 .fill 11ff @@ -27310,22 +27617,22 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40c .fill 4601 .fill ae01 -.fill 63f0 +.fill 6523 .fill c300 .fill 4601 .fill ae01 -.fill 6ca9 +.fill 6ddc .fill b600 .fill 4601 .fill ae01 -.fill 6ca5 +.fill 6dd8 .fill b600 .fill 10d0 .fill 11ff @@ -27343,7 +27650,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -27363,7 +27670,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -27396,7 +27703,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -27429,14 +27736,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 .fill a40e .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 6000 .fill 2380 .fill 3100 @@ -27453,7 +27760,7 @@ .fill a40d .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 1dff .fill 9180 .fill 6000 @@ -27480,25 +27787,25 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 1080 .fill a405 .fill 4601 .fill ae01 -.fill 6ca9 +.fill 6ddc .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 6000 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 6000 .fill 6380 .fill 1d81 @@ -27508,7 +27815,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -27519,7 +27826,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 6000 .fill 6380 .fill 1d81 @@ -27531,7 +27838,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 6000 .fill 6380 .fill 1d81 @@ -27541,7 +27848,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -27595,7 +27902,7 @@ .fill afbb .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 1dff .fill 9180 .fill 6000 @@ -27622,7 +27929,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 @@ -27643,7 +27950,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79d5 +.fill 7b17 .fill c300 .fill 1d82 .fill 2380 @@ -27661,7 +27968,7 @@ .fill a499 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 6000 .fill 1dff .fill 9180 @@ -27676,7 +27983,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -27697,7 +28004,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 6000 .fill 6380 .fill 1d81 @@ -27709,7 +28016,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 6000 .fill 6380 .fill 1d81 @@ -27719,7 +28026,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 @@ -27778,7 +28085,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e95 +.fill 7fd7 .fill 1dff .fill 9180 .fill 6000 @@ -27801,7 +28108,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 1dff .fill 9180 .fill 6000 @@ -27814,15 +28121,15 @@ .fill ae00 .fill 4601 .fill ae01 -.fill 6100 +.fill 6233 .fill c300 .fill 4601 .fill ae01 -.fill 6742 +.fill 6875 .fill b600 .fill 4001 .fill ae01 -.fill 7e96 +.fill 7fd8 .fill 6000 .fill 1080 .fill a404 @@ -27839,7 +28146,7 @@ .fill 11ff .fill 4601 .fill ae01 -.fill 6e11 +.fill 6f53 .fill b600 .fill ae00 .fill 10d0 @@ -27857,14 +28164,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a417 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 6000 .fill 2380 .fill 3100 @@ -27892,18 +28199,18 @@ .fill 11fe .fill 4601 .fill ae01 -.fill 6e11 +.fill 6f53 .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 6000 .fill 1080 .fill a45b .fill 4001 .fill ae01 -.fill 7e93 +.fill 7fd5 .fill 6000 .fill 1dff .fill 9180 @@ -27916,7 +28223,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -27928,7 +28235,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e93 +.fill 7fd5 .fill 6000 .fill 1dff .fill 9180 @@ -27952,7 +28259,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a67 +.fill 7ba9 .fill c300 .fill 1d82 .fill 6380 @@ -27994,10 +28301,10 @@ .fill ae01 .fill 2180 .fill 1080 -.fill a4af +.fill a4be .fill 4001 .fill ae01 -.fill 7e93 +.fill 7fd5 .fill 6000 .fill 1dff .fill 9180 @@ -28011,11 +28318,11 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 -.fill a458 +.fill a467 .fill 10d0 .fill 11fe .fill 1dff @@ -28029,9 +28336,13 @@ .fill 6000 .fill 1dff .fill 9180 +.fill 2180 +.fill 1183 +.fill 1dff +.fill 9180 .fill 4001 .fill ae01 -.fill 0180 +.fill 0080 .fill 6380 .fill 1d81 .fill 1dff @@ -28040,7 +28351,18 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ba9 +.fill c300 +.fill 1d82 +.fill 6380 +.fill 1d81 +.fill 1dff +.fill 9180 +.fill 1dff +.fill 9380 +.fill 4601 +.fill ae01 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -28092,10 +28414,10 @@ .fill 1d81 .fill 9040 .fill 10c0 -.fill afbb +.fill afac .fill 4001 .fill ae01 -.fill 7e93 +.fill 7fd5 .fill 1dff .fill 9180 .fill 2180 @@ -28106,7 +28428,7 @@ .fill ae00 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 6000 .fill 1dff .fill 9180 @@ -28129,7 +28451,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e93 +.fill 7fd5 .fill 6000 .fill 1dff .fill 9180 @@ -28144,7 +28466,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a67 +.fill 7ba9 .fill c300 .fill 1d82 .fill 6380 @@ -28159,7 +28481,7 @@ .fill 1d83 .fill 4001 .fill ae01 -.fill 7e93 +.fill 7fd5 .fill 1dff .fill 9180 .fill 6000 @@ -28172,7 +28494,7 @@ .fill ae00 .fill 4001 .fill ae01 -.fill 7e94 +.fill 7fd6 .fill 6000 .fill ae01 .fill 2180 @@ -28217,7 +28539,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e98 +.fill 7fda .fill 6000 .fill 1dff .fill 9180 @@ -28236,7 +28558,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 2380 @@ -28291,7 +28613,7 @@ .fill 1ae0 .fill 4001 .fill ae01 -.fill 953d +.fill 96f8 .fill 1dff .fill 9180 .fill 4601 @@ -28376,7 +28698,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 2380 @@ -28427,7 +28749,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -28437,7 +28759,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -28466,7 +28788,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 2380 @@ -28529,7 +28851,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e98 +.fill 7fda .fill 1dff .fill 9180 .fill 10d0 @@ -28553,7 +28875,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -28574,13 +28896,13 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 6000 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 6000 .fill 1dff .fill 9180 @@ -28627,7 +28949,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 @@ -28666,7 +28988,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 6000 .fill 1dff .fill 9180 @@ -28708,7 +29030,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -28766,7 +29088,7 @@ .fill afaf .fill 4001 .fill ae01 -.fill 9540 +.fill 96fb .fill 1dff .fill 9180 .fill 4601 @@ -28776,7 +29098,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 954e +.fill 9709 .fill 1dff .fill 9180 .fill 4601 @@ -28801,14 +29123,14 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 459f +.fill 4601 .fill c300 .fill 1d81 .fill 1080 .fill a40b .fill 4001 .fill ae01 -.fill 9559 +.fill 9714 .fill 1dff .fill 9180 .fill 4601 @@ -28870,14 +29192,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill aa04 .fill 4601 .fill ae01 -.fill 722d +.fill 736f .fill b600 .fill 2180 .fill 1181 @@ -28905,7 +29227,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -28915,7 +29237,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 @@ -28944,7 +29266,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a48 +.fill 7b8a .fill c300 .fill 1d82 .fill 2380 @@ -28976,7 +29298,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 @@ -29016,7 +29338,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 2380 @@ -29056,7 +29378,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 @@ -29104,7 +29426,7 @@ .fill af34 .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 6000 .fill 1dff .fill 9180 @@ -29119,14 +29441,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 .fill a41e .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 6000 .fill 1dff .fill 9180 @@ -29141,7 +29463,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79d5 +.fill 7b17 .fill c300 .fill 1d82 .fill 2380 @@ -29175,7 +29497,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -29185,7 +29507,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ff +.fill 7b41 .fill c300 .fill 1d82 .fill 1080 @@ -29226,7 +29548,7 @@ .fill 10c0 .fill 4601 .fill ae01 -.fill 70ae +.fill 71f0 .fill b600 .fill 2180 .fill 1181 @@ -29255,7 +29577,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 6e17 +.fill 6f59 .fill c300 .fill 1d81 .fill 2180 @@ -29271,12 +29593,12 @@ .fill 1d82 .fill 4001 .fill ae01 -.fill 955c +.fill 9717 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 6e17 +.fill 6f59 .fill c300 .fill 1d81 .fill 10d0 @@ -29310,7 +29632,7 @@ .fill 1d82 .fill 4001 .fill ae01 -.fill 9583 +.fill 973e .fill 1dff .fill 9180 .fill 4601 @@ -29333,7 +29655,7 @@ .fill 1df7 .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 1dff .fill 9180 .fill 2180 @@ -29346,7 +29668,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 958a +.fill 9745 .fill 6380 .fill 1d81 .fill 9040 @@ -29356,7 +29678,7 @@ .fill aa04 .fill 4601 .fill ae01 -.fill 78c5 +.fill 7a07 .fill b600 .fill 10d0 .fill 11f7 @@ -29376,7 +29698,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 6238 +.fill 636b .fill c300 .fill 6380 .fill 1d81 @@ -29387,7 +29709,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 8573 +.fill 86b5 .fill 6380 .fill 1d81 .fill 9040 @@ -29406,7 +29728,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -29436,7 +29758,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -29448,7 +29770,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 459f +.fill 4601 .fill c300 .fill 1d81 .fill 2380 @@ -29464,12 +29786,12 @@ .fill a405 .fill 4601 .fill ae01 -.fill 78c5 +.fill 7a07 .fill b600 .fill ae00 .fill 4001 .fill ae01 -.fill 95a6 +.fill 9761 .fill 1dff .fill 9180 .fill 10d0 @@ -29485,7 +29807,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 6238 +.fill 636b .fill c300 .fill 6380 .fill 1d81 @@ -29506,7 +29828,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -29527,7 +29849,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -29546,7 +29868,7 @@ .fill a405 .fill 4601 .fill ae01 -.fill 78c5 +.fill 7a07 .fill b600 .fill ae00 .fill 10d0 @@ -29565,7 +29887,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -29586,7 +29908,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -29610,7 +29932,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 47c7 +.fill 4829 .fill c300 .fill 1d81 .fill 2380 @@ -29628,12 +29950,12 @@ .fill a405 .fill 4601 .fill ae01 -.fill 78c5 +.fill 7a07 .fill b600 .fill ae00 .fill 4601 .fill ae01 -.fill 78c1 +.fill 7a03 .fill b600 .fill ae00 .fill 10d0 @@ -29651,7 +29973,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -29663,7 +29985,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 47c7 +.fill 4829 .fill c300 .fill 1d81 .fill 1080 @@ -29674,7 +29996,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 95c6 +.fill 9781 .fill 6380 .fill 1d81 .fill 9040 @@ -29685,13 +30007,13 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 95e9 +.fill 97a4 .fill 6380 .fill 1d81 .fill 9040 .fill 4601 .fill ae01 -.fill 78c1 +.fill 7a03 .fill b600 .fill 10d0 .fill 11ff @@ -29708,14 +30030,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a40e .fill 4001 .fill ae01 -.fill 7e90 +.fill 7fd2 .fill 6000 .fill 2380 .fill 3100 @@ -29736,14 +30058,14 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4001 .fill ae01 -.fill 7e8f +.fill 7fd1 .fill 6000 .fill 1dff .fill 9180 @@ -29758,7 +30080,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ab +.fill 7aed .fill c300 .fill 1d82 .fill 1080 @@ -29769,7 +30091,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8f +.fill 7fd1 .fill 6000 .fill 6380 .fill 1d81 @@ -29799,7 +30121,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79d5 +.fill 7b17 .fill c300 .fill 1d82 .fill 1080 @@ -29888,26 +30210,26 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e8f +.fill 7fd1 .fill 6000 .fill 6380 .fill 1d81 .fill 9040 .fill 4001 .fill ae01 -.fill 7e8f +.fill 7fd1 .fill 1dff .fill 9180 .fill 10d0 @@ -29918,13 +30240,13 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 6000 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -29934,19 +30256,19 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 79ab +.fill 7aed .fill c300 .fill 1d82 .fill 1080 .fill a40d .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -29958,13 +30280,13 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 9604 +.fill 97bf .fill 6380 .fill 1d81 .fill 9040 .fill 4601 .fill ae01 -.fill 78c1 +.fill 7a03 .fill b600 .fill 10d0 .fill 11ff @@ -29982,20 +30304,20 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a417 .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 6000 .fill 1080 .fill a40d .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 1dff .fill 9180 .fill 6000 @@ -30008,7 +30330,7 @@ .fill ae00 .fill 4601 .fill ae01 -.fill 78c1 +.fill 7a03 .fill b600 .fill 10d0 .fill 11ff @@ -30026,20 +30348,20 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 .fill a428 .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 6000 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -30049,14 +30371,14 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7981 +.fill 7ac3 .fill c300 .fill 1d82 .fill 1080 .fill a40d .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 1dff .fill 9180 .fill 6000 @@ -30069,7 +30391,7 @@ .fill ae00 .fill 4601 .fill ae01 -.fill 78c1 +.fill 7a03 .fill b600 .fill 10d0 .fill 11ff @@ -30087,7 +30409,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -30107,7 +30429,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -30126,18 +30448,18 @@ .fill a417 .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 6000 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 6eae +.fill 6ff0 .fill c300 .fill 1d81 .fill 6380 @@ -30145,7 +30467,7 @@ .fill 9040 .fill 4601 .fill ae01 -.fill 78c1 +.fill 7a03 .fill b600 .fill 10d0 .fill 11ff @@ -30163,7 +30485,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -30183,7 +30505,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 2380 @@ -30202,18 +30524,18 @@ .fill a417 .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 1dff .fill 9180 .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 6000 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 6f00 +.fill 7042 .fill c300 .fill 1d81 .fill 6380 @@ -30221,7 +30543,7 @@ .fill 9040 .fill 4601 .fill ae01 -.fill 78c1 +.fill 7a03 .fill b600 .fill 10d0 .fill 11ff @@ -30239,7 +30561,7 @@ .fill 9380 .fill 4601 .fill ae01 -.fill 7a29 +.fill 7b6b .fill c300 .fill 1d82 .fill 1080 @@ -30280,13 +30602,13 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 6000 .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 6eae +.fill 6ff0 .fill c300 .fill 1d81 .fill 6380 @@ -30298,7 +30620,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 6000 .fill 1dff .fill 9180 @@ -30367,7 +30689,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 6eae +.fill 6ff0 .fill c300 .fill 1d81 .fill 6380 @@ -30403,7 +30725,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 6f00 +.fill 7042 .fill c300 .fill 1d81 .fill 6380 @@ -30416,7 +30738,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -30458,7 +30780,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 6f00 +.fill 7042 .fill c300 .fill 1d81 .fill 6380 @@ -30466,7 +30788,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 1dff .fill 9180 .fill 10d0 @@ -30485,7 +30807,7 @@ .fill 9040 .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 6000 .fill 1dff .fill 9180 @@ -30504,7 +30826,7 @@ .fill a40c .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 1dff .fill 9180 .fill 10d0 @@ -30516,7 +30838,7 @@ .fill ae00 .fill 4601 .fill ae01 -.fill 78c1 +.fill 7a03 .fill b600 .fill 10d0 .fill 11fe @@ -30524,7 +30846,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 6000 .fill 6380 .fill 1d81 @@ -30631,7 +30953,7 @@ .fill a405 .fill 4601 .fill ae01 -.fill 78c1 +.fill 7a03 .fill b600 .fill ae00 .fill 10d0 @@ -30671,7 +30993,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 7e8e +.fill 7fd0 .fill 6000 .fill 6380 .fill 1d81 @@ -30871,14 +31193,14 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 4609 +.fill 466b .fill c300 .fill 1d84 .fill 1080 .fill a41a .fill 4001 .fill ae01 -.fill 7e97 +.fill 7fd9 .fill 1dff .fill 9180 .fill 10d0 @@ -30908,17 +31230,17 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 9617 +.fill 97d2 .fill 6380 .fill 1d81 .fill 9040 .fill 4601 .fill ae01 -.fill 72a7 +.fill 73e9 .fill b600 .fill 4001 .fill ae01 -.fill 92a9 +.fill 944b .fill 1dff .fill 9180 .fill 4601 @@ -30941,7 +31263,7 @@ .fill 1dfe .fill 4001 .fill ae01 -.fill 963b +.fill 97f6 .fill 1dff .fill 9180 .fill 4601 @@ -30951,7 +31273,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 9640 +.fill 97fb .fill 1dff .fill 9180 .fill 4601 @@ -30961,7 +31283,7 @@ .fill 1d81 .fill 4001 .fill ae01 -.fill 967d +.fill 9838 .fill 1dff .fill 9180 .fill 4601 @@ -30975,7 +31297,7 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 96b5 +.fill 9870 .fill 6380 .fill 1d81 .fill 9040 @@ -31001,12 +31323,12 @@ .fill 9180 .fill 4001 .fill ae01 -.fill 96e3 +.fill 989e .fill 1dff .fill 9180 .fill 4601 .fill ae01 -.fill 0d94 +.fill 0df6 .fill c300 .fill 1d84 .fill 2180 @@ -31015,7 +31337,7 @@ .fill a452 .fill 4001 .fill ae01 -.fill 96e9 +.fill 98a4 .fill 1dff .fill 9180 .fill 4601 @@ -31029,7 +31351,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 66eb +.fill 681e .fill c300 .fill 6380 .fill 1d81 @@ -31075,7 +31397,7 @@ .fill a40b .fill 4001 .fill ae01 -.fill 96ef +.fill 98aa .fill 1dff .fill 9180 .fill 4601 @@ -31091,7 +31413,7 @@ .fill 9180 .fill 4601 .fill ae01 -.fill 58b4 +.fill 5940 .fill c300 .fill 1d81 .fill afaa @@ -36506,6 +36828,92 @@ .fill 0062 .fill 0021 .fill 0000 +.fill 0068 +.fill 0069 +.fill 0073 +.fill 0074 +.fill 006f +.fill 0072 +.fill 0079 +.fill 0000 +.fill 0068 +.fill 0069 +.fill 0073 +.fill 0074 +.fill 006f +.fill 0072 +.fill 0079 +.fill 003a +.fill 0020 +.fill 006c +.fill 0069 +.fill 0073 +.fill 0074 +.fill 0020 +.fill 0074 +.fill 0068 +.fill 0065 +.fill 0020 +.fill 0066 +.fill 006f +.fill 0075 +.fill 0072 +.fill 0020 +.fill 006d +.fill 006f +.fill 0073 +.fill 0074 +.fill 0020 +.fill 0072 +.fill 0065 +.fill 0063 +.fill 0065 +.fill 006e +.fill 0074 +.fill 0020 +.fill 006e +.fill 006f +.fill 006e +.fill 0065 +.fill 006d +.fill 0070 +.fill 0074 +.fill 0079 +.fill 0020 +.fill 0073 +.fill 0068 +.fill 0065 +.fill 006c +.fill 006c +.fill 0020 +.fill 0063 +.fill 006f +.fill 006d +.fill 006d +.fill 0061 +.fill 006e +.fill 0064 +.fill 0073 +.fill 0020 +.fill 0066 +.fill 0072 +.fill 006f +.fill 006d +.fill 0020 +.fill 0074 +.fill 0068 +.fill 0069 +.fill 0073 +.fill 0020 +.fill 0073 +.fill 0065 +.fill 0073 +.fill 0073 +.fill 0069 +.fill 006f +.fill 006e +.fill 002e +.fill 0000 .fill 0063 .fill 006c .fill 0065 @@ -36839,6 +37247,16 @@ .fill 0020 .fill 007c .fill 0020 +.fill 0068 +.fill 0069 +.fill 0073 +.fill 0074 +.fill 006f +.fill 0072 +.fill 0079 +.fill 0020 +.fill 007c +.fill 0020 .fill 0063 .fill 006c .fill 0065 @@ -38046,6 +38464,21 @@ .fill 0029 .fill 0000 .fill 0055 +.fill 0073 +.fill 0061 +.fill 0067 +.fill 0065 +.fill 003a +.fill 0020 +.fill 0068 +.fill 0069 +.fill 0073 +.fill 0074 +.fill 006f +.fill 0072 +.fill 0079 +.fill 0000 +.fill 0055 .fill 006e .fill 006b .fill 006e @@ -38073,6 +38506,8 @@ .fill 0070 .fill 002e .fill 0000 +.fill 0020 +.fill 0000 .fill 000d .fill 001b .fill 005b @@ -38113,6 +38548,14 @@ .fill 006c .fill 0074 .fill 0020 +.fill 0068 +.fill 0069 +.fill 0073 +.fill 0074 +.fill 006f +.fill 0072 +.fill 0079 +.fill 0020 .fill 006c .fill 0069 .fill 0073 diff --git a/kernel/API.md b/kernel/API.md index 3402825..20a8ec2 100644 --- a/kernel/API.md +++ b/kernel/API.md @@ -29,7 +29,8 @@ unbuffered keys, converts Enter to newline, and treats Ctrl+D as EOF. Ctrl+Z is an ordinary control character: shell EOF, full-screen editor undo. Redirected input uses getchar. `bob_terminal()` (trap 9) returns 1 only when both input/output are native Windows console handles; otherwise 0. Shell -history, completion and editing are guest code in `kernel/input.c`. ANSI key +history, completion and editing are guest code in `kernel/input.c`; the shell's +`history` command lists the same four recent entries. ANSI key sequences in redirected regression fixtures exercise the same guest actions. `bob_columns()` (trap 10) reports the console buffer width, or 80 as fallback. The shell scrolls a long input line horizontally to keep redraw within it. @@ -74,9 +75,10 @@ returning its slot or -1 for a bad name, length or a full table. Kind 0 is text; kind 1 is machine code, kind 2 is resident bob32 C code, and kind 3 is a packed native B32K v2 image. Its copy appends a zero word, which is not part of length. Names hold at most 23 characters. bob16 retains eight fixed 511-word slots; -bob32 packs files into a shared 4,096-word content region. Text files remain -limited to 511 words; resident programs and native images can use the remaining -shared capacity (up to 4,095 words per file). Valid slot indices are 0..7. +bob32 packs files into a protected 8,192-word content region at `0x1E000`, +between the kernel and supervised-app regions. Text files remain limited to 511 +words; resident programs and native images can use the remaining shared capacity +(up to 8,191 words per file). Valid slot indices are 0..7. These are internal kernel APIs. Failed size/name validation does not overwrite an existing file. Edits start @@ -131,16 +133,87 @@ kernel code; ordinary shell programs use bob_run for recovery and write checks. See [the OS guide](../C_OS.md) for commands, examples and C subset limits. In bob32 mode, `import32 HOST_PATH NAME` validates and packs a B32K v2 image -into a guest RAM file; `run NAME` loads and executes it. B32S version 2 -snapshots preserve packed files; version 1 fixed-slot snapshots remain readable -and are converted to the packed layout on restore. `run32 HOST_PATH` remains +into a guest RAM file; `run NAME` loads and executes it. B32S version 3 +snapshots preserve the expanded filesystem; versions 1 and 2 remain readable +and are migrated to the current storage layout on restore. `run32 HOST_PATH` remains available for direct host-path launches. Native C applications can include `bob_string.h` for small app-side string and parsing helpers. It provides bounded integer formatting, status-returning decimal/hex parsing, and in-place quoted tokenization without depending on the kernel's private runtime functions. +`bob_native.h` is an optional convenience include for the common native API +surface: core `bob.h` calls, strings, app-managed memory, filesystem, process, +time, and input events. Graphics and GUI remain opt-in via `bob_gfx.h` and +`bob_gui.h` so text-only apps do not pull in widget code. +`bob_memory.h` provides a caller-owned word arena. Keep an integer buffer and a +used-word counter, request word counts with `bob_arena_alloc`, inspect +used/remaining capacity, and reset the counter when its allocations are no longer +needed. Exhaustion and invalid sizes return null; no OS-global heap is reserved. Native apps may define `main(int argc, char **argv)`; when launched by guest filename, `argv[0]` is that filename and `argc` includes it. `run app first "two words"` groups quoted words; backslash escapes the following character and `""` supplies an empty argument. + +`bob_fs.h` exposes the version 1 native-app filesystem service through +`bob_file_list`, `bob_file_read`, `bob_file_write`, `bob_file_delete`, +`bob_file_read_words`, `bob_file_write_words`, and `bob_file_kind`. Listing +returns kind and word-size metadata; `bob_file_kind` queries the kind directly +by name. Text reads/writes handle up to 511 characters. Word-file +helpers preserve binary values for bob16 and bob32 program kinds. Native B32K +images can be read as words, but must use the validated `import32` path to enter +the filesystem as runnable apps. Applications pass buffers in their own memory, +while the emulator validates and copies data to keep kernel tables private. +Files remain in the guest RAM filesystem and follow the normal B32S save/restore +flow. B32S v3 stores the expanded payload; v1 fixed-slot and v2 packed snapshots +remain readable. +`bob_system_info` reports the service version, app address-space size, mapped +pages, and filesystem slot/word usage through the same versioned boundary. + +`bob_process.h` adds `bob_app_run(name, arguments, &exit_code)` through version 1 +service operation 6. It launches a stored kind-3 B32K image with shell-style +quoted arguments, preserves the suspended caller's sparse application memory, +and separates launch errors from the child's exit code. Nested launches are +limited to eight active app frames. The API returns -1 when the app name is +missing, -2 for a non-native file, -4 for invalid data, and -5 when memory is +unavailable. The `launcher` app lists stored native images and can run one with +`run launcher APP [ARG ...]`. + +`bob_time.h` exposes version 1 time operation 7. `bob_time_utc_seconds(words)` +fills two 32-bit words with the low and high halves of UTC seconds since the +Unix epoch and returns 2. It returns a negative status for an invalid request. + +`bob_gfx.h` uses that OS boundary for an 80x25 cell framebuffer: enter/query, +clear, pixel, filled rectangle, line, text, transparent bitmap blit, present, +and leave. Each cell carries a 16-color foreground. Draw calls update a back +buffer; present renders it, and supervised app exit closes an unclosed canvas. +`bob_gfx_blit_color` accepts transparent row-major cells with an ASCII character +in bits 0..7 and a foreground color in bits 8..11; invalid cell values reject +the whole call before drawing. +`bob_font.h` adds an opt-in 5x7 bitmap font helper. `bob_gfx_bitmap_text` +rasterizes uppercase letters, digits, space, and common punctuation into the +canvas via the colored bitmap service; lowercase letters map to uppercase and +unsupported characters use `?`. +`bob_event.h` provides `bob_event_wait` and nonblocking `bob_event_poll` with +four-word events. Poll returns 1 for an event or 0 when the console queue is +empty; redirected input is left for the blocking wait and is not peeked. +Version 1 reports typed characters, special-key presses, key releases, mouse +movement and mouse button transitions when the Windows console provides those +records. Mouse coordinates are console-cell coordinates; redirected input +remains character based. +`bob_event_queue.h` adds an app-owned FIFO for those same four-word events. +Initialize a two-word `{head,count}` state, allocate four storage words per +queue slot, then use `bob_event_queue_push`/`pop`; push returns 0 when full +without overwriting older events, and pop returns 0 when empty. Invalid +capacity/state returns -1. The queue is optional and requires no OS memory. +`bob_wm.h` adds a small reusable window manager over caller-provided fixed +arrays. Initialize it with a window limit and screen size, then use create, +destroy, focus, raise, move, show/hide, and invalidate operations. Dispatch +returns a recipient ID, routes keys to the focused visible window, raises the +topmost clicked window, captures title-bar drags, and supplies window-local +mouse coordinates. `bob_wm_begin_draw` starts a redraw pass and repeated +`bob_wm_next_dirty` calls yield visible windows bottom-to-top; geometry and +stacking changes request a full redraw, while invalidation also marks any +overlapping windows so they repaint correctly. The manager stores no app-specific +titles or callbacks; applications keep their own state and draw their own +contents through `bob_gui.h` and `bob_gfx.h`. diff --git a/kernel/bob.h b/kernel/bob.h index 8c0332f..3bc0225 100644 --- a/kernel/bob.h +++ b/kernel/bob.h @@ -10,6 +10,8 @@ int bob_run(int entry); int bob_run_image(const char *path); int bob_import_image(int *descriptor); int bob_run_native(const int *descriptor); +int bob_os_service(int *request); +int bob_fs_register(int *descriptor); int bob_snapshot(int *descriptor, int operation); int bob_key(void); int bob_terminal(void); diff --git a/kernel/bob_event.h b/kernel/bob_event.h new file mode 100644 index 0000000..128a018 --- /dev/null +++ b/kernel/bob_event.h @@ -0,0 +1,37 @@ +#ifndef BOB_EVENT_H +#define BOB_EVENT_H + +#include "bob.h" + +#define BOB_EVENT_API_VERSION 1 +#define BOB_EVENT_KEY_DOWN 1 +#define BOB_EVENT_CHAR 2 +#define BOB_EVENT_KEY_UP 3 +#define BOB_EVENT_MOUSE_MOVE 4 +#define BOB_EVENT_MOUSE_BUTTON_DOWN 5 +#define BOB_EVENT_MOUSE_BUTTON_UP 6 +#define BOB_EVENT_MOUSE_WHEEL 7 +#define BOB_EVENT_POLL 28 +#define BOB_MOUSE_BUTTON_LEFT 1 +#define BOB_MOUSE_BUTTON_RIGHT 2 +#define BOB_MOUSE_BUTTON_MIDDLE 4 + +/* Four words: type, key/character/buttons/wheel delta, x, y. Blocks until input or EOF. */ +int bob_event_wait(int *event) { + int request[7]; + request[0]=(BOB_EVENT_API_VERSION << 16) | 26; + request[1]=(int)event;request[2]=4; + request[3]=0;request[4]=0;request[5]=0;request[6]=0; + return bob_os_service(request); +} + +/* Returns 1 with an event, 0 when no console event is available, negative on bad input. */ +int bob_event_poll(int *event) { + int request[7]; + request[0]=(BOB_EVENT_API_VERSION << 16) | BOB_EVENT_POLL; + request[1]=(int)event;request[2]=4; + request[3]=0;request[4]=0;request[5]=0;request[6]=0; + return bob_os_service(request); +} + +#endif diff --git a/kernel/bob_event_queue.h b/kernel/bob_event_queue.h new file mode 100644 index 0000000..943d2d8 --- /dev/null +++ b/kernel/bob_event_queue.h @@ -0,0 +1,36 @@ +#ifndef BOB_EVENT_QUEUE_H +#define BOB_EVENT_QUEUE_H + +#include "bob_event.h" + +/* Caller-owned FIFO state is head,count; storage holds capacity four-word events. */ +void bob_event_queue_init(int *state) { + if(!state)return; + state[0]=0;state[1]=0; +} + +/* Push returns 1 on success, 0 if full, and -1 for invalid state or arguments. */ +int bob_event_queue_push(int *state,int *storage,int capacity,const int *event) { + int tail; + if(!state||!storage||!event||capacity<1||state[0]<0||state[0]>=capacity|| + state[1]<0||state[1]>capacity)return -1; + if(state[1]==capacity)return 0; + tail=(state[0]+state[1])%capacity; + for(int i=0;i<4;i++)storage[tail*4+i]=event[i]; + state[1]++; + return 1; +} + +/* Pop returns 1 with an event, 0 when empty, and -1 for invalid state or arguments. */ +int bob_event_queue_pop(int *state,int *storage,int capacity,int *event) { + int head; + if(!state||!storage||!event||capacity<1||state[0]<0||state[0]>=capacity|| + state[1]<0||state[1]>capacity)return -1; + if(!state[1])return 0; + head=state[0]; + for(int i=0;i<4;i++)event[i]=storage[head*4+i]; + state[0]=(head+1)%capacity;state[1]--; + return 1; +} + +#endif diff --git a/kernel/bob_font.h b/kernel/bob_font.h new file mode 100644 index 0000000..fe6af20 --- /dev/null +++ b/kernel/bob_font.h @@ -0,0 +1,59 @@ +#ifndef BOB_FONT_H +#define BOB_FONT_H + +#include "bob_gfx.h" + +/* 5x7 column bitmaps: blank, A-Z, 0-9, ?, !, -, .; lowercase maps to uppercase. */ +static int bob_font5x7[41][5]={ + {0,0,0,0,0}, + {0x7e,0x11,0x11,0x11,0x7e},{0x7f,0x49,0x49,0x49,0x36}, + {0x3e,0x41,0x41,0x41,0x22},{0x7f,0x41,0x41,0x22,0x1c}, + {0x7f,0x49,0x49,0x49,0x41},{0x7f,0x09,0x09,0x09,0x01}, + {0x3e,0x41,0x49,0x49,0x7a},{0x7f,0x08,0x08,0x08,0x7f}, + {0x00,0x41,0x7f,0x41,0x00},{0x20,0x40,0x41,0x3f,0x01}, + {0x7f,0x08,0x14,0x22,0x41},{0x7f,0x40,0x40,0x40,0x40}, + {0x7f,0x02,0x0c,0x02,0x7f},{0x7f,0x04,0x08,0x10,0x7f}, + {0x3e,0x41,0x41,0x41,0x3e},{0x7f,0x09,0x09,0x09,0x06}, + {0x3e,0x41,0x51,0x21,0x5e},{0x7f,0x09,0x19,0x29,0x46}, + {0x46,0x49,0x49,0x49,0x31},{0x01,0x01,0x7f,0x01,0x01}, + {0x3f,0x40,0x40,0x40,0x3f},{0x1f,0x20,0x40,0x20,0x1f}, + {0x3f,0x40,0x38,0x40,0x3f},{0x63,0x14,0x08,0x14,0x63}, + {0x07,0x08,0x70,0x08,0x07},{0x61,0x51,0x49,0x45,0x43}, + {0x3e,0x51,0x49,0x45,0x3e},{0x00,0x42,0x7f,0x40,0x00}, + {0x62,0x51,0x49,0x49,0x46},{0x22,0x41,0x49,0x49,0x36}, + {0x18,0x14,0x12,0x7f,0x10},{0x2f,0x49,0x49,0x49,0x31}, + {0x3e,0x49,0x49,0x49,0x32},{0x01,0x71,0x09,0x05,0x03}, + {0x36,0x49,0x49,0x49,0x36},{0x26,0x49,0x49,0x49,0x3e}, + {0x02,0x01,0x51,0x09,0x06},{0x00,0x00,0x5f,0x00,0x00}, + {0x08,0x08,0x08,0x08,0x08},{0x00,0x60,0x60,0x00,0x00} +}; + +/* Draws uppercase 5x7 glyphs at cell-pixel resolution; clips at the right edge. */ +int bob_gfx_bitmap_text(int x,int y,const char *text,int color) { + int bitmap[560]; + int length=0,width,max_chars,character,glyph,cell; + if(x<0||y<0||x>=80||y+7>25||color<0||color>15)return -1; + max_chars=(80-x+1)/6; + while(text[length]&&length='a'&&character<='z')character-=32; + if(character==' ')glyph=0; + else if(character>='A'&&character<='Z')glyph=1+character-'A'; + else if(character>='0'&&character<='9')glyph=27+character-'0'; + else if(character=='!')glyph=38; + else if(character=='-')glyph=39; + else if(character=='.')glyph=40; + else glyph=37; + for(int column=0;column<5;column++)for(int row=0;row<7;row++) { + cell=(bob_font5x7[glyph][column]&(1<=rect[0]&&y>=rect[1]&&x=0;i--) { + int id=order[i]; + if(id>=0&&id=rect[0]+rect[2]||y!=rect[1])return 0; + drag[0]=1;drag[1]=x-rect[0];drag[2]=y-rect[1];return 1; +} + +int bob_gui_drag_update(int *rect,int *drag,int x,int y,int screen_width,int screen_height) { + int max_x,max_y; + if(!drag[0])return 0; + max_x=screen_width-rect[2];max_y=screen_height-rect[3]; + if(max_x<0)max_x=0;if(max_y<0)max_y=0; + rect[0]=x-drag[1];rect[1]=y-drag[2]; + if(rect[0]<0)rect[0]=0;if(rect[0]>max_x)rect[0]=max_x; + if(rect[1]<0)rect[1]=0;if(rect[1]>max_y)rect[1]=max_y; + return 1; +} + +int bob_gui_drag_stop(int *drag) { + int was_dragging=drag[0];drag[0]=0;return was_dragging; +} + +/* Button state is hovered, pressed; returns one only for an inside release. */ +int bob_gui_button_event(const int *rect,int *state,const int *event) { + int inside=bob_gui_window_hit(event[2],event[3],rect); + if(event[0]==BOB_EVENT_MOUSE_MOVE)state[0]=inside; + else if(event[0]==BOB_EVENT_MOUSE_BUTTON_DOWN) { + state[0]=inside;state[1]=inside&&((event[1]&BOB_MOUSE_BUTTON_LEFT)!=0); + } else if(event[0]==BOB_EVENT_MOUSE_BUTTON_UP) { + state[0]=inside; + if(state[1]&&inside&&!(event[1]&BOB_MOUSE_BUTTON_LEFT)){state[1]=0;return 1;} + state[1]=0; + } + return 0; +} + +int bob_gui_button_draw(int x,int y,int width,int height,const char *label, + int hovered,int pressed) { + int color=pressed?14:(hovered?11:7); + int label_length=0,label_start=0,label_x,label_width; + if(width<3||height<3)return -1; + while(label[label_length])label_length++; + bob_gfx_fill_rect(x,y,width,height,' ',color); + bob_gfx_line(x+1,y,x+width-2,y,pressed?'=':'-',color); + bob_gfx_line(x+1,y+height-1,x+width-2,y+height-1,pressed?'=':'-',color); + bob_gfx_line(x,y+1,x,y+height-2,'|',color); + bob_gfx_line(x+width-1,y+1,x+width-1,y+height-2,'|',color); + bob_gfx_pixel(x,y,'+',color);bob_gfx_pixel(x+width-1,y,'+',color); + bob_gfx_pixel(x,y+height-1,'+',color);bob_gfx_pixel(x+width-1,y+height-1,'+',color); + label_width=width-2; + if(label_length>label_width){label_start=(label_length-label_width)/2;label_length=label_width;} + label_x=x+1+(label_width-label_length)/2; + for(int i=0;i80||rect[3]!=count+2|| + rect[0]<0||rect[1]<0||rect[0]+rect[2]>80||rect[1]+rect[3]>25)return -1; + bob_gfx_fill_rect(rect[0],rect[1],rect[2],rect[3],' ',7); + bob_gfx_line(rect[0]+1,rect[1],rect[0]+rect[2]-2,rect[1],'-',7); + bob_gfx_line(rect[0]+1,rect[1]+rect[3]-1,rect[0]+rect[2]-2,rect[1]+rect[3]-1,'-',7); + bob_gfx_line(rect[0],rect[1]+1,rect[0],rect[1]+rect[3]-2,'|',7); + bob_gfx_line(rect[0]+rect[2]-1,rect[1]+1,rect[0]+rect[2]-1,rect[1]+rect[3]-2,'|',7); + bob_gfx_pixel(rect[0],rect[1],'+',7);bob_gfx_pixel(rect[0]+rect[2]-1,rect[1],'+',7); + bob_gfx_pixel(rect[0],rect[1]+rect[3]-1,'+',7);bob_gfx_pixel(rect[0]+rect[2]-1,rect[1]+rect[3]-1,'+',7); + for(int row=0;row':' ',color); + while(lengthscreen_width)rect[0]=screen_width-width; + if(rect[0]<0)rect[0]=0; + if(rect[1]+height>screen_height)rect[1]=screen_height-height; + if(rect[1]<0)rect[1]=0; + return 0; +} + +/* Returns the activated row, -1 for no action, or -2 when Escape closes it. */ +int bob_gui_menu_event(const int *rect,int count,int *state,const int *event) { + int row=-1; + if(count<1||rect[3]!=count+2)return -1; + if(event[2]>=rect[0]+1&&event[2]=rect[1]+1&&event[3]=0&&(event[1]&BOB_MOUSE_BUTTON_LEFT)?row:-1; + } else if(event[0]==BOB_EVENT_MOUSE_BUTTON_UP) { + int activated=row>=0&&state[1]==row&&!(event[1]&BOB_MOUSE_BUTTON_LEFT)?row:-1; + state[0]=row;state[1]=-1;return activated; + } else if(event[0]==BOB_EVENT_KEY_DOWN) { + if(event[1]==256)state[0]=state[0]<=0?count-1:state[0]-1; + else if(event[1]==257)state[0]=state[0<0||state[0]>=count-1?0:state[0]+1]; + } else if(event[0]==BOB_EVENT_CHAR) { + if(event[1]==27)return -2; + if((event[1]==10||event[1]==13)&&state[0]>=0&&state[0]length)state[1]=length; + } + } else if(state[0]&&event[0]==BOB_EVENT_CHAR) { + if(event[1]>=32&&event[1]<127&&lengthstate[1];i--)buffer[i]=buffer[i-1]; + buffer[state[1]++]=event[1];buffer[++length]=0;changed=1; + } else if((event[1]==8||event[1]==127)&&state[1]>0) { + for(int i=state[1]-1;i0)state[1]--; + else if(event[1]==259&&state[1]=state[2]+visible)state[2]=state[1]-visible+1; + return changed; +} + +int bob_gui_text_field_draw(const int *rect,const char *buffer,const int *state) { + int visible=rect[2]-2; + char shown[80]; + int i=0; + if(rect[2]<3||rect[2]>80||rect[3]<3)return -1; + bob_gfx_fill_rect(rect[0],rect[1],rect[2],rect[3],' ',state[0]?15:8); + bob_gfx_line(rect[0]+1,rect[1],rect[0]+rect[2]-2,rect[1],'-',state[0]?15:8); + bob_gfx_line(rect[0]+1,rect[1]+rect[3]-1,rect[0]+rect[2]-2,rect[1]+rect[3]-1,'-',state[0]?15:8); + bob_gfx_line(rect[0],rect[1]+1,rect[0],rect[1]+rect[3]-2,'|',state[0]?15:8); + bob_gfx_line(rect[0]+rect[2]-1,rect[1]+1,rect[0]+rect[2]-1,rect[1]+rect[3]-2,'|',state[0]?15:8); + for(i=0;i=0&&state[1]-state[2]=capacity-1)return 0; + for(int i=*length;i>*cursor;i--)buffer[i]=buffer[i-1]; + buffer[*cursor]=value;(*cursor)++;(*length)++;buffer[*length]=0; + return 1; +} + +static void bob_gui_text_area_position(const char *buffer,int cursor,int *line,int *column) { + *line=0;*column=0; + for(int i=0;i=state[2]+visible)state[2]=line-visible+1; +} + +int bob_gui_text_area_reveal(const char *buffer,int *state,const int *rect) { + bob_gui_text_area_scroll(buffer,state[1],state,rect); + return 0; +} + +int bob_gui_text_area_event(const int *rect,char *buffer,int *state,int capacity,const int *event) { + int length=0,changed=0,line,column,start,end,next_start,next_end,target,visible,total_lines,max_scroll,old_scroll; + while(length0&&state[2]>0)state[2]--; + else if(event[1]<0&&state[2]0){start++;column--;} + state[1]=start; + } + } else if(state[0]&&event[0]==BOB_EVENT_CHAR) { + if(event[1]==8||event[1]==127) { + if(state[1]>0) { + for(int i=state[1]-1;i=32&&event[1]<127) { + changed=bob_gui_text_area_insert(buffer,&length,&state[1],capacity,(char)event[1]); + } + } else if(state[0]&&event[0]==BOB_EVENT_KEY_DOWN) { + bob_gui_text_area_position(buffer,state[1],&line,&column); + if(event[1]==258&&state[1]>0)state[1]--; + else if(event[1]==259&&state[1]0&&buffer[start-1]!='\n')start--;state[1]=start; + } else if(event[1]==261) { + end=state[1];while(end0&&buffer[start-1]!='\n')start--; + end=state[1];while(end0) { + next_end=start-1;next_start=next_end; + while(next_start>0&&buffer[next_start-1]!='\n')next_start--; + target=next_start+column;if(target>next_end)target=next_end;state[1]=target; + } else if(event[1]==257&&endnext_end)target=next_end;state[1]=target; + } + } + } + bob_gui_text_area_scroll(buffer,state[1],state,rect); + return changed; +} + +int bob_gui_text_area_draw(const int *rect,const char *buffer,const int *state) { + int width=rect[2]-2,height=rect[3]-2,length=0,line=0,column=0; + int position=0,row,row_start,row_end,offset,shown_length,cursor_line,cursor_column; + char shown[80]; + if(rect[2]<3||rect[2]>80||rect[3]<3)return -1; + while(buffer[length])length++; + bob_gfx_fill_rect(rect[0],rect[1],rect[2],rect[3],' ',state[0]?15:8); + bob_gfx_line(rect[0]+1,rect[1],rect[0]+rect[2]-2,rect[1],'-',state[0]?15:8); + bob_gfx_line(rect[0]+1,rect[1]+rect[3]-1,rect[0]+rect[2]-2,rect[1]+rect[3]-1,'-',state[0]?15:8); + bob_gfx_line(rect[0],rect[1]+1,rect[0],rect[1]+rect[3]-2,'|',state[0]?15:8); + bob_gfx_line(rect[0]+rect[2]-1,rect[1]+1,rect[0]+rect[2]-1,rect[1]+rect[3]-2,'|',state[0]?15:8); + bob_gui_text_area_position(buffer,state[1],&cursor_line,&cursor_column); + while(position=width)offset=cursor_column-width+1; + shown_length=0; + while(shown_length=offset&&cursor_column-offset=length)break; + position=row_end+1;line++; + } + return 0; +} + +/* Reusable character-cell window frame and content area. */ +int bob_gui_window(int x,int y,int width,int height,const char *title, + const char *body,const char *message,int focused) { + int edge=focused?14:8; + int title_color=focused?15:7; + if(width<4||height<4)return -1; + bob_gfx_fill_rect(x,y,width,height,' ',edge); + bob_gfx_line(x+1,y,x+width-2,y,'-',edge); + bob_gfx_line(x+1,y+height-1,x+width-2,y+height-1,'-',edge); + bob_gfx_line(x,y+1,x,y+height-2,'|',edge); + bob_gfx_line(x+width-1,y+1,x+width-1,y+height-2,'|',edge); + bob_gfx_pixel(x,y,'+',edge);bob_gfx_pixel(x+width-1,y,'+',edge); + bob_gfx_pixel(x,y+height-1,'+',edge);bob_gfx_pixel(x+width-1,y+height-1,'+',edge); + bob_gfx_fill_rect(x+1,y+1,width-2,1,' ',focused?4:8); + bob_gfx_text(x+2,y+1,title,title_color); + bob_gfx_text(x+2,y+3,body,edge); + if(message)bob_gfx_text(x+2,y+height-2,message,focused?10:7); + return 0; +} + +#endif diff --git a/kernel/bob_memory.h b/kernel/bob_memory.h new file mode 100644 index 0000000..25c4bd3 --- /dev/null +++ b/kernel/bob_memory.h @@ -0,0 +1,18 @@ +#ifndef BOB_MEMORY_H +#define BOB_MEMORY_H + +/* Caller-owned word arena; allocation sizes are target words, not host bytes. */ +int bob_arena_reset(int *used) { if(!used)return -1;*used=0;return 0; } +int *bob_arena_alloc(int *storage,int capacity,int *used,int words) { + int *result; + if(!storage||!used||capacity<=0||words<=0||*used<0||*used>capacity)return 0; + if(words>capacity-*used)return 0; + result=storage+*used;*used+=words;return result; +} +int bob_arena_used(int *used) { if(!used||*used<0)return -1;return *used; } +int bob_arena_remaining(int capacity,int *used) { + if(!used||capacity<0||*used<0||*used>capacity)return -1; + return capacity-*used; +} + +#endif diff --git a/kernel/bob_native.h b/kernel/bob_native.h new file mode 100644 index 0000000..283b7bd --- /dev/null +++ b/kernel/bob_native.h @@ -0,0 +1,15 @@ +#ifndef BOB_NATIVE_H +#define BOB_NATIVE_H + +/* Common bob32 application APIs. Include bob_gfx.h/bob_gui.h only when needed. */ +#include "bob.h" +#include "bob_string.h" +#include "bob_memory.h" +#include "bob_fs.h" +#include "bob_system.h" +#include "bob_process.h" +#include "bob_time.h" +#include "bob_event.h" +#include "bob_event_queue.h" + +#endif diff --git a/kernel/bob_process.h b/kernel/bob_process.h new file mode 100644 index 0000000..68d1fde --- /dev/null +++ b/kernel/bob_process.h @@ -0,0 +1,14 @@ +#ifndef BOB_PROCESS_H +#define BOB_PROCESS_H + +#include "bob_fs.h" + +/* Run a stored native bob32 app; returns service status and writes child status. */ +int bob_app_run(const char *name,const char *arguments,int *exit_code) { + int request[7]; + request[0]=BOB_FS_REQUEST(BOB_FS_RUN_APP);request[1]=(int)name;request[2]=(int)arguments; + request[3]=(int)exit_code;request[4]=0;request[5]=0;request[6]=0; + return bob_os_service(request); +} + +#endif diff --git a/kernel/bob_system.h b/kernel/bob_system.h new file mode 100644 index 0000000..079496d --- /dev/null +++ b/kernel/bob_system.h @@ -0,0 +1,21 @@ +#ifndef BOB_SYSTEM_H +#define BOB_SYSTEM_H + +#include "bob.h" + +#define BOB_SYSTEM_API_VERSION 1 +#define BOB_SYSTEM_CAPABILITIES 11 +#define BOB_SYSTEM_DEVICE_CELL_FRAMEBUFFER 1 +#define BOB_SYSTEM_INPUT_KEYBOARD 1 +#define BOB_SYSTEM_INPUT_MOUSE 2 + +/* Returns version, device flags, cell width/height, and input flags. */ +int bob_system_capabilities(int *values,int capacity) { + int request[7]; + request[0]=(BOB_SYSTEM_API_VERSION << 16) | BOB_SYSTEM_CAPABILITIES; + request[1]=(int)values;request[2]=capacity; + request[3]=0;request[4]=0;request[5]=0;request[6]=0; + return bob_os_service(request); +} + +#endif diff --git a/kernel/bob_time.h b/kernel/bob_time.h new file mode 100644 index 0000000..3fac74a --- /dev/null +++ b/kernel/bob_time.h @@ -0,0 +1,18 @@ +#ifndef BOB_TIME_H +#define BOB_TIME_H + +#include "bob.h" + +#define BOB_TIME_API_VERSION 1 +#define BOB_TIME_GET_UTC_SECONDS 7 + +/* Writes low/high 32-bit words of UTC seconds since 1970-01-01. */ +int bob_time_utc_seconds(int *words) { + int request[7]; + request[0]=(BOB_TIME_API_VERSION << 16) | BOB_TIME_GET_UTC_SECONDS; + request[1]=(int)words;request[2]=2;request[3]=0;request[4]=0; + request[5]=0;request[6]=0; + return bob_os_service(request); +} + +#endif diff --git a/kernel/bob_wm.h b/kernel/bob_wm.h new file mode 100644 index 0000000..f26da49 --- /dev/null +++ b/kernel/bob_wm.h @@ -0,0 +1,193 @@ +#ifndef BOB_WM_H +#define BOB_WM_H + +#include "bob_event.h" + +/* App-owned window records contain x,y,w,h,visible,dirty,allocated. */ +#define BOB_WM_MAX_WINDOWS 8 +#define BOB_WM_WINDOW_WORDS 7 +#define BOB_WM_STATE_WORDS 10 + +/* State contains max,count,focus,drag,offset-x,offset-y,screen-w,screen-h, + full-dirty,draw-cursor. Z-order is an app-owned bottom-to-top ID array. */ +static int bob_wm_window_valid(const int *state,const int *windows,int id) { + return state&&windows&&id>=0&&idmax_x)window[0]=max_x; + if(window[1]<0)window[1]=0;if(window[1]>max_y)window[1]=max_y; +} + +int bob_wm_init(int *state,int *windows,int *order,int maximum,int screen_width,int screen_height) { + if(!state||!windows||!order||maximum<1||maximum>BOB_WM_MAX_WINDOWS|| + screen_width<1||screen_height<1)return -1; + for(int i=0;istate[6]||height>state[7])return -1; + for(int i=0;i=state[0])return -1; + int *window=windows+id*BOB_WM_WINDOW_WORDS; + window[0]=x;window[1]=y;window[2]=width;window[3]=height; + window[4]=1;window[5]=1;window[6]=1;bob_wm_clamp(window,state); + order[state[1]++]=id;state[2]=id;state[3]=-1; + for(int i=0;i=0&&old=0;i--)if(windows[order[i]*BOB_WM_WINDOW_WORDS+4]){state[2]=order[i];break;} + if(state[2]>=0)windows[state[2]*BOB_WM_WINDOW_WORDS+5]=1; + } + bob_wm_mark_all(state,windows,order);return 1; +} + +int bob_wm_destroy(int *state,int *windows,int *order,int id) { + int index=-1,was_focused; + if(!bob_wm_window_valid(state,windows,id))return -1; + for(int i=0;i=0;i--)if(windows[order[i]*BOB_WM_WINDOW_WORDS+4]){state[2]=order[i];break;} + } + if(state[2]>=0)windows[state[2]*BOB_WM_WINDOW_WORDS+5]=1; + bob_wm_mark_all(state,windows,order);return 0; +} + +int bob_wm_window_at(const int *state,const int *windows,const int *order,int x,int y) { + if(!state||!windows||!order)return -1; + for(int i=state[1]-1;i>=0;i--) { + int id=order[i];int *window=(int *)(windows+id*BOB_WM_WINDOW_WORDS); + if(bob_wm_window_valid(state,windows,id)&&window[4]&& + x>=window[0]&&y>=window[1]&&x=0) { + bob_wm_focus(state,windows,order,target); + int *window=windows+target*BOB_WM_WINDOW_WORDS; + if((event[1]&BOB_MOUSE_BUTTON_LEFT)&&y==window[1]) { + state[3]=target;state[4]=x-window[0];state[5]=y-window[1]; + } + } + } + if(target<0)return -1; + routed[2]=x-windows[target*BOB_WM_WINDOW_WORDS]; + routed[3]=y-windows[target*BOB_WM_WINDOW_WORDS+1]; + return target; +} + +void bob_wm_invalidate(int *state,int *windows,int *order,int id) { + if(!bob_wm_window_valid(state,windows,id))return; + windows[id*BOB_WM_WINDOW_WORDS+5]=1; + for(int i=0;i= targetOffset; i--) ((int *)0xf000)[i + length + 1] = ((int *)0xf000)[i]; + for (i = total - 1; i >= targetOffset; i--) ((int *)WIDE_FILE_BASE)[i + length + 1] = ((int *)WIDE_FILE_BASE)[i]; if (sourceSlot >= 0) { int sourceOffset = 0; for (i = 0; i < sourceSlot; i++) if (file_used[i] && i != slot) sourceOffset += file_lengths[i] + 1; if (sourceSlot > slot) sourceOffset += length + 1; - data = (int *)0xf000 + sourceOffset; + data = (int *)WIDE_FILE_BASE + sourceOffset; } - memcpy((int *)0xf000 + targetOffset, data, length); - ((int *)0xf000)[targetOffset + length] = 0; + memcpy((int *)WIDE_FILE_BASE + targetOffset, data, length); + ((int *)WIDE_FILE_BASE)[targetOffset + length] = 0; file_lengths[slot] = length; file_kinds[slot] = kind; } return slot; @@ -150,7 +157,7 @@ void file_list(void) { if (!count) println("No files."); print("Used "); print_dec(count); #ifdef BOBC_WIDE - println("/8 slots; shared 4096-word storage. Text/resident files max 511; native apps use remaining space."); + println("/8 slots; shared 8192-word storage. Text files max 511; native apps use remaining space."); #else println("/8 slots; limit 511 words per file. delete frees a slot."); #endif @@ -167,7 +174,7 @@ void file_manage(char *operation, char *name, char *destination) { for (i = 0; i < FILE_COUNT; i++) if (file_used[i]) { if (i == slot) { sourceOffset += file_lengths[i] + 1; continue; } if (sourceOffset != destinationOffset) - for (j = 0; j <= file_lengths[i]; j++) ((int *)0xf000)[destinationOffset + j] = ((int *)0xf000)[sourceOffset + j]; + for (j = 0; j <= file_lengths[i]; j++) ((int *)WIDE_FILE_BASE)[destinationOffset + j] = ((int *)WIDE_FILE_BASE)[sourceOffset + j]; sourceOffset += file_lengths[i] + 1; destinationOffset += file_lengths[i] + 1; } #endif diff --git a/kernel/input.c b/kernel/input.c index 8857961..1a0f28b 100644 --- a/kernel/input.c +++ b/kernel/input.c @@ -1,10 +1,20 @@ /* Native shell editing; history is stored before command tokenization. */ #define shell_history ((char *)0xe400) +#define SHELL_HISTORY_LIMIT 4 +#define SHELL_HISTORY_ENTRY_SIZE 128 int history_count; int input_length; int input_cursor; int input_echo; +void shell_history_list(void) { + int i; + for (i = 0; i < history_count; i++) { + print_dec(i + 1); print(" "); + println(shell_history + i * SHELL_HISTORY_ENTRY_SIZE); + } +} + void input_redraw(void) { int i; int width; int start; int end; if (!input_echo) return; @@ -45,9 +55,9 @@ void input_complete(void) { if (input_cursor != input_length) return; if (!start) { #ifdef BOBC_WIDE - words = "help echo clear mem halt list ls dir read write edit load run run32 cc go copy rename delete alloc peek poke save restore"; + words = "help echo clear mem halt history list ls dir read write edit load run run32 cc go copy rename delete alloc peek poke save restore"; #else - words = "help echo clear mem halt list ls dir read write edit load run cc go copy rename delete alloc peek poke save restore"; + words = "help echo clear mem halt history list ls dir read write edit load run cc go copy rename delete alloc peek poke save restore"; #endif while (*words) { length = 0; @@ -90,7 +100,8 @@ int shell_read_line(void) { if (key == 256 && browsing) browsing--; if (key == 257 && browsing < history_count) browsing++; if (browsing == history_count) memcpy(command_line, draft, strlen(draft) + 1); - else memcpy(command_line, shell_history + browsing * 128, strlen(shell_history + browsing * 128) + 1); + else memcpy(command_line, shell_history + browsing * SHELL_HISTORY_ENTRY_SIZE, + strlen(shell_history + browsing * SHELL_HISTORY_ENTRY_SIZE) + 1); input_length = strlen(command_line); input_cursor = input_length; } else if (key == 258) { if (input_cursor) input_cursor--; } else if (key == 259) { if (input_cursor < input_length) input_cursor++; } @@ -118,11 +129,12 @@ int shell_read_line(void) { if (truncated) return -1; if (key == -1 && !input_length) return -2; if (input_length && (history_count == 0 || strcmp(command_line, shell_history + (history_count - 1) * 128))) { - if (history_count == 4) { - for (i = 0; i < 384; i++) shell_history[i] = shell_history[i + 128]; - history_count = 3; + if (history_count == SHELL_HISTORY_LIMIT) { + for (i = 0; i < (SHELL_HISTORY_LIMIT - 1) * SHELL_HISTORY_ENTRY_SIZE; i++) + shell_history[i] = shell_history[i + SHELL_HISTORY_ENTRY_SIZE]; + history_count = SHELL_HISTORY_LIMIT - 1; } - memcpy(shell_history + history_count * 128, command_line, input_length + 1); history_count++; + memcpy(shell_history + history_count * SHELL_HISTORY_ENTRY_SIZE, command_line, input_length + 1); history_count++; } return input_length; } diff --git a/kernel/kernel.c b/kernel/kernel.c index 7414ba7..66592c8 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -8,6 +8,9 @@ int main(void) { int length; char *sample; +#ifdef BOBC_WIDE + file_service_register(); +#endif println("bob!"); #ifdef BOBC_WIDE println("bob32 OS: help COMMAND for usage; go bob.c runs the example."); diff --git a/kernel/runtime.h b/kernel/runtime.h index 1678349..0555b6c 100644 --- a/kernel/runtime.h +++ b/kernel/runtime.h @@ -14,10 +14,12 @@ #endif #define WIDE_PROGRAM_BASE 0x20000 #define WIDE_VARIABLE_BASE 0xf0000 +#define WIDE_FILE_BASE 0x1e000 +#define WIDE_FILE_WORDS 8192 #define FILE_COUNT 8 #define TEXT_WORDS 512 #if BOBC_WIDE -#define FILE_WORDS 4096 +#define FILE_WORDS WIDE_FILE_WORDS #else #define FILE_WORDS 512 #endif @@ -28,6 +30,7 @@ int file_find(char *name); int file_prepare_native(char *name); char *file_name(int slot); int *file_content(int slot); +void file_service_register(void); #if BOBC_WIDE void memcpy(void *dst, void *src, int count); void memset(void *dst, int value, int count); diff --git a/kernel/shell.c b/kernel/shell.c index 1f3ae6c..c1e5a04 100644 --- a/kernel/shell.c +++ b/kernel/shell.c @@ -7,6 +7,7 @@ int editor_undo_length; int editor_has_undo; char *arguments; void nano_edit(char *name); +void shell_history_list(void); char *next_arg(void) { char *start; @@ -270,7 +271,7 @@ void memory_status(void) { print("Programs "); print_hex(PROGRAM_BASE); print(".."); print_hex(0xbfff); println(""); #endif #ifdef BOBC_WIDE - println("Files: 8 slots, 4096 words total; text files up to 511 words; native apps share remaining space."); + println("Files: 8 slots, 8192 words total; text files up to 511 words; native apps share remaining space."); #else println("Files: 8 slots, 511 words each; stack above 0xE600."); #endif @@ -309,6 +310,7 @@ void command_help(char *name) { else if (strcmp(name, "alloc") == 0 || strcmp(name, "mem") == 0) println("alloc WORDS: allocate/zero heap words, print start address; no free. Example: alloc 16. mem shows remaining heap and memory regions."); else if (strcmp(name, "echo") == 0) println("echo TEXT: print text. Example: echo bob!"); + else if (strcmp(name, "history") == 0) println("history: list the four most recent nonempty shell commands from this session."); else if (strcmp(name, "clear") == 0) println("clear: clear an ANSI-capable terminal; does not remove files."); else if (strcmp(name, "halt") == 0) println("halt: stop emulator. Unsaved RAM files and allocations are lost; use save before quitting."); else if (strcmp(name, "help") == 0) println("help: list commands. help COMMAND: show usage and an example. Try help edit or help go."); @@ -326,7 +328,7 @@ void SHELL_COMMAND_BODY(char *line) { if (strcmp(command, "help") == 0) { name = next_arg(); if (*name) { command_help(name); return; } - println("help | echo TEXT | clear | mem | halt"); + println("help | echo TEXT | history | clear | mem | halt"); println("peek ADDRESS | poke ADDRESS VALUE | alloc WORDS"); println("list / ls / dir | read NAME | write NAME TEXT | edit NAME"); println("copy OLD NEW | rename OLD NEW | delete NAME (permanent in RAM)"); @@ -396,6 +398,9 @@ void SHELL_COMMAND_BODY(char *line) { *pointer = value; } print_hex(address); print(": "); print_hex(*pointer); print(" ("); print_dec(*pointer); println(")"); + } else if (strcmp(command, "history") == 0) { + if (*next_arg()) println("Usage: history"); + else shell_history_list(); } else println("Unknown command. Type help."); } #ifdef BOBC_WIDE diff --git a/main.c b/main.c index 573a4ed..beebf16 100644 --- a/main.c +++ b/main.c @@ -107,6 +107,7 @@ #include #include +#include #include #include #include @@ -124,6 +125,50 @@ static bool application32; static uint32_t applicationArgc; static uint32_t applicationArgv; static bool applicationEntryArguments; +static bool filesystemRegistered; +static uint32_t filesystemNames; +static uint32_t filesystemLengths; +static uint32_t filesystemKinds; +static uint32_t filesystemUsed; +enum { GRAPHICS_WIDTH=80, GRAPHICS_HEIGHT=25, GRAPHICS_CELLS=GRAPHICS_WIDTH*GRAPHICS_HEIGHT }; +enum { SYSTEM_API_VERSION=1, SYSTEM_DEVICE_CELL_FRAMEBUFFER=1, SYSTEM_INPUT_KEYBOARD=1, SYSTEM_INPUT_MOUSE=2 }; +enum { WIDE_FILE_BASE=0x1e000, WIDE_FILE_WORDS=8192 }; +static unsigned char graphicsCharacters[GRAPHICS_CELLS]; +static unsigned char graphicsColors[GRAPHICS_CELLS]; +static bool graphicsActive; +static int terminalAvailable(void); + +static void graphicsReset(void) { + for(unsigned i=0;i=GRAPHICS_WIDTH || y>=GRAPHICS_HEIGHT)return; + unsigned index=(unsigned)y*GRAPHICS_WIDTH+(unsigned)x; + graphicsCharacters[index]=character?character:' ';graphicsColors[index]=color&15; +} +static void graphicsPresent(void) { + int ansi=terminalAvailable(),lastColor=-1; + if(ansi)printf("\033[2J\033[H"); + for(int y=0;y>16); + if(!delta)return 0; + *type=OS_EVENT_MOUSE_WHEEL;*value=delta; + } + else if(buttons!=*buttonState) { + *type=(buttons&~*buttonState)?OS_EVENT_MOUSE_BUTTON_DOWN:OS_EVENT_MOUSE_BUTTON_UP; + *buttonState=buttons; + } else return 0; + return 1; + } + return 0; +} +static int terminalEvent(int *type,int *value,int *x,int *y) { + fflush(stdout); +#ifdef _WIN32 + if(terminalAvailable()) { + HANDLE input=GetStdHandle(STD_INPUT_HANDLE);DWORD mode,count;INPUT_RECORD record; + if(!GetConsoleMode(input,&mode))return 0; + DWORD originalMode=mode; + mode=(mode&~ENABLE_PROCESSED_INPUT)|ENABLE_MOUSE_INPUT|ENABLE_EXTENDED_FLAGS; + if(!SetConsoleMode(input,mode))return 0; + if(!rawInputStarted){originalInputMode=originalMode;rawInputStarted=true;atexit(restoreInputMode);} + while(ReadConsoleInputA(input,&record,1,&count) && count) { + if(record.EventType==KEY_EVENT) { + KEY_EVENT_RECORD key=record.Event.KeyEvent; + if(terminalEventDecode(1,key.bKeyDown,(unsigned char)key.uChar.AsciiChar, + key.wVirtualKeyCode,0,0,0,&terminalMouseButtons,type,value,x,y))return 1; + } + if(record.EventType==MOUSE_EVENT) { + MOUSE_EVENT_RECORD mouse=record.Event.MouseEvent; + unsigned buttons=mouse.dwButtonState; + int moving=mouse.dwEventFlags==MOUSE_MOVED; + if(terminalEventDecode(2,moving,(int)mouse.dwEventFlags,0, + mouse.dwMousePosition.X,mouse.dwMousePosition.Y,buttons, + &terminalMouseButtons,type,value,x,y))return 1; + } + } + return 0; + } +#endif + int key=getchar();if(key==EOF)return 0;if(key=='\r')key='\n'; + return terminalEventDecode(1,1,key,0,0,0,0,&terminalMouseButtons,type,value,x,y); +} +static int terminalEventPoll(int *type,int *value,int *x,int *y) { +#ifdef _WIN32 + if(terminalAvailable()) { + HANDLE input=GetStdHandle(STD_INPUT_HANDLE);DWORD mode,count;INPUT_RECORD record; + if(!GetConsoleMode(input,&mode))return 0; + DWORD originalMode=mode; + mode=(mode&~ENABLE_PROCESSED_INPUT)|ENABLE_MOUSE_INPUT|ENABLE_EXTENDED_FLAGS; + if(!SetConsoleMode(input,mode))return 0; + if(!rawInputStarted){originalInputMode=originalMode;rawInputStarted=true;atexit(restoreInputMode);} + for(;;) { + if(!PeekConsoleInputA(input,&record,1,&count)||!count)return 0; + if(!ReadConsoleInputA(input,&record,1,&count)||!count)return 0; + if(record.EventType==KEY_EVENT) { + KEY_EVENT_RECORD key=record.Event.KeyEvent; + if(terminalEventDecode(1,key.bKeyDown,(unsigned char)key.uChar.AsciiChar, + key.wVirtualKeyCode,0,0,0,&terminalMouseButtons,type,value,x,y))return 1; + } else if(record.EventType==MOUSE_EVENT) { + MOUSE_EVENT_RECORD mouse=record.Event.MouseEvent; + unsigned buttons=mouse.dwButtonState; + int moving=mouse.dwEventFlags==MOUSE_MOVED; + if(terminalEventDecode(2,moving,(int)mouse.dwEventFlags,0, + mouse.dwMousePosition.X,mouse.dwMousePosition.Y,buttons, + &terminalMouseButtons,type,value,x,y))return 1; + } + } + } +#else + (void)type;(void)value;(void)x;(void)y; +#endif + return 0; +} typedef uint32_t ureg_t; typedef uint16_t instruction_t; @@ -314,14 +454,310 @@ static void memoryReset(void) { memset(sparseMemory,0,sizeof(sparseMemory)); } +typedef struct {uint32_t number;int32_t *words;} SavedSparsePage; +static SavedSparsePage *sparseMemorySave(unsigned *count) { + unsigned used=0,out=0; + for(unsigned i=0;i=0x20&&sparseMemory[i].number<0x100)used++; + *count=used; + SavedSparsePage *saved=used?calloc(used,sizeof(*saved)):NULL; + if(used&&!saved)return NULL; + for(unsigned i=0;i=0x20&&sparseMemory[i].number<0x100) { + saved[out].number=sparseMemory[i].number; + saved[out].words=malloc(MEMORY_PAGE_WORDS*sizeof(int32_t)); + if(!saved[out].words) { + for(unsigned j=0;j=0x20&&sparseMemory[i].number<0x100) { + free(sparseMemory[i].words);sparseMemory[i].used=0;sparseMemory[i].words=NULL; + } + for(unsigned i=0;i0xf000-4))return -1; + if(programMode && (request<0x20000 || request>0xffff9))return -1; + uint32_t op=(uint32_t)memoryRead(request); + if(!programMode) { + if(op!=0 || !cpu32)return -1; + filesystemNames=(uint32_t)memoryRead(request+1); + filesystemLengths=(uint32_t)memoryRead(request+2); + filesystemKinds=(uint32_t)memoryRead(request+3); + filesystemUsed=(uint32_t)memoryRead(request+4); + uint64_t imageEnd=(uint64_t)bootOrigin+bootWords; + if(imageEnd>WIDE_FILE_BASE)return -1; + if(filesystemNamesimageEnd || + filesystemLengthsimageEnd || + filesystemKindsimageEnd || + filesystemUsedimageEnd)return -1; + filesystemRegistered=true;return 0; + } + if(!application32 || !filesystemRegistered)return -1; + if((op>>16)!=1)return -4; + op&=0xffffu; + uint32_t a=(uint32_t)memoryRead(request+1),b=(uint32_t)memoryRead(request+2),c=(uint32_t)memoryRead(request+3),d=(uint32_t)memoryRead(request+4); + uint32_t e=(uint32_t)memoryRead(request+5),f=(uint32_t)memoryRead(request+6); +#define APP_RANGE(p,n) ((p)>=0x20000u && (uint64_t)(p)+(uint64_t)(n)<=0x100000u) + char name[24];unsigned nameLength=0; + if((op>=2 && op<=4) || op==8 || op==9 || op==10) { + if(!APP_RANGE(a,1))return -1; + while(nameLength126)return -1; + name[nameLength++]=(char)ch; + } + if(!nameLength || nameLength==sizeof(name)-1 || nameLength>=24 || (uint32_t)memoryRead(a+nameLength)!=0)return -1; + name[nameLength]=0; + } + int slot=-1; + if((op>=2 && op<=4) || op==8 || op==9 || op==10)for(int i=0;i<8;i++) { + if(!memoryRead(filesystemUsed+i))continue; + unsigned j=0;while(j<23 && (uint32_t)memoryRead(filesystemNames+i*24+j)==(unsigned char)name[j] && name[j])j++; + if(j==nameLength && !name[j]){slot=i;break;} + } + if(op==1) { + uint32_t index=a,buffer=b,capacity=c,lengthAddress=d; + if(index>=8)return 0; + if(!APP_RANGE(buffer,capacity) || !capacity || !APP_RANGE(lengthAddress,1))return -1; + if(!memoryRead(filesystemUsed+index))return 0; + unsigned n=0;while(n<23 && memoryRead(filesystemNames+index*24+n))n++; + if(capacity<=n)return -2; + for(unsigned i=0;i2)) || + (!kind && length>=512) || !APP_RANGE(buffer,length))return -1; + if(slot<0)for(int i=0;i<8;i++)if(!memoryRead(filesystemUsed+i)){slot=i;break;} + if(slot<0)return -1; + uint32_t total=length+1; + for(int i=0;i<8;i++)if(i!=slot && memoryRead(filesystemUsed+i))total+=(uint32_t)memoryRead(filesystemLengths+i)+1; + if(total>WIDE_FILE_WORDS)return -1; + if(!kind)for(uint32_t i=0;i255)return -1;} + int32_t packed[WIDE_FILE_WORDS];uint32_t out=0;int newLengths[8],newKinds[8],newUsed[8];char newNames[8][24]; + for(int i=0;i<8;i++) { + newUsed[i]=i==slot?1:(int)memoryRead(filesystemUsed+i); + if(!newUsed[i]){newLengths[i]=0;newKinds[i]=0;memset(newNames[i],0,24);continue;} + uint32_t oldName=filesystemNames+i*24;for(int j=0;j<24;j++)newNames[i][j]=(char)memoryRead(oldName+j); + if(i==slot){for(int j=0;j<24;j++)newNames[i][j]=j<(int)nameLength?name[j]:0;newLengths[i]=(int)length;newKinds[i]=(int)kind; + for(uint32_t j=0;j126)return -1; + name[nameLength++]=(char)ch; + } + if(!nameLength||nameLength>=sizeof(name)-1||!APP_RANGE(nameAddress+nameLength,1)||memoryRead(nameAddress+nameLength))return -1; + name[nameLength]=0; + if(argumentAddress) { + while(argumentLength255)return -1; + arguments[argumentLength++]=(char)ch; + if(!ch)break; + } + if(!argumentLength||arguments[argumentLength-1])return -1; + } else arguments[argumentLength++]=0; + for(int i=0;i<8;i++)if(memoryRead(filesystemUsed+i)) { + unsigned j=0;while(j<23&&(uint32_t)memoryRead(filesystemNames+i*24+j)==(unsigned char)name[j]&&name[j])j++; + if(j==nameLength&&!name[j]){target=i;break;} + } + if(target<0)return -1; + kind=(int)memoryRead(filesystemKinds+target); + if(kind!=3)return -2; + for(int i=0;i>32)); + return 2; + } + if(op==16) { graphicsReset();graphicsActive=true;return 0; } + if(op==17) { + if(!graphicsActive || !APP_RANGE(a,b) || b<2)return -1; + memoryWrite(a,GRAPHICS_WIDTH);memoryWrite(a+1,GRAPHICS_HEIGHT);return 2; + } + if(op==18) { + if(!graphicsActive || (int32_t)a<0 || (int32_t)b<0 || a>=GRAPHICS_WIDTH || b>=GRAPHICS_HEIGHT || c>255 || d>15)return -1; + graphicsPixel((int)a,(int)b,(unsigned char)c,(unsigned char)d);return 0; + } + if(op==19) { + int x=(int32_t)a,y=(int32_t)b,w=(int32_t)c,h=(int32_t)d; + if(!graphicsActive || w<=0 || h<=0 || w>GRAPHICS_WIDTH*2 || h>GRAPHICS_HEIGHT*2 || e>255 || f>15)return -1; + int64_t endX=(int64_t)x+w,endY=(int64_t)y+h; + int startX=x<0?0:x,startY=y<0?0:y; + int clippedX=endX>GRAPHICS_WIDTH?GRAPHICS_WIDTH:(int)endX; + int clippedY=endY>GRAPHICS_HEIGHT?GRAPHICS_HEIGHT:(int)endY; + for(int py=startY;py=GRAPHICS_WIDTH || x1<0 || x1>=GRAPHICS_WIDTH || y0<0 || y0>=GRAPHICS_HEIGHT || y1<0 || y1>=GRAPHICS_HEIGHT || e>255 || f>15)return -1; + int dx=abs(x1-x0),sx=x0=dy){error+=dy;x0+=sx;}if(twice<=dx){error+=dx;y0+=sy;}} + return 0; + } + if(op==21) { + int x=(int32_t)a,y=(int32_t)b,startX=x;uint32_t text=c,color=d; + if(!graphicsActive || (int32_t)x<0 || x>=GRAPHICS_WIDTH || y<0 || y>=GRAPHICS_HEIGHT || !APP_RANGE(text,1) || color>15)return -1; + for(unsigned i=0;i=GRAPHICS_HEIGHT)break;continue;} + graphicsPixel(x++,y,(unsigned char)(ch<=255?ch:'?'),(unsigned char)color); + if(x>=GRAPHICS_WIDTH)break; + } + return 0; + } + if(op==22) { + int x=(int32_t)a,y=(int32_t)b,w=(int32_t)c,h=(int32_t)d;uint32_t bitmap=e,color=f; + if(!graphicsActive || x<0 || y<0 || x>=GRAPHICS_WIDTH || y>=GRAPHICS_HEIGHT || w<=0 || h<=0 || w>GRAPHICS_WIDTH-x || h>GRAPHICS_HEIGHT-y || (uint64_t)w*h>GRAPHICS_CELLS || !APP_RANGE(bitmap,(uint64_t)w*h) || color>15)return -1; + for(int py=0;py255)return -1; + if(ch)graphicsPixel(x+px,y+py,(unsigned char)ch,(unsigned char)color); + } + return 0; + } + if(op==27) { + int x=(int32_t)a,y=(int32_t)b,w=(int32_t)c,h=(int32_t)d;uint32_t bitmap=e; + if(!graphicsActive || x<0 || y<0 || x>=GRAPHICS_WIDTH || y>=GRAPHICS_HEIGHT || w<=0 || h<=0 || w>GRAPHICS_WIDTH-x || h>GRAPHICS_HEIGHT-y || (uint64_t)w*h>GRAPHICS_CELLS || !APP_RANGE(bitmap,(uint64_t)w*h))return -1; + for(int i=0;i0xfffu)return -1; + for(int py=0;py>8)&15u; + if(ch)graphicsPixel(x+px,y+py,(unsigned char)ch,(unsigned char)color); + } + return 0; + } + if(op==23) { + if(!graphicsActive || a>255 || b>15)return -1; + for(unsigned i=0;i= 0xf0000) : (entry < legacyBase || entry >= legacyEnd))) return -1; + if (programDepth>=8 || (application32 ? (entry < 0x20000 || entry >= 0xf0000) : (entry < legacyBase || entry >= legacyEnd))) return -1; struct cpu_t saved = cpu; ureg_t savedMar = ram.mar; reg_t savedMdr = ram.mdr; @@ -330,7 +766,8 @@ static int runProgram(uint32_t entry) { programMode = true; programDone = false; bool savedApplicationEntryArguments=applicationEntryArguments; - if (setjmp(programFault) == 0) { + unsigned frame=programDepth++; + if (setjmp(programFaultStack[frame]) == 0) { if(!application32)cpu32=false; cpu.pc = addressValue(entry); cpu.regFile[6] = wordValue(application32?0x100000u:(savedCpu32?0xd000u:0xc000u)); @@ -345,7 +782,9 @@ static int runProgram(uint32_t entry) { } status = cycles == 5000000 ? -3 : (int32_t)(uint32_t)cpu.regFile[0]; } - programMode = false; + programDepth--; + programMode = savedProgramMode; + if(application32 && graphicsActive)graphicsClose(); if(savedCpu32 && !application32 && bootWideHeader) { uint64_t imageEnd=(uint64_t)bootOrigin+bootWords; uint32_t restoreStart=bootOrigin>legacyBase?bootOrigin:legacyBase; @@ -355,13 +794,14 @@ static int runProgram(uint32_t entry) { cpu32=savedCpu32; legacyProgram32=savedLegacyProgram32; applicationEntryArguments=savedApplicationEntryArguments; + programDone=savedProgramDone; cpu = saved; ram.mar = savedMar; ram.mdr = savedMdr; return status; } static int runWideImageFromGuest(uint32_t pathAddress); -static int runWidePackedFromGuest(uint32_t descriptor); +static int runWidePackedFromGuest(uint32_t descriptor,int *started); static int importWideImageFromGuest(uint32_t descriptor); int sext(int16_t val, uint16_t length) { @@ -643,13 +1083,17 @@ void execute() { else cpu.regFile[0]=wordValue((uint32_t)runWideImageFromGuest((uint32_t)cpu.regFile[0])); break; case 13: - if(programMode || !cpu32)cpu.regFile[0]=-4; - else cpu.regFile[0]=wordValue((uint32_t)runWidePackedFromGuest((uint32_t)cpu.regFile[0])); + if(!cpu32)cpu.regFile[0]=-4; + else cpu.regFile[0]=wordValue((uint32_t)runWidePackedFromGuest((uint32_t)cpu.regFile[0],NULL)); break; case 14: if(programMode || !cpu32)cpu.regFile[0]=-4; else cpu.regFile[0]=wordValue((uint32_t)importWideImageFromGuest((uint32_t)cpu.regFile[0])); break; + case 15: + if(!cpu32)cpu.regFile[0]=-4; + else cpu.regFile[0]=wordValue((uint32_t)filesystemService((uint32_t)cpu.regFile[0])); + break; default: machineFault(); } @@ -1312,6 +1756,8 @@ static int assembleSource(FILE *file) { } static void bootImage(const char *path) { + filesystemRegistered=false; + graphicsActive=false;graphicsReset(); FILE *file = fopen(path, "rb"); if (!file) { perror(path); exit(1); } char magic[4]; @@ -1393,11 +1839,13 @@ static int prepareApplicationArguments(const char *programName,const char *text) storage[write++]=storage[scan++]; } if(quote)return -4; - storage[write]=0;scan++; + int separated=storage[scan]!=0; + storage[write]=0;if(separated)scan++; } for(unsigned i=0;i0xf000-4)return -4; uint32_t address=(uint32_t)memoryRead(descriptor),length=(uint32_t)memoryRead(descriptor+1); uint32_t argumentAddress=(uint32_t)memoryRead(descriptor+2); @@ -1497,7 +1946,9 @@ static int runWidePackedFromGuest(uint32_t descriptor) { } if(!i || programNameBuffer[i-1])return -4; } else programNameBuffer[0]=0; - if(address<0xf000 || address>=0x10000 || !length || length>4096 || address+length>0x10000)return -4; + int oldStorage=address>=0xf000&&address<0x10000&&length<=4096&&address+length<=0x10000; + int wideStorage=address>=WIDE_FILE_BASE&&address0xf000-3)return -4; uint32_t pathAddress=(uint32_t)memoryRead(descriptor),destination=(uint32_t)memoryRead(descriptor+1),capacity=(uint32_t)memoryRead(descriptor+2); if(pathAddress<0x100 || pathAddress>=0xf000)return -4; - if(destination<0xf000 || destination>=0x10000 || capacity>0x10000-destination || capacity<7)return -4; + int oldStorage=destination>=0xf000&&destination<0x10000&&capacity<=0x10000-destination; + int wideStorage=destination>=WIDE_FILE_BASE&&destination255)return -4;path[pathLength++]=(char)c;} if(!pathLength || pathLength==sizeof(path)-1)return -4; diff --git a/storage.c b/storage.c index f5f19ee..22a89d6 100644 --- a/storage.c +++ b/storage.c @@ -1,65 +1,69 @@ /* Included by main.c after ram is defined. Durable file device; guest owns shell. */ -enum { SNAP_WORDS = 4312 }; +enum { SNAP_WORDS=4312, SNAP_WIDE_WORDS=8408, SNAP_META_WORDS=216, + SNAP_OLD_FILE_WORDS=4096, SNAP_FILE_WORDS=8192 }; static uint32_t kernelIdentity; -static uint32_t snapshotHash(const uint32_t *words, unsigned count) { +static uint32_t snapshotHash(const uint32_t *words,unsigned count) { uint32_t hash=2166136261u; for(unsigned i=0;i>8)&255))*16777619u; - if(cpu32) { hash=(hash^((words[i]>>16)&255))*16777619u; hash=(hash^(words[i]>>24))*16777619u; } + if(cpu32) {hash=(hash^((words[i]>>16)&255))*16777619u;hash=(hash^(words[i]>>24))*16777619u;} } return hash; } -static int snapshotValidFormat(const uint32_t *words, int packed) { - unsigned packedOffset=0; +/* Layout 0: fixed 512-word slots; 1: packed 4096-word B32S v2; 2: packed v3. */ +static int snapshotValidFormat(const uint32_t *words,int layout) { + unsigned capacity=layout==2?SNAP_FILE_WORDS:SNAP_OLD_FILE_WORDS; + unsigned packedOffset=0;int packed=layout!=0; for(unsigned i=0;i<8;i++) { unsigned length=words[192+i],kind=words[200+i],used=words[208+i]; - if(used>1 || kind>(cpu32?(packed?3u:2u):1u) || length>=(packed?4096u:512u))return 0; + if(used>1 || kind>(cpu32?(packed?3u:2u):1u) || length>=(packed?capacity:512u))return 0; if(!used)continue; const uint32_t *name=words+i*24;unsigned n=0; - while(n<24 && name[n]) {if(name[n]<33 || name[n]>126)return 0;n++;} + while(n<24&&name[n]) {if(name[n]<33||name[n]>126)return 0;n++;} unsigned contentOffset=packed?packedOffset:i*512; - if(!n || n==24 || words[216+contentOffset+length])return 0; - if(!kind)for(unsigned k=0;k255)return 0; + if(!n||n==24||contentOffset+length>=capacity||words[SNAP_META_WORDS+contentOffset+length])return 0; + if(!kind)for(unsigned k=0;k255)return 0; if(packed)packedOffset+=length+1; for(unsigned j=0;j4096)return 0; - return 1; + return !packed||packedOffset<=capacity; } -static int snapshotValid(const uint32_t *words) { return snapshotValidFormat(words,cpu32); } -static int snapshotService(unsigned descriptor, int operation) { - if(programMode || descriptor<0x300 || descriptor>0xf000-4)return -3; +static int snapshotValid(const uint32_t *words) { return snapshotValidFormat(words,2); } +static int snapshotService(unsigned descriptor,int operation) { + if(programMode||descriptor<0x300||descriptor>0xf000-4)return -3; unsigned addresses[4],sizes[4]={192,8,8,8}; for(unsigned i=0;i<4;i++) { addresses[i]=cpu32?(uint32_t)memoryRead(descriptor+i):(uint16_t)ram.memory[descriptor+i]; uint64_t end=(uint64_t)addresses[i]+sizes[i]; - int lowArray=addresses[i]>=0x300 && end<=(cpu32?0xc000u:0xa000u); + int lowArray=addresses[i]>=0x300&&end<=(cpu32?0xc000u:0xa000u); uint32_t kernelStart=bootMode?bootOrigin:(assembledWide?assembledOrigin:0); uint64_t kernelEnd=bootMode?(uint64_t)bootOrigin+bootWords:(assembledWide?(uint64_t)assembledOrigin+assembledWords:0); - int kernelArray=cpu32 && addresses[i]>=kernelStart && end<=kernelEnd; - if(!lowArray && !kernelArray)return -3; - for(unsigned j=0;j=kernelStart&&end<=kernelEnd; + if(!lowArray&&!kernelArray)return -3; + for(unsigned j=0;j>(8*i));header[12+i]=(unsigned char)(hash>>(8*i));} int okay=fwrite(header,1,16,file)==16; - for(unsigned i=0;i>(8*b))&255,file)==EOF)okay=0; + for(unsigned i=0;i>(8*b))&255,file)==EOF)okay=0; if(fclose(file))okay=0; if(okay) { #ifdef _WIN32 @@ -73,36 +77,42 @@ static int snapshotService(unsigned descriptor, int operation) { } if(operation!=1)return -3; FILE *file=fopen(path,"rb");if(!file)return -1; - unsigned char header[16];int valid=fread(header,1,16,file)==16; - for(unsigned i=0;i` with width-matched `size_t`/`ptrdiff_t` and `NULL`. `sizeof` Host C now supports typed function-pointer declarations and calls, including local/file-scope pointers, nested pointer parameters, function-address relocations, copying, and parenthesized indirect calls. Empty `()` signatures accept unspecified call arguments; typed signatures enforce argument count and compatibility. B16/B32 positive and negative regressions cover these behaviors, including invalid casts between function and object pointers. Full suite: CPU 194, OS/compiler 1,793, console 28. Native bob32 application workflow: the RAM filesystem packs eight file slots into 4,096 words, allowing validated B32K v2 images larger than 511 words. `import32 HOST_PATH NAME` stores an image, `run NAME` or `run32 NAME` executes it from guest RAM, and B32S v2 snapshots preserve it; B32S v1 fixed-slot snapshots convert on restore. Integration tests import a 629-word image, execute it through both guest-name commands, save/restore, and execute again. Failure coverage checks missing, invalid and truncated images, storage-capacity exhaustion, checksum corruption and sparse-memory allocation failure. The expanded bob32 kernel now runs at `0x10000..0x1D115`, with native applications starting at `0x20000`. Resident compiler diagnostics include token context with the existing source location. Full suite: CPU 203, OS/compiler 1,813, console 28. + +Native apps now access the bob32 RAM filesystem through version 1 of the `bob_fs.h` service API: list files and metadata, read/write text, delete, and query basic system information. Apps `echo`, `ls`, `cat`, `sysinfo`, and `notes` compile as B32K images and run in the emulator; the notes integration creates a file, snapshots it, restores in a second process, reads it, and deletes it. Argument parsing preserves empty arguments and stops at the input terminator. Full suite: CPU 203, OS/compiler 1,874, console 28. + +Added a version 1 `bob_gfx.h` cell-framebuffer API with resolution queries, colors, pixels, filled rectangles, lines, text, transparent bitmap-cell blitting, clearing, presentation and clean exit. The 80x25 terminal backend is decoupled from drawing calls. `bob_event.h` adds blocking four-word character/special-key events, with release/mouse types reserved. `apps/graphics_demo.c` draws the canvas, waits for a test key event, exits graphics mode and prints `bob!`. Full suite: CPU 203, OS/compiler 1,880, console 28. + +Added a reusable `bob_gui.h` window-frame helper and `apps/gui_demo.c`, a small two-window desktop prototype with title bars, active-window focus colors, Tab focus switching, Backspace editing, and character routing to the focused window. The Windows console event backend now reports key-up, mouse movement, and button transitions in addition to key-down/character events; the GUI draws a `+` cursor and mouse clicks select a window. Redirected input remains character based. Escape exits graphics mode and returns to the shell with `bob!`. End-to-end tests cover rendering, keyboard focus/routing, and clean return. Full suite: CPU 203, OS/compiler 1,888, console 28. + +Extracted host input record decoding into a deterministic helper and added CPU tests for character presses/releases, normalized arrow keys, mouse coordinates, button press/release, and duplicate button-state filtering. Full suite: CPU 210, OS/compiler 1,888, console 28. + +Added reusable GUI rectangle hit-testing and title-bar drag helpers with screen-edge clamping. The desktop prototype now supports mouse dragging while retaining click focus and keyboard focus. Window frames and title strips are visually distinct. A native bob32 fixture tests hit bounds, drag offsets, movement, clamping and drag release. Full suite: CPU 210, OS/compiler 1,892, console 28. + +Added reusable GUI button draw and event helpers with hover, pressed, and left-click activation states; labels clip to the button interior. The desktop demo includes an “Open Window B” button that moves keyboard focus. Native bob32 tests cover hover, left press, inside-release activation, and release outside without activation. Full suite: CPU 210, OS/compiler 1,892, console 28. + +Added a reusable single-line GUI text field with mouse caret placement, insertion, Backspace/Delete, Left/Right/Home/End, visible caret drawing, and horizontal scrolling. The demo now includes an editable field; the native bob32 fixture checks insertion, navigation, deletion, blur, and scroll offset. Full suite: CPU 210, OS/compiler 1,892, console 28. + +Added reusable z-order operations for packed window rectangles: topmost hit-testing and raising a clicked window. The GUI demo draws bottom-to-top and sends pointer/widget events only to the visible top window, so overlapping windows have consistent focus and control behavior. Native bob32 fixture checks overlap selection, order changes, invalid IDs, and outside hits. Full suite: CPU 210, OS/compiler 1,892, console 28. + +Connected the GUI demo's second window to `bob_fs.h`: it lists guest files, allows mouse or n/p row selection, and previews the selected text file. The emulator integration test creates `gui.txt` with a unique preview marker, selects it with the keyboard, verifies that exact content is rendered, and checks clean exit. Full suite: CPU 210, OS/compiler 1,894, console 28. + +Added line-aware scrolling to the file preview using Up/Down and u/d, with scroll reset on file selection. The GUI integration test creates a long text file whose unique marker begins beyond the initial six preview rows, navigates to it, scrolls down, and verifies the marker is rendered. Full suite: CPU 210, OS/compiler 1,896, console 28. + +Added an on-screen Yes/Cancel confirmation panel for text-file deletion, with mouse buttons and keyboard y/n support. Deletion is restricted to text files. The GUI clears stale preview/selection state after filesystem changes. Integration tests verify cancellation preserves the file, confirmation deletes it, and guest `cat` cannot read it afterward. Full suite: CPU 210, OS/compiler 1,902, console 28. + +Expanded the GUI editor window with filename and text fields, a Save button, and Ctrl+S; Tab cycles through filename, text, and browser focus without stealing normal typed characters. Saved text files appear in the browser. Integration tests save `new.txt` from the GUI, save the filesystem snapshot, restore in a fresh emulator process, and read the file with `cat`. Full suite: OS/compiler 1,907 checks. + +Added version 1 process service operation 6 and `bob_process.h` for launching stored kind-3 native apps with quoted arguments. Nested apps run in the shared address range while the emulator snapshots/restores the suspended app's sparse memory, CPU state, arguments, and graphics buffer; nesting is bounded at eight frames. Added a native launcher that lists apps and passes arguments. Integration launches `echo` through `launcher`, verifies its quoted argument and child exit status, snapshots both apps, restores them in a new process, and launches the child again. Full build: CPU 210, OS/compiler 1,920, console 28. + +Expanded the protected bob32 packed filesystem from 4,096 to 8,192 words at `0x1E000..0x1FFFF`, preserving the 0x20000 native-app boundary. B32S v3 stores the larger payload; v1 fixed-slot and v2 packed snapshots remain readable, and bob16 B16S layout is unchanged. Native launch regression imports launcher, echo, and notes with the starter source, runs notes as a child to create a file, then restores the apps and data in a new process. Full build: CPU 211, OS/compiler 1,926, console 28. + +Added `bob_memory.h`, a caller-owned word arena that fits bobcc's current C subset. Apps allocate contiguous ranges from their own integer buffer, check used/remaining words, and reset for reuse; invalid and exhausted requests return null, without reserving global OS memory. A compiled native app checks bounds, writes through returned pointers, verifies exhaustion, resets, and reallocates. Full build: CPU 211, OS/compiler 1,930, console 28. + +Added version 1 OS time operation 7 and `bob_time.h`. Native apps can query UTC seconds since the Unix epoch as low/high 32-bit words, with request-range and capacity validation in the emulator. A compiled and imported native app verifies a plausible current timestamp through the service. Full build: CPU 211, OS/compiler 1,934, console 28. + +Extended the native filesystem API with word-preserving binary reads/writes for bob16 and bob32 program kinds. The emulator rejects other write kinds, validates app buffers and sizes, and keeps native B32K app storage behind the existing validated import flow. API request wrappers now provide all seven initialized service words. A native app writes signed/high-bit words, verifies kind/size and short-buffer errors, saves a B32S snapshot, restores in a fresh process, reads the same words, and deletes the file. Full build: CPU 211, OS/compiler 1,942, console 28. + +Added `bob_gfx_blit_color` for transparent cell bitmaps with per-cell 16-color foregrounds. Cell values encode an ASCII glyph and color; invalid values reject the request before drawing. A compiled native app verifies rejection, renders a multicolor bitmap through the emulator, checks visible output, and returns to the shell. Full build: CPU 211, OS/compiler 1,948, console 28. + +Added an application-launcher panel to `gui_demo`: it lists stored kind-3 apps, supports keyboard and mouse selection, runs the chosen app through `bob_process.h`, then redraws the desktop with the child's exit code. Integration test drives the GUI with Tab, opens the launcher, starts a stored child returning 7, verifies its output/status, and exits cleanly. Full build: CPU 211, OS/compiler 1,955, console 28. + +Added `bob_native.h` as an opt-in umbrella for common native APIs: core calls, strings, caller-managed memory, files, processes, time, and events. Graphics/GUI remain separate includes to keep those optional. A native bobcc fixture includes only the umbrella, exercises strings, arena allocation, text filesystem operations and UTC time, then runs inside bob32. Full build: CPU 211, OS/compiler 1,959, console 28. + +Extended `notes` with an explicit `edit` replacement command and `add` line-append workflow, length checks, and protection against treating binary/program files as notes. Added `bob_file_kind(name)` to the native filesystem API so apps can query file metadata without scanning every slot. Removed the notes app's duplicate general-purpose string-library dependency; `launcher`, `echo`, `notes`, and the starter source still fit together in the 8,192-word filesystem. Integration edits and appends a note, saves/restores B32S in a fresh process, verifies the content, and confirms `notes` refuses to delete its own executable. Full build: CPU 211, OS/compiler 1,960, console 28. + +Added an opt-in `bob_font.h` 5x7 bitmap font renderer. `bob_gfx_bitmap_text` maps lowercase to uppercase, supports A-Z, digits, space and common punctuation, substitutes `?` for unsupported characters, and rasterizes glyphs as per-color canvas pixels. A native app renders `BOB!`; integration checks its exact raster row and clean return to the shell. Full build: CPU 211, OS/compiler 1,965, console 28. + +Added version 1 event operation 28 and `bob_event_poll`, which peeks Windows console records without blocking and decodes the same key/mouse events as `bob_event_wait`. Empty/redirected input returns 0 and leaves redirected characters available to the blocking API. A native app polls, then waits for the next redirected key and verifies its event type/value. Full build: CPU 211, OS/compiler 1,969, console 28. + +Integrated the 5x7 bitmap font in `gui_demo` through a keyboard/mouse help overlay. Press `?` to view a large bitmap `HELP` heading and shortcuts; Escape or Close returns to the desktop. Modal overlays clear the canvas behind them while retaining the status row. Native UI integration checks the rendered glyph row and close behavior. Full build: CPU 211, OS/compiler 1,973, console 28. + +Expanded `bob_gui.h` with a reusable multiline text area that supports caret placement, insertion, deletion, Home/End and arrow movement, vertical scrolling, and horizontal scrolling for long lines. The GUI editor now loads a selected text file with `e` and saves it with Ctrl+S; the text area handles up to 511 characters. Native widget tests cover newline editing and cursor movement, while an end-to-end test edits a two-line file and verifies the saved newline/content through `cat`. Full build: CPU 211, OS/compiler 1,980, console 28. + +Extended event version 1 with signed Windows mouse-wheel deltas. The GUI file browser uses wheel direction to change selection over the file list or scroll the selected preview over its text; synthetic event-decoder checks cover upward and downward deltas. Full build: CPU 213, OS/compiler 1,980, console 28. + +The reusable multiline text area now responds to wheel events over its bounds, moving the viewport while leaving the byte cursor in place. The GUI routes wheel input to the editor when that window is frontmost, and widget checks verify scrolling at both content boundaries. The full suite remains green: CPU 213, OS/compiler 1,980, console 28. + +Added reusable popup-menu drawing and event helpers with fixed-stride labels, keyboard up/down selection, Enter activation, Escape close, and mouse hover/click behavior. Window B opens the File menu with `m` or from its title area; actions open the selected text file, start delete confirmation, or close the menu. Corrected the bare bob32 guest test helper to execute under `kernel32.b32`, so success-marker assertions now verify actual OS-launched apps rather than a kernel boot lacking OS services. Added screen-clamped popup placement and anchor it to Window B so it follows dragging. Full build: CPU 213, OS/compiler 1,991, console 28. + +Added a `history` shell builtin to print recent commands with their session order. Up/Down browsing still retains four entries in the explicitly reserved history region; tests cover listing, invalid arguments and interactive recall. Raised the long bob32 shell workflow's execution budget to 60 million cycles after the expanded kernel path exceeded its previous 50-million ceiling. Full build: CPU 213, OS/compiler 1,996, console 28. + +Added `bob_event_queue.h`, an optional caller-owned FIFO for version-1 input events. Tests verify empty/full behavior, FIFO ordering, wraparound after popping and pushing, and invalid capacity; the shared `bob_native.h` umbrella includes it. Full build: CPU 213, OS/compiler 1,996, console 28. + +Adjusted native `cat` to preserve a file's existing trailing newline instead of adding an extra blank line, while still separating nonempty unterminated file content from the shell exit status. End-to-end tests cover trailing-newline and empty files. Full build: CPU 213, OS/compiler 2,000, console 28. + +Added the version 1 `bob_system.h` capability query for the cell framebuffer dimensions and keyboard/mouse availability. `sysinfo` now reports these capabilities along with memory and filesystem usage on readable, single-line entries; its integration test checks the reported API version, framebuffer, dimensions and keyboard. Full build: CPU 213, OS/compiler 1,985, console 28. + +Added `bob_wm.h` as a reusable bob32 window manager for fixed-capacity window lifecycle, focus, stacking, hit testing, clamped title-bar dragging, input routing, and dirty redraw ordering. The GUI demo now uses manager IDs for its editor and file browser, redraws dirty windows in stack order, and no longer tracks focus, stacking, or drag state itself. Synthetic manager tests cover overlap, background-window focusing, local coordinates, edge drags, redraw order, hide/destroy, and slot reuse. The GUI integration fixture still checks preview scrolling, delete cancellation/confirmation, and save behavior. Verified separately against fresh emulator builds: CPU 213, OS/compiler 2,000, native console 28. diff --git a/tests/test_bob64.c b/tests/test_bob64.c new file mode 100644 index 0000000..647aae1 --- /dev/null +++ b/tests/test_bob64.c @@ -0,0 +1,2676 @@ +#include "../bob64/types.h" +#include "../bob64/memory.h" +#include "../bob64/paging.h" +#include "../bob64/cpu.h" +#include "../bob64/descriptors.h" +#include "../bob64/interrupts.h" +#include "../bob64/bootstrap.h" +#include "../bob64/console.h" +#include "../bob64/heap.h" +#include "../bob64/keyboard.h" +#include "../bob64/mouse.h" +#include "../bob64/window.h" +#include "../bob64/window_server.h" +#include "../bob64/editor.h" +#include "../bob64/shell.h" +#include "../bob64/exec.h" +#include "../bob64/process.h" +#include "../bob64/syscall.h" +#include "../bob64/app.h" +#include "../bob64/libc.h" +#include "../bob64/compiler.h" +#include +#include +#include +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#else +#include +#include +#endif + +typedef struct { + _Alignas(16) u8 Bytes[4*4096]; + usize PagesUsed; +} HEAP_TEST_ARENA; + +static int heap_test_grow(void *context,void **region,usize *region_size); + +#define CHECK(expression,message) do { if(!(expression)){fprintf(stderr,"bob64 check failed: %s\n",message);return 1;} } while(0) + +typedef struct { + u64 Base; + usize Used; + usize Capacity; + u64 Entries[128][512]; +} TEST_PAGE_TABLES; + +static TEST_PAGE_TABLES test_clone_tables={0x100000000ULL,0,128,{{0}}}; +static u32 read32(const u8 *bytes); +static u64 read64(const u8 *bytes); +static int contains_bytes(const u8 *bytes,usize length,const char *needle, + usize needle_length); +static u8 resident_compiler_image[BOB64_COMPILER_IMAGE_LIMIT]; +static usize resident_compiler_image_length; + +static int execute_compiled_main(const BOB64_EXEC_IMAGE *image,s64 *result) { + typedef s64 (BOB64_MS_ABI *GENERATED_MAIN)(void); + void *memory; + if(!image||!result||image->CodeSize<64||image->FileSize>image->MemorySize)return -1; +#ifdef _WIN32 + memory=VirtualAlloc(0,(SIZE_T)image->MemorySize,MEM_RESERVE|MEM_COMMIT, + PAGE_EXECUTE_READWRITE); + if(!memory)return -1; +#else + memory=mmap(0,(usize)image->MemorySize,PROT_READ|PROT_WRITE|PROT_EXEC, + MAP_PRIVATE|MAP_ANONYMOUS,-1,0); + if(memory==MAP_FAILED)return -1; +#endif + memcpy(memory,image->Image,(usize)image->FileSize); + GENERATED_MAIN main_function=(GENERATED_MAIN)((u8 *)memory+32); + *result=main_function(); +#ifdef _WIN32 + VirtualFree(memory,0,MEM_RELEASE); +#else + munmap(memory,(usize)image->MemorySize); +#endif + return 0; +} + +static int libc_tests(void) { + char source[]="bob64!",copy[16],overlap[12]="0123456789"; + static const char expected[]="0101234567"; + u8 fill[4]; + CHECK(bob64_memcpy(copy,source,sizeof(source))==copy&& + bob64_memcmp(copy,source,sizeof(source))==0, + "copy and compare native application memory"); + CHECK(bob64_memmove(overlap+2,overlap,8)==overlap+2&& + bob64_memcmp(overlap,expected,10)==0, + "move overlapping ranges in either address direction"); + CHECK(bob64_memset(fill,0xa5,sizeof(fill))==fill&&fill[0]==0xa5&& + fill[3]==0xa5&&bob64_memcmp(fill,fill,sizeof(fill))==0, + "fill memory with an 8-bit value"); + CHECK(bob64_strlen(source)==6&&bob64_strlen("")==0&& + bob64_strcmp("bob64!","bob64!")==0&&bob64_strcmp("a","b")<0&& + bob64_strcmp("b","a")>0, + "measure and compare NUL-terminated strings"); + return 0; +} + +static int compiler_tests(void) { + static const char source[]= + "int main(void) { bob64_app_write(\"bob!\", 4); return 0; }"; + static const char invalid[]="int main(void) { return value; }"; + usize length=0,error_offset=0; + BOB64_EXEC_IMAGE image; + CHECK(!bob64_compile_c(source,sizeof(source)-1,resident_compiler_image, + sizeof(resident_compiler_image),&length, + &error_offset)&&length==sizeof(resident_compiler_image), + "compile the resident C smoke program into a B64E image"); + resident_compiler_image_length=length; + CHECK(!bob64_exec_parse(resident_compiler_image,length,&image)&&image.EntryOffset==0&& + image.CodeSize==BOB64_PAGE_SIZE&&image.FileSize==2*BOB64_PAGE_SIZE&& + image.MemorySize==2*BOB64_PAGE_SIZE, + "validate resident compiler output with the shared B64E loader parser"); + CHECK(image.Image[0]==0x48&&image.Image[1]==0x83&&image.Image[2]==0xec&& + image.Image[3]==0x28&&image.Image[4]==0xe8&& + image.Image[43]==0x48&&image.Image[44]==0x8d&& + image.Image[50]==0xba&&image.Image[51]==4&&image.Image[55]==0xb8&& + image.Image[60]==0xcd&&image.Image[61]==0x80&& + !memcmp(image.Image+BOB64_PAGE_SIZE,"bob!",4), + "emit Microsoft x64 entry code and the bob! console syscall"); + CHECK(read32(image.Image+5)==23&& + (s32)read32(image.Image+46)==(s32)(BOB64_PAGE_SIZE-50)&& + image.Image[62]==0x48&&image.Image[63]==0xb8&& + read64(image.Image+64)==0&&image.Image[79]==0xc3, + "resolve the x64 entry call and RIP-relative string address"); + CHECK(bob64_compile_c(invalid,sizeof(invalid)-1,resident_compiler_image, + sizeof(resident_compiler_image),&length, + &error_offset)==-2&&error_offset>0, + "reject unsupported C syntax with a source offset"); + CHECK(bob64_compile_c(source,sizeof(source)-1,resident_compiler_image, + sizeof(resident_compiler_image)-1,&length, + &error_offset)==-1, + "reject a B64E output buffer that is too small"); + return 0; +} + +static int compiler_arithmetic_tests(void) { + static const char source[]= + "long long main(void) { return (0x100000001ULL + 2) * 3; }"; + static const char bad_suffix[]="long long main(void) { return 1LUL; }"; + static const char signed_source[]="int main(void) { return -1; }"; + u8 file[BOB64_COMPILER_IMAGE_LIMIT];usize length,error_offset; + BOB64_EXEC_IMAGE image; + CHECK(!bob64_compile_c(source,sizeof(source)-1,file,sizeof(file),&length, + &error_offset)&&!bob64_exec_parse(file,length,&image), + "compile a 64-bit arithmetic expression as a native app"); + CHECK(image.Image[43]==0x48&&image.Image[44]==0xb8&& + read64(image.Image+45)==0x100000001ULL&&image.Image[53]==0x50&& + image.Image[64]==0x59&&image.Image[65]==0x48&& + image.Image[66]==0x01&&image.Image[67]==0xc8&&image.Image[68]==0x50&& + image.Image[79]==0x59&&image.Image[80]==0x48&& + image.Image[81]==0x0f&&image.Image[82]==0xaf&& + image.Image[83]==0xc1&&image.Image[88]==0xc3, + "emit 64-bit immediates, stack temporaries, precedence, and multiply"); + s64 result=0; + CHECK(!execute_compiled_main(&image,&result)&&result==0x300000009LL, + "execute generated 64-bit arithmetic with the Microsoft x64 stack ABI"); + CHECK(bob64_compile_c(bad_suffix,sizeof(bad_suffix)-1,file,sizeof(file),&length, + &error_offset)==-2, + "reject malformed C integer suffixes"); + CHECK(!bob64_compile_c(signed_source,sizeof(signed_source)-1,file,sizeof(file), + &length,&error_offset)&& + !bob64_exec_parse(file,length,&image)&& + !execute_compiled_main(&image,&result)&&result==-1, + "sign-extend a 32-bit int return through the 64-bit app ABI"); + return 0; +} + +static int compiler_local_tests(void) { + static const char source[]= + "long long main(void) { long long value = 0x100000001ULL; " + "int delta = 2; value = value + delta; return value * 3; }"; + u8 file[BOB64_COMPILER_IMAGE_LIMIT];usize length,error_offset; + BOB64_EXEC_IMAGE image; + CHECK(!bob64_compile_c(source,sizeof(source)-1,file,sizeof(file),&length, + &error_offset)&&!bob64_exec_parse(file,length,&image), + "compile typed local variables and assignments into B64E"); + CHECK(contains_bytes(image.Image,(usize)image.CodeSize,"\x48\x89\x45\xf8",4)&& + contains_bytes(image.Image,(usize)image.CodeSize,"\x89\x45\xf0",3)&& + contains_bytes(image.Image,(usize)image.CodeSize,"\x48\x8b\x45\xf8",4)&& + contains_bytes(image.Image,(usize)image.CodeSize,"\x48\x63\x45\xf0",4), + "use 64-bit stack slots and sign-extend 32-bit local loads"); + s64 result=0; + CHECK(!execute_compiled_main(&image,&result)&&result==0x300000009LL, + "execute generated local loads/stores and the 64-bit function frame"); + static const char string_pointer_source[]= + "int main(void) { char *text = \"bob!\"; return length(text); } " + "int length(char *text) { int n = 0; " + "while (text[n] != '\\0') n = n + 1; return n; }"; + CHECK(!bob64_compile_c(string_pointer_source,sizeof(string_pointer_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile string literals, char pointers, and string-taking helpers"); + CHECK(!execute_compiled_main(&image,&result)&&result==4, + "execute char-pointer indexing and NUL-terminated string traversal"); + static const char char_array_source[]= + "int main(void) { char text[8] = \"bob!\"; text[1] = 'O'; " + "return length(text) + text[1]; } " + "int length(char text[]) { int n = 0; " + "while (text[n] != '\\0') n = n + 1; return n; }"; + CHECK(!bob64_compile_c(char_array_source,sizeof(char_array_source)-1,file, + sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile initialized local char arrays and array parameters"); + CHECK(!execute_compiled_main(&image,&result)&&result==4+'O', + "execute byte-array initialization, mutation, decay, and traversal"); + static const char char_brace_array_source[]= + "int main(void) { char text[4] = {'b','o','b','!'}; return text[3]; }"; + CHECK(!bob64_compile_c(char_brace_array_source, + sizeof(char_brace_array_source)-1,file,sizeof(file), + &length,&error_offset)&& + !bob64_exec_parse(file,length,&image)&& + !execute_compiled_main(&image,&result)&&result=='!', + "compile and execute brace-initialized char arrays"); + static const char exact_char_array_source[]= + "int main(void) { char text[3] = \"bob\"; return text[2]; }"; + CHECK(!bob64_compile_c(exact_char_array_source, + sizeof(exact_char_array_source)-1,file,sizeof(file), + &length,&error_offset)&& + !bob64_exec_parse(file,length,&image)&& + !execute_compiled_main(&image,&result)&&result=='b', + "allow a character array sized exactly to its string initializer"); + static const char char_array_zero_fill_source[]= + "int main(void) { char text[4] = {'b'}; return text[1]; }"; + CHECK(!bob64_compile_c(char_array_zero_fill_source, + sizeof(char_array_zero_fill_source)-1,file,sizeof(file), + &length,&error_offset)&& + !bob64_exec_parse(file,length,&image)&& + !execute_compiled_main(&image,&result)&&result==0, + "zero-fill omitted elements in a char array initializer"); + static const char oversized_char_string_source[]= + "int main(void) { char text[3] = \"long\"; return text[0]; }"; + CHECK(bob64_compile_c(oversized_char_string_source, + sizeof(oversized_char_string_source)-1,file,sizeof(file), + &length,&error_offset)==-2, + "reject a string initializer that exceeds its char array"); + static const char global_storage_source[]= + "static int counter = 40; char text[5] = \"bob!\"; " + "int values[3] = {1, 2}; " + "int main(void) { counter = counter + 2; text[1] = 'O'; " + "values[2] = counter; return letter(text) + values[2]; } " + "int letter(char *value) { return value[1]; }"; + CHECK(!bob64_compile_c(global_storage_source,sizeof(global_storage_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile initialized global scalars and mutable arrays across functions"); + CHECK(!execute_compiled_main(&image,&result)&&result=='O'+42, + "execute RIP-relative global loads/stores and global array access"); + static const char wide_global_source[]= + "long long wide = 0x100000001ULL; int zero_value; " + "long long main(void) { return wide + zero_value + 1; }"; + CHECK(!bob64_compile_c(wide_global_source,sizeof(wide_global_source)-1,file, + sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image)&& + !execute_compiled_main(&image,&result)&&result==0x100000002LL, + "preserve 64-bit initialized globals and zero-fill uninitialized globals"); + static const char global_pointer_source[]= + "char text[5] = \"bob!\"; int numbers[2] = {40, 2}; " + "char *active_text = text; int *values = numbers; char *label = \"gui\"; " + "int main(void) { active_text[1] = 'O'; return read_text() + values[0] + values[1] + label[0]; } " + "int read_text(void) { return active_text[1]; }"; + CHECK(!bob64_compile_c(global_pointer_source,sizeof(global_pointer_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image)&& + !execute_compiled_main(&image,&result)&&result=='O'+42+'g', + "initialize global pointers to arrays and strings without fixed-address relocations"); + static const char struct_member_source[]= + "struct Record { int value; char mark; long long count; char *text; }; " + "struct Record shared; " + "int first(char *text) { return text[0]; } " + "int main(void) { struct Record local; local.value=40; local.mark='!'; " + "local.count=2; shared.value=local.value+local.count; " + "shared.mark=local.mark; shared.text=\"bob\"; " + "return shared.value+shared.mark+first(shared.text); }"; + CHECK(!bob64_compile_c(struct_member_source,sizeof(struct_member_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile named struct layouts and local/global scalar and pointer members"); + CHECK(!execute_compiled_main(&image,&result)&&result==40+2+'!'+ 'b', + "execute aligned struct field loads and stores in local and global objects"); + static const char struct_pointer_source[]= + "struct Node { int value; }; struct Node shared; " + "struct Node *shared_pointer = &shared; " + "int main(void) { struct Node local; struct Node *pointer=&local; " + "pointer->value=40; shared_pointer->value=2; " + "return shared_pointer->value+pointer->value; }"; + CHECK(!bob64_compile_c(struct_pointer_source,sizeof(struct_pointer_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile struct pointers and arrow-member expressions"); + CHECK(!execute_compiled_main(&image,&result)&&result==42, + "execute global and local struct pointers across object layouts"); + static const char struct_pointer_function_source[]= + "struct Node { int value; }; " + "int read_value(struct Node *node) { return node->value; } " + "int main(void) { return 42; }"; + CHECK(!bob64_compile_c(struct_pointer_function_source, + sizeof(struct_pointer_function_source)-1,file,sizeof(file), + &length,&error_offset)&&!bob64_exec_parse(file,length,&image)&& + !execute_compiled_main(&image,&result)&&result==42, + "compile struct pointer parameters and their member access in helper functions"); + static const char struct_pointer_call_source[]= + "struct Node { int value; }; " + "int read_value(struct Node *node) { return node->value; } " + "int main(void) { struct Node local; struct Node *pointer=&local; " + "pointer->value=42; return read_value(pointer); }"; + int struct_pointer_call_result=bob64_compile_c(struct_pointer_call_source, + sizeof(struct_pointer_call_source)-1,file,sizeof(file),&length,&error_offset); + if(struct_pointer_call_result) { + usize begin=error_offset>24?error_offset-24:0; + usize end=error_offset+24value+a+b+c+d; } " + "int main(void) { struct Node local; struct Node *pointer=&local; " + "pointer->value=32; return read_value(1, 2, 3, 4, pointer); }"; + CHECK(!bob64_compile_c(struct_pointer_stack_call_source, + sizeof(struct_pointer_stack_call_source)-1,file,sizeof(file), + &length,&error_offset)&&!bob64_exec_parse(file,length,&image), + "compile a struct pointer in the fifth Microsoft x64 argument slot"); + CHECK(!execute_compiled_main(&image,&result)&&result==42, + "preserve struct pointers passed on the x64 argument stack"); + static const char char_pointer_arithmetic_source[]= + "int main(void) { char *text = \"bob!\"; return *(text + 1) == 'o'; }"; + CHECK(!bob64_compile_c(char_pointer_arithmetic_source, + sizeof(char_pointer_arithmetic_source)-1,file,sizeof(file), + &length,&error_offset)&& + !bob64_exec_parse(file,length,&image)&& + !execute_compiled_main(&image,&result)&&result==1, + "execute byte-scaled char-pointer arithmetic, dereference, and character literals"); + static const char char_pointer_store_source[]= + "int main(void) { char *text = \"bob!\"; text[1] = 97; return text[1]; }"; + CHECK(!bob64_compile_c(char_pointer_store_source, + sizeof(char_pointer_store_source)-1,file,sizeof(file), + &length,&error_offset)&& + !bob64_exec_parse(file,length,&image)&& + !execute_compiled_main(&image,&result)&&result=='a', + "execute byte stores through a char pointer"); + static const char signed_char_source[]= + "int main(void) { char value = 255; return value; }"; + CHECK(!bob64_compile_c(signed_char_source,sizeof(signed_char_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image)&& + !execute_compiled_main(&image,&result)&&result==-1, + "narrow and sign-extend a signed 8-bit char local"); + static const char char_argument_source[]= + "int main(void) { return value('A'); } int value(char input) { return input; }"; + CHECK(!bob64_compile_c(char_argument_source,sizeof(char_argument_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image)&& + !execute_compiled_main(&image,&result)&&result=='A', + "pass and sign-extend a char argument through the x64 ABI"); + static const char array_source[]= + "int main(void) { int values[3]; int *pointer = values; " + "pointer[0] = 40; pointer[1] = 2; return pointer[0] + pointer[1]; }"; + CHECK(!bob64_compile_c(array_source,sizeof(array_source)-1,file,sizeof(file), + &length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile a local int array through a 64-bit pointer"); + CHECK(!execute_compiled_main(&image,&result)&&result==42, + "execute pointer indexing, scaled address arithmetic, and array loads/stores"); + static const char pointer_arithmetic_source[]= + "int main(void) { int values[3]; int *pointer = values; " + "pointer = 1 + pointer; *pointer = 40; pointer = pointer - 1; " + "pointer[0] = 2; return values[1] + values[0]; }"; + CHECK(!bob64_compile_c(pointer_arithmetic_source, + sizeof(pointer_arithmetic_source)-1,file,sizeof(file), + &length,&error_offset)&&!bob64_exec_parse(file,length,&image), + "compile scaled pointer arithmetic in both addition operand orders"); + CHECK(!execute_compiled_main(&image,&result)&&result==42, + "execute pointer arithmetic with sizeof(int) scaling"); + static const char pointer_difference_source[]= + "long long main(void) { int values[3]; int *pointer = values; " + "pointer = pointer + 2; return pointer - values; }"; + CHECK(!bob64_compile_c(pointer_difference_source, + sizeof(pointer_difference_source)-1,file,sizeof(file), + &length,&error_offset)&&!bob64_exec_parse(file,length,&image), + "compile int-pointer difference as an element count"); + CHECK(!execute_compiled_main(&image,&result)&&result==2, + "execute pointer difference in int elements"); + static const char array_initializer_source[]= + "int main(void) { int seed = 40; int values[4] = {seed, 2,}; " + "return values[0] + values[1] + values[2] + values[3]; }"; + CHECK(!bob64_compile_c(array_initializer_source, + sizeof(array_initializer_source)-1,file,sizeof(file), + &length,&error_offset)&&!bob64_exec_parse(file,length,&image), + "compile local array brace initialization with a trailing comma"); + CHECK(!execute_compiled_main(&image,&result)&&result==42, + "execute local array initialization and zero-fill omitted elements"); + static const char excess_array_initializer[]= + "int main(void) { int values[1] = {1, 2}; return values[0]; }"; + CHECK(bob64_compile_c(excess_array_initializer, + sizeof(excess_array_initializer)-1,file,sizeof(file), + &length,&error_offset), + "reject an array initializer with excess elements"); + static const char array_parameter_source[]= + "int main(void) { int values[3] = {40, 2}; return sum(values, 2); } " + "int sum(int values[], int count) { " + "return values[0] + values[1] + count; }"; + CHECK(!bob64_compile_c(array_parameter_source,sizeof(array_parameter_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile array-parameter functions and a forward call from main"); + CHECK(!execute_compiled_main(&image,&result)&&result==44, + "execute an array parameter with the Microsoft x64 integer-argument ABI"); + static const char nested_call_source[]= + "int double_value(int value) { return value * 2; } " + "int main(void) { return add(double_value(21), 1); } " + "int add(int left, int right) { return left + right; }"; + CHECK(!bob64_compile_c(nested_call_source,sizeof(nested_call_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile nested calls and multiple integer arguments"); + CHECK(!execute_compiled_main(&image,&result)&&result==43, + "execute nested calls with stack alignment and forward-call fixups"); + static const char wide_return_source[]= + "long long wide_value(void); " + "long long main(void) { return wide_value(); } " + "long long wide_value(void) { return 0x100000001ULL; }"; + CHECK(!bob64_compile_c(wide_return_source,sizeof(wide_return_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile long-long helper definitions before main"); + CHECK(!execute_compiled_main(&image,&result)&&result==0x100000001LL, + "preserve a 64-bit helper return through the C call ABI"); + static const char long_type_source[]= + "long shared=40; long long wide=0x100000001ULL; " + "long read_shared(void); long long main(void) { long local=read_shared(); " + "return local+shared+wide; } " + "long read_shared(void) { return shared; }"; + CHECK(!bob64_compile_c(long_type_source,sizeof(long_type_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile 64-bit long globals, locals, prototypes, and returns"); + CHECK(!execute_compiled_main(&image,&result)&&result==0x100000051LL, + "execute LLP64 long and long-long values at their declared widths"); + static const char short_global_source[]= + "short shared=64302; int main(void) { return shared; }"; + CHECK(!bob64_compile_c(short_global_source,sizeof(short_global_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image)&& + !execute_compiled_main(&image,&result)&&result==-1234, + "load and sign-extend a 16-bit global"); + static const char short_local_source[]= + "int main(void) { short value=64302; return value; }"; + CHECK(!bob64_compile_c(short_local_source,sizeof(short_local_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image)&& + !execute_compiled_main(&image,&result)&&result==-1234, + "store and sign-extend a 16-bit local"); + static const char short_call_source[]= + "int main(void) { return echo(64302); } " + "short echo(short value) { return value; }"; + CHECK(!bob64_compile_c(short_call_source,sizeof(short_call_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile short helper call"); + CHECK(!execute_compiled_main(&image,&result)&&result==-1234, + "pass and return signed short values through a helper call"); + static const char short_stack_call_source[]= + "int main(void) { return fifth(1,2,3,4,64302); } " + "short fifth(int a,int b,int c,int d,short value) { return value; }"; + CHECK(!bob64_compile_c(short_stack_call_source,sizeof(short_stack_call_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image)&& + !execute_compiled_main(&image,&result)&&result==-1234, + "pass and return a signed short in the fifth ABI slot"); + static const char short_type_source[]= + "struct ShortRecord { char tag; short value; int tail; }; " + "short shared=64302; short echo(short value) { return value; } " + "short fifth(int a,int b,int c,int d,short value) { return value; } " + "int main(void) { short local=echo(shared); struct ShortRecord record; " + "record.value=fifth(1,2,3,4,local); record.tail=128; " + "if(local == -1234 && record.value == -1234 && record.tail == 128) " + "return 42; return 0; }"; + CHECK(!bob64_compile_c(short_type_source,sizeof(short_type_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile signed 16-bit globals, locals, fields, and ABI parameters"); + CHECK(!execute_compiled_main(&image,&result)&&result==42, + "sign-extend short loads and preserve short values across calls"); + static const char short_array_pointer_source[]= + "short shared[2]={65535,2}; short *shared_pointer=shared; " + "int sum(short values[]) { return values[0]+values[1]+values[2]; } " + "int main(void) { short values[4]={65535,2}; short *pointer=values; " + "*pointer=40; values[2]=shared_pointer[1]; " + "return sum(pointer)+*(shared_pointer+1); }"; + CHECK(!bob64_compile_c(short_array_pointer_source, + sizeof(short_array_pointer_source)-1,file,sizeof(file), + &length,&error_offset)&&!bob64_exec_parse(file,length,&image), + "compile short arrays, pointers, initialization, and array parameters"); + CHECK(!execute_compiled_main(&image,&result)&&result==46, + "index, dereference, and scale pointer arithmetic by two bytes"); + static const char pointer_sized_integer_source[]= + "uintptr_t high=0x100000001ULL; " + "usize echo_unsigned(usize value) { return value; } " + "isize echo_signed(isize value) { return value; } " + "int main(void) { usize size=echo_unsigned(high); " + "intptr_t distance=echo_signed(-42); " + "if(size > 0xffffffffULL && distance == -42) return 42; return 0; }"; + CHECK(!bob64_compile_c(pointer_sized_integer_source, + sizeof(pointer_sized_integer_source)-1,file,sizeof(file), + &length,&error_offset)&&!bob64_exec_parse(file,length,&image), + "compile uintptr_t/usize and intptr_t/isize function types"); + CHECK(!execute_compiled_main(&image,&result)&&result==42, + "preserve unsigned pointer-sized values above four GiB and signed isize arguments"); + static const char prototype_arguments_source[]= + "int combine(int, int); " + "int main(void) { return combine(20, 22); } " + "int combine(int left, int right) { return left + right; }"; + CHECK(!bob64_compile_c(prototype_arguments_source, + sizeof(prototype_arguments_source)-1,file,sizeof(file), + &length,&error_offset)&&!bob64_exec_parse(file,length,&image), + "compile a forward declaration with unnamed parameters"); + CHECK(!execute_compiled_main(&image,&result)&&result==42, + "resolve a prototype to its later definition"); + static const char conflicting_prototype_source[]= + "int combine(int); int main(void) { return combine(42); } " + "int combine(int left, int right) { return left + right; }"; + CHECK(bob64_compile_c(conflicting_prototype_source, + sizeof(conflicting_prototype_source)-1,file,sizeof(file), + &length,&error_offset), + "reject a function definition that conflicts with its prototype"); + static const char missing_function_definition_source[]= + "int absent(int); int main(void) { return absent(42); }"; + CHECK(bob64_compile_c(missing_function_definition_source, + sizeof(missing_function_definition_source)-1, + file,sizeof(file),&length,&error_offset), + "reject a call whose prototype has no definition"); + static const char four_argument_source[]= + "int main(void) { return sum4(1, 2, 3, 4); } " + "int sum4(int first, int second, int third, int fourth) { " + "return first + second + third + fourth; }"; + CHECK(!bob64_compile_c(four_argument_source,sizeof(four_argument_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile a four-argument call using all Microsoft x64 integer registers"); + CHECK(!execute_compiled_main(&image,&result)&&result==10, + "execute arguments in RCX, RDX, R8, and R9"); + static const char eight_argument_source[]= + "int main(void) { return sum8(1, 2, 3, 4, 5, 6, 7, 8); } " + "int sum8(int a, int b, int c, int d, int e, int f, int g, int h) { " + "return a + b + c + d + e + f + g + h; }"; + CHECK(!bob64_compile_c(eight_argument_source,sizeof(eight_argument_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile stack-passed fifth through eighth arguments"); + CHECK(!execute_compiled_main(&image,&result)&&result==36, + "execute eight arguments across registers and the Microsoft x64 stack area"); + static const char sixteen_argument_source[]= + "int main(void) { return sum16(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16); } " + "int sum16(int a,int b,int c,int d,int e,int f,int g,int h," + "int i,int j,int k,int l,int m,int n,int o,int p) { " + "return a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p; }"; + CHECK(!bob64_compile_c(sixteen_argument_source,sizeof(sixteen_argument_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile calls and definitions with sixteen ABI parameters"); + CHECK(!execute_compiled_main(&image,&result)&&result==136, + "execute sixteen arguments including the widest stack displacement"); + static const char lexical_scope_source[]= + "int main(void) { int value=40; { int value=2; value=value+1; } " + "{ int temporary=3; } { int temporary=4; } return value+2; }"; + CHECK(!bob64_compile_c(lexical_scope_source,sizeof(lexical_scope_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile shadowing locals and reused names in sibling C blocks"); + CHECK(!execute_compiled_main(&image,&result)&&result==42, + "restore the outer local binding after leaving a nested scope"); + static const char for_scope_source[]= + "int main(void) { int total=0; for(int index=0;index<3;index=index+1) " + "{ int item=index+1; total=total+item; } return total; }"; + CHECK(!bob64_compile_c(for_scope_source,sizeof(for_scope_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image)&& + !execute_compiled_main(&image,&result)&&result==6, + "scope a for-loop variable and its compound body"); + static const char duplicate_scope_local_source[]= + "int main(void) { { int value=1; int value=2; } return 0; }"; + CHECK(bob64_compile_c(duplicate_scope_local_source, + sizeof(duplicate_scope_local_source)-1,file,sizeof(file), + &length,&error_offset), + "reject duplicate declarations in the same lexical scope"); + static const char for_scope_escape_source[]= + "int main(void) { for(int index=0;index<1;index=index+1) { } " + "return index; }"; + CHECK(bob64_compile_c(for_scope_escape_source, + sizeof(for_scope_escape_source)-1,file,sizeof(file), + &length,&error_offset), + "reject access to a for-loop variable after its scope"); + static const char stack_pointer_argument_source[]= + "int main(void) { int value = 42; return read_pointer(1, 2, 3, 4, &value); } " + "int read_pointer(int a, int b, int c, int d, int *pointer) { " + "return *pointer; }"; + CHECK(!bob64_compile_c(stack_pointer_argument_source, + sizeof(stack_pointer_argument_source)-1,file,sizeof(file), + &length,&error_offset)&&!bob64_exec_parse(file,length,&image), + "compile a pointer passed in the fifth argument slot"); + CHECK(!execute_compiled_main(&image,&result)&&result==42, + "preserve a 64-bit pointer through stack argument passing"); + static const char bad_call_arity[]= + "int main(void) { return add(1); } " + "int add(int left, int right) { return left + right; }"; + CHECK(bob64_compile_c(bad_call_arity,sizeof(bad_call_arity)-1,file,sizeof(file), + &length,&error_offset), + "reject calls with the wrong number of arguments"); + static const char bad_pointer_argument[]= + "int main(void) { int value = 4; return read_value(value); } " + "int read_value(int *pointer) { return *pointer; }"; + CHECK(bob64_compile_c(bad_pointer_argument,sizeof(bad_pointer_argument)-1, + file,sizeof(file),&length,&error_offset), + "reject an integer argument where an int pointer is required"); + static const char control_flow_source[]= + "int main(void) { int count = 4; int total = 0; " + "while (count > 0) { if (count != 2) total = total + count; " + "else total = total + 2; count = count - 1; } return total; }"; + CHECK(!bob64_compile_c(control_flow_source,sizeof(control_flow_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile nested if/else and while control flow"); + CHECK(!execute_compiled_main(&image,&result)&&result==10, + "execute backward and forward branches through a counted loop"); + static const char for_loop_source[]= + "int main(void) { int total = 0; " + "for (int index = 0; index < 5; index = index + 1) " + "total = total + index; return total; }"; + CHECK(!bob64_compile_c(for_loop_source,sizeof(for_loop_source)-1,file,sizeof(file), + &length,&error_offset)&&!bob64_exec_parse(file,length,&image), + "compile a C-style for loop with a declaration, condition, and update"); + CHECK(!execute_compiled_main(&image,&result)&&result==10, + "execute for-loop condition, body, update, and back edges"); + static const char loop_control_source[]= + "int main(void) { int total = 0; " + "for (int index = 0; index < 6; index = index + 1) { " + "if (index == 2) continue; if (index == 5) break; " + "total = total + index; } return total; }"; + CHECK(!bob64_compile_c(loop_control_source,sizeof(loop_control_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile break and continue in a for loop"); + CHECK(!execute_compiled_main(&image,&result)&&result==8, + "continue runs the for update and break exits the nearest loop"); + static const char nested_loop_control_source[]= + "int main(void) { int outer = 0; int inner = 0; int total = 0; " + "while (outer < 3) { outer = outer + 1; inner = 0; " + "while (inner < 3) { inner = inner + 1; " + "if (inner == 2) continue; if (outer == 2) break; " + "total = total + 1; } if (outer == 3) break; } return total; }"; + CHECK(!bob64_compile_c(nested_loop_control_source, + sizeof(nested_loop_control_source)-1,file,sizeof(file), + &length,&error_offset)&&!bob64_exec_parse(file,length,&image), + "compile nested loops with loop-local break and continue targets"); + CHECK(!execute_compiled_main(&image,&result), + "execute nested loop control flow"); + CHECK(result==4,"route break and continue to the nearest nested loop"); + static const char early_return_source[]= + "int main(void) { return absolute(-42); } " + "int absolute(int value) { if (value < 0) return -value; return value; }"; + CHECK(!bob64_compile_c(early_return_source,sizeof(early_return_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile an early return inside a conditional helper"); + CHECK(!execute_compiled_main(&image,&result)&&result==42, + "execute an early conditional return and fallthrough return"); + static const char invalid_break_source[]= + "int main(void) { break; return 0; }"; + CHECK(bob64_compile_c(invalid_break_source,sizeof(invalid_break_source)-1, + file,sizeof(file),&length,&error_offset), + "reject break outside a loop"); + static const char invalid_continue_source[]= + "int main(void) { continue; return 0; }"; + CHECK(bob64_compile_c(invalid_continue_source,sizeof(invalid_continue_source)-1, + file,sizeof(file),&length,&error_offset), + "reject continue outside a loop"); + static const char comparison_source[]= + "int main(void) { int value = -1; int result = 0; " + "if (value < 0) { if (value <= -1) { if (value >= -1) { " + "if (value == -1) result = 42; } } } return result; }"; + CHECK(!bob64_compile_c(comparison_source,sizeof(comparison_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile signed relational and equality operators"); + CHECK(!execute_compiled_main(&image,&result)&&result==42, + "execute signed comparisons for if/else conditions"); + static const char logical_source[]= + "int main(void) { int value = 1; int result = 0; " + "if (0 && change(&value)) result = 9; " + "if (1 || change(&value)) result = value + 41; " + "if (!result) result = 0; return result; } " + "int change(int *pointer) { *pointer = 40; return 1; }"; + CHECK(!bob64_compile_c(logical_source,sizeof(logical_source)-1,file,sizeof(file), + &length,&error_offset)&&!bob64_exec_parse(file,length,&image), + "compile unary not and short-circuit logical expressions"); + CHECK(!execute_compiled_main(&image,&result)&&result==42, + "short-circuit logical operators skip pointer-mutating function calls"); + static const char invalid_pointer_arithmetic[]= + "int main(void) { int values[2]; int *pointer = values; " + "return pointer * 2; }"; + CHECK(bob64_compile_c(invalid_pointer_arithmetic, + sizeof(invalid_pointer_arithmetic)-1,file,sizeof(file), + &length,&error_offset), + "reject multiplication of a pointer by an integer"); + static const char invalid_pointer_assignment[]= + "int main(void) { int *pointer = 1; return 0; }"; + CHECK(bob64_compile_c(invalid_pointer_assignment, + sizeof(invalid_pointer_assignment)-1,file,sizeof(file), + &length,&error_offset), + "reject assigning an integer expression to an int pointer"); + static const char pointer_source[]= + "long long main(void) { int value = 42; int *pointer = &value; " + "*pointer = *pointer + 1; return pointer; }"; + CHECK(!bob64_compile_c(pointer_source,sizeof(pointer_source)-1,file,sizeof(file), + &length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile address-of, int-pointer dereference, and a pointer return"); + CHECK(!execute_compiled_main(&image,&result)&&result>0xffffffffLL, + "preserve a generated stack pointer value above the 4 GiB boundary"); + static const char usize_pointer_source[]= + "usize update(usize *pointer); " + "int main(void) { usize value = 0x100000001ULL; " + "usize *pointer = &value; update(pointer); " + "return pointer[0] - 0x100000003ULL; } " + "usize update(usize *pointer) { pointer[0] = pointer[0] + 2; " + "return *pointer; }"; + CHECK(!bob64_compile_c(usize_pointer_source,sizeof(usize_pointer_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile usize pointers through calls, dereference, and indexing"); + CHECK(!execute_compiled_main(&image,&result)&&result==0, + "preserve pointer-sized unsigned values above 4 GiB through memory"); + static const char usize_array_source[]= + "usize sum(usize values[], usize length) { usize total = 0; " + "usize index = 0; while (index < length) { total = total + values[index]; " + "index = index + 1; } return total; } " + "long long main(void) { usize values[3] = {0x100000000ULL, 2}; " + "values[1] = values[1] + 3; " + "return sum(values, 2) - 0x100000005ULL; }"; + CHECK(!bob64_compile_c(usize_array_source,sizeof(usize_array_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile local usize arrays, indexing, initialization, and array parameters"); + CHECK(!execute_compiled_main(&image,&result)&&result==0, + "sum initialized 64-bit array elements above 4 GiB through a helper"); + static const char isize_array_source[]= + "long long main(void) { isize values[3] = {-0x100000000LL, 2}; " + "values[1] = values[0] + 3; " + "return values[1] + 0xfffffffeLL; }"; + CHECK(!bob64_compile_c(isize_array_source,sizeof(isize_array_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile signed wide arrays and indexed assignment"); + CHECK(!execute_compiled_main(&image,&result)&&result==1, + "preserve signed 64-bit values in wide array elements"); + static const char global_usize_array_source[]= + "usize values[2] = {0x100000000ULL, 1}; usize *pointer = values; " + "long long main(void) { return pointer[1] - pointer[0] + 0xffffffffLL; }"; + CHECK(!bob64_compile_c(global_usize_array_source, + sizeof(global_usize_array_source)-1,file,sizeof(file), + &length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile global usize arrays and a decayed global pointer"); + CHECK(!execute_compiled_main(&image,&result)&&result==0, + "load global wide arrays through a 64-bit pointer"); + static const char isize_pointer_return_source[]= + "isize *step(isize *pointer) { return pointer + 1; } " + "long long main(void) { isize first = 0; isize second = 0; " + "return step(&second) - &second; }"; + CHECK(!bob64_compile_c(isize_pointer_return_source, + sizeof(isize_pointer_return_source)-1,file,sizeof(file), + &length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile isize pointer returns, scaled arithmetic, and subtraction"); + CHECK(!execute_compiled_main(&image,&result)&&result==1, + "scale isize pointer arithmetic by the eight-byte pointee size"); + static const char isize_pointer_source[]= + "struct Box { isize *value; }; " + "long long advance(isize *pointer) { pointer[0] = pointer[0] + 1; " + "return *pointer; } " + "long long main(void) { isize value = -0x100000001LL; " + "struct Box box; box.value = &value; " + "return advance(box.value) + 0x100000000LL; }"; + CHECK(!bob64_compile_c(isize_pointer_source,sizeof(isize_pointer_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile isize pointers in parameters and struct fields"); + CHECK(!execute_compiled_main(&image,&result)&&result==0, + "preserve signed 64-bit pointees through indexed and direct access"); + static const char mismatched_wide_pointer_source[]= + "usize read_value(usize *pointer) { return *pointer; } " + "long long main(void) { isize value = 1; " + "return read_value(&value); }"; + CHECK(bob64_compile_c(mismatched_wide_pointer_source, + sizeof(mismatched_wide_pointer_source)-1,file,sizeof(file), + &length,&error_offset), + "reject passing a signed wide pointer to an unsigned pointer parameter"); + static const char global_usize_pointer_source[]= + "usize shared = 0x100000002ULL; usize *cursor = &shared; " + "long long main(void) { return *cursor - 0x100000002ULL; }"; + CHECK(!bob64_compile_c(global_usize_pointer_source, + sizeof(global_usize_pointer_source)-1,file,sizeof(file), + &length,&error_offset)&& + !bob64_exec_parse(file,length,&image)&& + !execute_compiled_main(&image,&result)&&result==0, + "initialize a global usize pointer to a global scalar"); + static const char pointer_return_source[]= + "int *identity(int *pointer); " + "int main(void) { int value = 42; int *same = identity(&value); " + "return *same; } " + "int *identity(int *pointer) { return pointer; }"; + CHECK(!bob64_compile_c(pointer_return_source,sizeof(pointer_return_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile a typed pointer return through a prototype and call"); + CHECK(!execute_compiled_main(&image,&result)&&result==42, + "preserve pointer identity through a generated function return"); + static const char string_return_source[]= + "char *message(void) { return \"Bob!\"; } " + "int main(void) { char *text = message(); " + "return text[0] + text[1] + text[2] + text[3]; }"; + CHECK(!bob64_compile_c(string_return_source,sizeof(string_return_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile a returned string pointer and index its data"); + CHECK(!execute_compiled_main(&image,&result)&&result=='B'+'o'+'b'+'!', + "retain a string literal address through a pointer return"); + static const char struct_pointer_return_source[]= + "struct Item { int value; }; " + "struct Item *identity(struct Item *item); " + "int main(void) { struct Item value; value.value = 42; " + "struct Item *same = identity(&value); return same->value; } " + "struct Item *identity(struct Item *item) { return item; }"; + CHECK(!bob64_compile_c(struct_pointer_return_source, + sizeof(struct_pointer_return_source)-1,file,sizeof(file), + &length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile a declared-struct pointer return through a prototype"); + CHECK(!execute_compiled_main(&image,&result)&&result==42, + "preserve a struct pointer through a generated function return"); + static const char incompatible_pointer_return_source[]= + "int *wrong(void) { return \"Bob!\"; } " + "int main(void) { return 0; }"; + CHECK(bob64_compile_c(incompatible_pointer_return_source, + sizeof(incompatible_pointer_return_source)-1, + file,sizeof(file),&length,&error_offset), + "reject a pointer return with an incompatible pointee type"); + static const char char_return_source[]= + "char negative_byte(void); " + "int main(void) { return negative_byte(); } " + "char negative_byte(void) { return 255; }"; + CHECK(!bob64_compile_c(char_return_source,sizeof(char_return_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile a scalar char return through a prototype"); + CHECK(!execute_compiled_main(&image,&result)&&result==-1, + "sign-extend a returned high-bit char through the x64 ABI"); + static const char void_return_source[]= + "void store(int *pointer); " + "void add_two(int *pointer) { *pointer = *pointer + 2; } " + "int main(void) { int value = 0; store(&value); " + "add_two(&value); return value; } " + "void store(int *pointer) { *pointer = 40; return; }"; + CHECK(!bob64_compile_c(void_return_source,sizeof(void_return_source)-1, + file,sizeof(file),&length,&error_offset)&& + !bob64_exec_parse(file,length,&image), + "compile void calls with explicit and implicit function returns"); + CHECK(!execute_compiled_main(&image,&result)&&result==42, + "execute void helper calls and restore the caller stack"); + static const char invalid_void_value_source[]= + "void action(void) { return; } " + "int main(void) { return action(); }"; + CHECK(bob64_compile_c(invalid_void_value_source, + sizeof(invalid_void_value_source)-1,file,sizeof(file), + &length,&error_offset), + "reject using a void function call as a value"); + static const char invalid_nonvoid_empty_return_source[]= + "int value(void) { return; } int main(void) { return 0; }"; + CHECK(bob64_compile_c(invalid_nonvoid_empty_return_source, + sizeof(invalid_nonvoid_empty_return_source)-1,file,sizeof(file), + &length,&error_offset), + "reject an empty return in a non-void function"); + static const char invalid_void_value_return_source[]= + "void action(void) { return 42; } int main(void) { return 0; }"; + CHECK(bob64_compile_c(invalid_void_value_return_source, + sizeof(invalid_void_value_return_source)-1,file,sizeof(file), + &length,&error_offset), + "reject a value return in a void function"); + return 0; +} + +static u64 test_table_allocate(void *context) { + TEST_PAGE_TABLES *tables=(TEST_PAGE_TABLES *)context; + if(tables->Used==tables->Capacity)return 0; + return tables->Base+(tables->Used++)*BOB64_PAGE_SIZE; +} + +static u64 *test_table_access(void *context,u64 physical) { + TEST_PAGE_TABLES *tables=(TEST_PAGE_TABLES *)context; + if(physicalBase||(physical-tables->Base)%BOB64_PAGE_SIZE)return 0; + usize index=(usize)((physical-tables->Base)/BOB64_PAGE_SIZE); + if(index>=tables->Used)return 0; + return tables->Entries[index]; +} + +static int paging_tests(void) { + TEST_PAGE_TABLES storage={0x100000000ULL,0,16,{{0}}}; + BOB64_PAGE_TABLE table; + u64 physical=0,flags=0; + CHECK(!bob64_page_table_init(&table,48,test_table_allocate,test_table_access,&storage), + "initialize an x86-64 PML4 with physical pages above 4 GiB"); + CHECK(table.RootPhysical==0x100000000ULL,"retain a full-width PML4 address"); + CHECK(!bob64_page_map(&table,0x0000000100000000ULL,0x1234500000ULL, + BOB64_PAGE_WRITE|BOB64_PAGE_NX), + "map a 4 KiB page through the four-level hierarchy"); + CHECK(bob64_page_translate(&table,0x0000000100000123ULL,&physical,&flags)==1&& + physical==0x1234500123ULL&&(flags&BOB64_PAGE_WRITE)&&(flags&BOB64_PAGE_NX), + "translate an offset with 64-bit physical address and permissions"); + CHECK(bob64_page_translate(&table,0x0000000100001000ULL,&physical,&flags)==0, + "report an unmapped page"); + CHECK(!bob64_page_map(&table,0xffff800000001000ULL,0x100000000ULL, + BOB64_PAGE_USER), + "map the canonical upper-half address without truncation"); + CHECK(bob64_page_translate(&table,0xffff800000001000ULL,&physical,&flags)==1&& + physical==0x100000000ULL&&(flags&BOB64_PAGE_USER), + "walk upper-half PML4 entries"); + CHECK(bob64_page_map(&table,0x1001,0x2000,0)==BOB64_PAGING_INVALID, + "reject unaligned virtual pages"); + CHECK(bob64_page_map(&table,0x0000800000000000ULL,0x2000,0)==BOB64_PAGING_INVALID, + "reject noncanonical virtual addresses"); + CHECK(bob64_page_map(&table,0x3000,0x2000,0x2000)==BOB64_PAGING_INVALID, + "reject address bits smuggled through page flags"); + CHECK(!bob64_page_map(&table,0x9000,0xa000,BOB64_PAGE_USER|BOB64_PAGE_WRITE)&& + !bob64_page_protect(&table,0x9000,BOB64_PAGE_USER|BOB64_PAGE_NX)&& + bob64_page_translate(&table,0x9000,&physical,&flags)==1&& + physical==0xa000&&(flags&BOB64_PAGE_USER)&&(flags&BOB64_PAGE_NX)&& + !(flags&BOB64_PAGE_WRITE), + "tighten a mapped page to read-only user data and disable execution"); + u64 removed_physical=0,removed_flags=0; + CHECK(!bob64_page_unmap(&table,0x9000,&removed_physical,&removed_flags)&& + removed_physical==0xa000&&(removed_flags&BOB64_PAGE_USER)&& + bob64_page_translate(&table,0x9000,&physical,&flags)==0&& + bob64_page_protect(&table,0x9000,BOB64_PAGE_WRITE)==BOB64_PAGING_NOT_MAPPED, + "unmap a page, report its frame and permissions, and reject stale protection"); + CHECK(!bob64_page_map(&table,0x9000,0xb000,BOB64_PAGE_USER|BOB64_PAGE_WRITE)&& + bob64_page_translate(&table,0x9000,&physical,&flags)==1&&physical==0xb000, + "reuse a virtual page after removing its previous mapping"); + CHECK(bob64_page_map(&table,0x0000000100000000ULL,0x1000,0)== + BOB64_PAGING_ALREADY_MAPPED,"reject accidental remapping"); + CHECK(!bob64_page_map_range(&table,0x400123,0x500123,0x2200, + BOB64_PAGE_WRITE|BOB64_PAGE_NX), + "identity-map a byte range spanning partial first and last pages"); + CHECK(bob64_page_translate(&table,0x400123,&physical,&flags)==1&& + physical==0x500123&&bob64_page_translate(&table,0x402322,&physical,&flags)==1&& + physical==0x502322,"preserve offsets over a multi-page mapping"); + CHECK(bob64_page_map_range(&table,0x00007ffffffff000ULL,0x7000,0x2000,0)== + BOB64_PAGING_INVALID&& + bob64_page_translate(&table,0x00007ffffffff000ULL,&physical,&flags)==0, + "reject a span crossing the canonical-address hole before changing page tables"); + CHECK(bob64_page_map_range(&table,0x6000,0x8000,0,0)==BOB64_PAGING_INVALID, + "reject empty virtual-memory ranges"); + CHECK(!bob64_page_table_init(&table,40,test_table_allocate,test_table_access,&storage), + "initialize a page table with the detected physical-address width"); + CHECK(bob64_page_map(&table,0x4000,0x10000000000ULL,0)==BOB64_PAGING_INVALID, + "reject physical mappings above the CPU-reported address width"); + CHECK(bob64_page_table_init(&table,53,test_table_allocate,test_table_access,&storage)== + BOB64_PAGING_INVALID,"reject unsupported physical-address widths"); + return 0; +} + +static int process_address_space_tests(void) { + TEST_PAGE_TABLES *storage=&test_clone_tables; + BOB64_PAGE_TABLE kernel_table,process_table; + u64 physical,flags; + storage->Used=0; + CHECK(!bob64_page_table_init(&kernel_table,48,test_table_allocate, + test_table_access,storage),"initialize shared kernel mappings for a process root"); + CHECK(!bob64_page_map(&kernel_table,0x200000,0x300000, + BOB64_PAGE_WRITE|BOB64_PAGE_NX)&& + !bob64_page_map(&kernel_table,0xffff900000000000ULL,0x400000, + BOB64_PAGE_WRITE|BOB64_PAGE_NX)&& + !bob64_page_map(&kernel_table,BOB64_PROCESS_IMAGE_BASE,0x500000, + BOB64_PAGE_USER|BOB64_PAGE_WRITE|BOB64_PAGE_NX)&& + !bob64_page_map(&kernel_table,BOB64_PROCESS_STACK_BASE,0x501000, + BOB64_PAGE_USER|BOB64_PAGE_WRITE|BOB64_PAGE_NX)&& + !bob64_page_map(&kernel_table,BOB64_PROCESS_IMAGE_BASE+34ULL*1024*1024, + 0x502000,BOB64_PAGE_WRITE|BOB64_PAGE_NX), + "seed kernel, stale process, stack, and adjacent high-half mappings"); + CHECK(!bob64_page_table_init(&process_table,48,test_table_allocate, + test_table_access,storage)&& + !bob64_page_table_clone_isolated(&process_table,&kernel_table, + BOB64_PROCESS_IMAGE_BASE,34ULL*1024*1024), + "clone the kernel mappings while privatizing the complete application arena"); + CHECK(bob64_page_translate(&process_table,0x200000,&physical,&flags)==1&& + physical==0x300000&&bob64_page_translate(&process_table, + 0xffff900000000000ULL,&physical,&flags)==1&&physical==0x400000, + "retain low identity and high-half kernel mappings in the process root"); + CHECK(bob64_page_translate(&process_table,BOB64_PROCESS_IMAGE_BASE, + &physical,&flags)==0&&bob64_page_translate(&kernel_table, + BOB64_PROCESS_IMAGE_BASE,&physical,&flags)==1&&physical==0x500000&& + bob64_page_translate(&process_table,BOB64_PROCESS_STACK_BASE, + &physical,&flags)==0, + "remove stale image and stack pages only from the cloned user arena"); + CHECK(bob64_page_translate(&process_table, + BOB64_PROCESS_IMAGE_BASE+34ULL*1024*1024,&physical,&flags)==1&& + physical==0x502000,"preserve mappings immediately outside the isolated range"); + CHECK(!bob64_page_map(&process_table,BOB64_PROCESS_IMAGE_BASE+0x1000,0x600000, + BOB64_PAGE_USER)&&!bob64_page_map(&process_table, + BOB64_PROCESS_IMAGE_BASE+2ULL*1024*1024,0x601000, + BOB64_PAGE_USER|BOB64_PAGE_WRITE|BOB64_PAGE_NX)&& + bob64_page_translate(&kernel_table,BOB64_PROCESS_IMAGE_BASE+0x1000, + &physical,&flags)==0&&bob64_page_translate(&process_table, + BOB64_PROCESS_IMAGE_BASE+0x1000,&physical,&flags)==1&&physical==0x600000&& + (flags&BOB64_PAGE_USER)&&!(flags&BOB64_PAGE_WRITE), + "map private read-only executable code and writable NX data pages"); + CHECK(bob64_page_table_clone_isolated(&process_table,&kernel_table, + BOB64_PROCESS_IMAGE_BASE+1,34ULL*1024*1024)==BOB64_PAGING_INVALID&& + bob64_page_table_clone_isolated(&process_table,&kernel_table, + BOB64_PROCESS_IMAGE_BASE,2ULL<<30)==BOB64_PAGING_INVALID, + "reject unaligned and cross-PDPT isolation requests"); + return 0; +} + +static int bootstrap_tests(void) { + TEST_PAGE_TABLES storage={0x100000000ULL,16,16,{{0}}}; + BOB64_BOOTSTRAP_SPACE space; + u64 physical,flags; + CHECK(!bob64_bootstrap_space_init(&space,48,test_table_access,&storage, + storage.Base,16,0x200000,0x5000,0x800000,0x8000,1), + "build an identity-mapped bootstrap image, stack and table pool"); + CHECK(space.TablePoolUsed>1&&space.TablePoolUsed<=space.TablePoolPages, + "allocate every paging level from the pre-reserved table pool"); + CHECK(bob64_page_translate(&space.PageTable,0x204123,&physical,&flags)==1&& + physical==0x204123&&(flags&BOB64_PAGE_WRITE)&&!(flags&BOB64_PAGE_NX), + "keep executable EFI image pages identity-mapped"); + CHECK(bob64_page_translate(&space.PageTable,0x807fff,&physical,&flags)==1&& + physical==0x807fff&&(flags&BOB64_PAGE_WRITE)&&(flags&BOB64_PAGE_NX), + "map the replacement stack writable and non-executable"); + CHECK(bob64_page_translate(&space.PageTable,storage.Base+0x9000,&physical,&flags)==1&& + physical==storage.Base+0x9000&&(flags&BOB64_PAGE_NX), + "identity-map table pages needed after loading the new CR3"); + CHECK(bob64_bootstrap_space_init(&space,48,test_table_access,&storage, + storage.Base,1,0x200000,0x5000,0x800000,0x8000,1)==BOB64_PAGING_NO_MEMORY, + "fail cleanly when the reserved table pool cannot cover all mappings"); + CHECK(bob64_bootstrap_space_init(&space,48,test_table_access,&storage, + storage.Base,16,0x200000,0x5000,0x204000,0x2000,1)<0, + "reject overlapping image and stack identity ranges"); + return 0; +} + +static int cpu_tests(void) { + BOB64_CPU_FEATURES features; + BOB64_CPU_FEATURES host_features; + CHECK(!bob64_cpu_decode_features(1,0x80000008u,1u<<6, + (1u<<29)|(1u<<20),48,&features),"decode x86-64 CPU feature leaves"); + CHECK(features.PAE&&features.LongMode&&features.NX&&features.PhysicalAddressBits==48, + "record PAE, long mode, NX and physical-address width"); + CHECK(!bob64_cpu_decode_features(1,0x80000001u,1u<<6,1u<<29,0,&features)&& + features.PhysicalAddressBits==36, + "use the architectural minimum address width when leaf 80000008 is absent"); + CHECK(!bob64_cpu_decode_features(0,0,1u<<6,(1u<<29)|(1u<<20),0,&features)&& + !features.PAE&&!features.LongMode&&!features.NX, + "do not trust feature bits from leaves the CPU does not provide"); + CHECK(bob64_cpu_decode_features(1,0x80000008u,1u<<6,1u<<29,53,&features)<0, + "reject impossible CPUID physical-address widths"); + CHECK(bob64_cpu_decode_features(1,0x80000008u,1u<<6,1u<<29,35,&features)<0, + "reject physical-address widths below PAE requirements"); + CHECK(!bob64_cpu_detect(&host_features)&&host_features.PAE&&host_features.LongMode&& + host_features.PhysicalAddressBits>=36&&host_features.PhysicalAddressBits<=52, + "query real host CPUID leaves without privileged instructions"); + return 0; +} + +static int descriptor_tests(void) { + u64 gdt[BOB64_GDT_ENTRY_COUNT]; + BOB64_TSS tss; + BOB64_IDT_GATE idt[BOB64_IDT_ENTRIES]; + BOB64_DESCRIPTOR_TABLE_POINTER pointer; + const u64 handler=0x1234567887654321ULL; + CHECK(!bob64_tss_init(&tss,0x1234567887654000ULL)&&tss.Rsp0==0x1234567887654000ULL&& + tss.IoMapBase==sizeof(tss)&&tss.Reserved0==0&& + bob64_tss_init(&tss,0x1234567887654008ULL)<0, + "initialize a 64-bit TSS with aligned privilege stack and disabled I/O bitmap"); + CHECK(!bob64_tss_set_rsp0(&tss,0xabcdef0087654000ULL)&& + tss.Rsp0==0xabcdef0087654000ULL&& + bob64_tss_set_rsp0(&tss,0xabcdef0087654008ULL)<0&& + bob64_tss_set_rsp0(0,0x1234567887654000ULL)<0&& + tss.Rsp0==0xabcdef0087654000ULL, + "switch the TSS privilege stack without truncating its 64-bit address"); + CHECK(!bob64_tss_init(&tss,0x1234567887654000ULL),"restore a valid TSS after bad input"); + bob64_gdt_init(gdt,&pointer,&tss); + CHECK(gdt[0]==0&&gdt[1]==0x00af9a000000ffffULL&& + gdt[2]==0x00cf92000000ffffULL&&gdt[3]==0x00cff2000000ffffULL&& + gdt[4]==0x00affa000000ffffULL, + "build kernel and DPL3 user code/data segments in the 64-bit GDT"); + u64 tss_base=(u64)(uintptr_t)&tss; + u64 tss_low=(103ULL)|((tss_base&0xffffffULL)<<16)|((u64)0x89<<40)| + ((tss_base&0xff000000ULL)<<32); + CHECK(gdt[5]==tss_low&&gdt[6]==(tss_base>>32)&&pointer.Limit==55&& + pointer.Base==(u64)(uintptr_t)gdt&&pointer.Base>0xffffffffULL, + "encode the complete TSS base in a two-slot 64-bit GDT descriptor"); + CHECK(!bob64_idt_init(idt,handler,BOB64_GDT_KERNEL_CODE_SELECTOR,0), + "initialize a full 256-entry IDT"); + CHECK(idt[255].OffsetLow==0x4321&&idt[255].OffsetMiddle==0x8765&& + idt[255].OffsetHigh==0x12345678&&idt[255].Selector==0x08&& + idt[255].TypeAttributes==0x8e&&idt[255].Reserved==0, + "split a 64-bit handler address into an x86-64 interrupt gate"); + CHECK(!bob64_idt_set_gate(&idt[14],handler,0x08,3,0,BOB64_IDT_TRAP_GATE)&& + idt[14].Ist==3&&idt[14].TypeAttributes==0x8f, + "support a trap gate and IST selection"); + CHECK(!bob64_idt_set_gate(&idt[128],handler,BOB64_GDT_KERNEL_CODE_SELECTOR,0,3, + BOB64_IDT_INTERRUPT_GATE)&&idt[128].TypeAttributes==0xee, + "encode a DPL3 interrupt gate for a future user syscall entry"); + bob64_idt_pointer(&pointer,idt); + CHECK(pointer.Limit==4095&&pointer.Base==(u64)(uintptr_t)idt&& + pointer.Base>0xffffffffULL,"build an IDTR without truncating its base"); + CHECK(bob64_idt_set_gate(&idt[0],handler,0,0,0,BOB64_IDT_INTERRUPT_GATE)<0&& + bob64_idt_set_gate(&idt[0],handler,0x08,8,0,BOB64_IDT_INTERRUPT_GATE)<0&& + bob64_idt_set_gate(&idt[0],handler,0x08,0,4,BOB64_IDT_INTERRUPT_GATE)<0&& + bob64_idt_set_gate(&idt[0],handler,0x08,0,0,0x0c)<0, + "reject invalid IDT selectors, IST, privilege and gate types"); + CHECK(bob64_idt_init(idt,0,0x08,0)<0,"reject an unusable default exception gate"); + CHECK(!bob64_interrupts_build_idt(idt,BOB64_GDT_KERNEL_CODE_SELECTOR), + "wire all CPU exceptions to their dedicated 64-bit assembly stubs"); + for(usize vector=0;vector<32;vector++) { + u64 stub=(u64)(uintptr_t)bob64_exception_stub_table[vector]; + CHECK(idt[vector].OffsetLow==(u16)stub&& + idt[vector].OffsetMiddle==(u16)(stub>>16)&& + idt[vector].OffsetHigh==(u32)(stub>>32), + "preserve each assembly stub address in its IDT gate"); + } + CHECK(idt[34].OffsetLow==(u16)(uintptr_t)bob64_unhandled_interrupt&& + idt[255].OffsetHigh==(u32)((u64)(uintptr_t)bob64_unhandled_interrupt>>32), + "route unassigned vectors to the fatal fallback stub"); + CHECK(idt[0x80].OffsetLow==(u16)(uintptr_t)bob64_syscall_entry&& + idt[0x80].TypeAttributes==0xee, + "install the user-callable DPL3 syscall gate"); + CHECK(idt[0x21].OffsetLow==(u16)(uintptr_t)bob64_irq1_entry&& + idt[0x21].TypeAttributes==0x8e, + "install the kernel-only keyboard IRQ gate"); + CHECK(idt[0x20].OffsetLow==(u16)(uintptr_t)bob64_irq0_entry&& + idt[0x20].TypeAttributes==0x8e, + "install the kernel-only PIT timer IRQ gate"); + CHECK(idt[0x2c].OffsetLow==(u16)(uintptr_t)bob64_irq12_entry&& + idt[0x2c].TypeAttributes==0x8e, + "install the kernel-only PS/2 mouse IRQ gate"); + return 0; +} + +static char syscall_test_output[16]; +static usize syscall_test_output_length; +static u64 syscall_test_user_base; +static char syscall_test_file_name[BOB64_SYSCALL_MAX_FILENAME+1]; +static u8 syscall_test_file_data[BOB64_SYSCALL_MAX_BUFFER]; +static usize syscall_test_file_length; +static u8 syscall_test_user_output[BOB64_SYSCALL_MAX_BUFFER]; +static usize syscall_test_user_output_length; +static u32 syscall_test_surface[6*8]; +static u32 syscall_test_display_pixels[6*8]; +static u32 syscall_context_test_counts[2]; +static BOB64_EVENT syscall_test_event={.Type=BOB64_EVENT_KEY_DOWN,.Key=0x01, + .Character=0x1b}; +static void syscall_test_write(void *context,u8 character) { + (void)context; + if(syscall_test_output_length=syscall_test_user_base+64&& + address-syscall_test_user_base-64<=sizeof(syscall_test_surface)&& + length<=sizeof(syscall_test_surface)- + (usize)(address-syscall_test_user_base-64)) { + memcpy(destination,(const u8 *)syscall_test_surface+ + (usize)(address-syscall_test_user_base-64),length); + return 0; + } + if(!source||length>source_length)return -1; + memcpy(destination,source,length); + return 0; +} +static int syscall_test_write_user(void *context,u64 address,const void *source, + usize length) { + (void)context; + if((address!=syscall_test_user_base+48&& + address!=syscall_test_user_base+3*BOB64_PAGE_SIZE)|| + length>sizeof(syscall_test_user_output))return -1; + memcpy(syscall_test_user_output,source,length); + syscall_test_user_output_length=length; + return 0; +} +static int syscall_test_wait_event(void *context,BOB64_EVENT *event) { + (void)context; + if(!event)return -1; + *event=syscall_test_event; + return 0; +} +static s64 syscall_test_file_read(void *context,const char *name,u8 *buffer, + usize capacity) { + (void)context; + if(strcmp(name,syscall_test_file_name))return -2; + if(syscall_test_file_length>capacity)return -28; + memcpy(buffer,syscall_test_file_data,syscall_test_file_length); + return (s64)syscall_test_file_length; +} +static s64 syscall_test_file_write(void *context,const char *name,const u8 *buffer, + usize length) { + (void)context; + if(length>sizeof(syscall_test_file_data)||strlen(name)>=sizeof(syscall_test_file_name)) + return -28; + strcpy(syscall_test_file_name,name);memcpy(syscall_test_file_data,buffer,length); + syscall_test_file_length=length;return (s64)length; +} +static s64 syscall_test_stream_open(void *context,const char *name,u32 flags) { + (void)context;(void)flags; + return strcmp(name,syscall_test_file_name)?-2:(s64)syscall_test_file_length; +} +static s64 syscall_test_stream_read(void *context,const char *name,u64 offset, + u8 *buffer,usize capacity) { + (void)context; + if(strcmp(name,syscall_test_file_name))return -2; + if(offset>=syscall_test_file_length)return 0; + usize count=syscall_test_file_length-(usize)offset; + if(count>capacity)count=capacity; + memcpy(buffer,syscall_test_file_data+(usize)offset,count); + return (s64)count; +} +static s64 syscall_test_stream_write(void *context,const char *name,u64 offset, + const u8 *buffer,usize length) { + (void)context; + if(strcmp(name,syscall_test_file_name)||offset>sizeof(syscall_test_file_data)|| + length>sizeof(syscall_test_file_data)-(usize)offset)return -28; + memcpy(syscall_test_file_data+(usize)offset,buffer,length); + if((usize)offset+length>syscall_test_file_length) + syscall_test_file_length=(usize)offset+length; + return (s64)length; +} +static s64 syscall_test_file_list(void *context,BOB64_FILE_INFO *entries, + usize capacity) { + (void)context; + if(!entries||!capacity)return -22; + memset(entries,0,sizeof(*entries)); + strcpy(entries[0].Name,"note");entries[0].Size=4; + return 1; +} +static s64 syscall_test_file_delete(void *context,const char *name) { + (void)context; + return strcmp(name,"note")?-2:0; +} + +static int syscall_tests(void) { + TEST_PAGE_TABLES *storage=&test_clone_tables; + BOB64_PAGE_TABLE table; + HEAP_TEST_ARENA window_arena={0}; + BOB64_HEAP window_heap; + BOB64_WINDOW_SERVER window_server; + BOB64_INTERRUPT_FRAME frame={0}; + u64 first=BOB64_PROCESS_IMAGE_BASE,physical; + u64 window_owner=0x100000001ULL,window_handle; + u64 timer_before; + u64 *root; + if(bob64_framebuffer_init((u64)(uintptr_t)syscall_test_display_pixels, + sizeof(syscall_test_display_pixels),6,8,6,0))return -1; + if(bob64_heap_init(&window_heap,sizeof(window_arena.Bytes),heap_test_grow, + &window_arena)||bob64_window_server_init(&window_server,&window_heap, + window_owner,6,8))return -1; + for(usize i=0;iUsed=0; + if(bob64_page_table_init(&table,48,test_table_allocate,test_table_access,storage)|| + bob64_page_map(&table,first,0x800000,BOB64_PAGE_USER|BOB64_PAGE_WRITE)|| + bob64_page_map(&table,first+BOB64_PAGE_SIZE,0x801000,0)|| + bob64_page_map(&table,first+2*BOB64_PAGE_SIZE,0x802000,BOB64_PAGE_USER)|| + bob64_page_map(&table,first+3*BOB64_PAGE_SIZE,0x803000, + BOB64_PAGE_USER|BOB64_PAGE_WRITE)|| + bob64_page_map(&table,first+4*BOB64_PAGE_SIZE,0x804000, + BOB64_PAGE_USER|BOB64_PAGE_WRITE))return -1; + if(bob64_syscall_validate_user_range(&table,first+16,64)|| + bob64_syscall_validate_user_range(&table,first+BOB64_PAGE_SIZE,1)==0|| + bob64_syscall_validate_user_range(&table,first+BOB64_PAGE_SIZE-1,2)==0|| + bob64_syscall_validate_user_range(&table,BOB64_PROCESS_STACK_GUARD,1)==0|| + bob64_syscall_validate_user_range(&table,first+3*BOB64_PAGE_SIZE, + BOB64_SYSCALL_MAX_BUFFER)!=0|| + bob64_syscall_validate_user_range(&table,first+3*BOB64_PAGE_SIZE, + BOB64_SYSCALL_MAX_BUFFER+1)==0|| + bob64_page_translate(&table,first,&physical,0)!=1)return -1; + root=table.Access(table.Context,table.RootPhysical); + usize root_index=(usize)((first>>39)&0x1ff); + u64 original_root_entry=root[root_index]; + root[root_index]&=~BOB64_PAGE_USER; + if(bob64_syscall_validate_user_range(&table,first,1)==0)return -1; + root[root_index]=original_root_entry; + bob64_syscall_set_address_space(&table); + bob64_syscall_set_write(syscall_test_write,0); + bob64_syscall_set_read_user(syscall_test_read_user,0); + bob64_syscall_set_write_user(syscall_test_write_user,0); + bob64_syscall_set_filesystem(syscall_test_file_read,syscall_test_file_write,0); + bob64_syscall_set_file_stream(syscall_test_stream_open,syscall_test_stream_read, + syscall_test_stream_write,0); + bob64_syscall_set_file_manager(syscall_test_file_list, + syscall_test_file_delete,0); + bob64_syscall_set_wait_event(syscall_test_wait_event,0); + bob64_syscall_set_window_server(&window_server,window_owner); + bob64_user_active=1; + syscall_test_output_length=0;syscall_test_user_base=first+16; + frame.CS=0x23;frame.RAX=BOB64_SYSCALL_QUERY_ABI; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX!=BOB64_SYSCALL_ABI_VERSION)return -1; + timer_before=bob64_timer_ticks();bob64_timer_irq_tick(); + frame.RAX=BOB64_SYSCALL_GET_TICKS; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX!=timer_before+1)return -1; + frame.RAX=BOB64_SYSCALL_GET_DISPLAY; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX!=6||frame.RDX!=8)return -1; + frame.RAX=BOB64_SYSCALL_PRESENT;frame.RCX=first+80;frame.RDX=6;frame.R8=8; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX!=48|| + syscall_test_display_pixels[0]!=0x000000ffu|| + syscall_test_display_pixels[1]!=0x00ff0000u)return -1; + if(bob64_framebuffer_init((u64)(uintptr_t)syscall_test_display_pixels, + sizeof(syscall_test_display_pixels),6,8,6,1))return -1; + frame.RAX=BOB64_SYSCALL_PRESENT;frame.RCX=first+80;frame.RDX=6;frame.R8=8; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX!=48|| + syscall_test_display_pixels[0]!=0x00ff0000u|| + syscall_test_display_pixels[1]!=0x000000ffu)return -1; + frame.RAX=BOB64_SYSCALL_PRESENT;frame.RCX=first+BOB64_PAGE_SIZE; + frame.RDX=6;frame.R8=8; + if(bob64_syscall_dispatch(&frame)!=0||(s64)frame.RAX!=-14)return -1; + frame.RAX=BOB64_SYSCALL_PRESENT;frame.RCX=first+80;frame.RDX=5;frame.R8=8; + if(bob64_syscall_dispatch(&frame)!=0||(s64)frame.RAX!=-14)return -1; + frame.RAX=BOB64_SYSCALL_WAIT_EVENT;frame.RCX=first+64; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX|| + syscall_test_user_output_length!=sizeof(syscall_test_event)|| + memcmp(syscall_test_user_output,&syscall_test_event,sizeof(syscall_test_event)))return -1; + frame.RAX=BOB64_SYSCALL_WAIT_EVENT;frame.RCX=first+BOB64_PAGE_SIZE; + if(bob64_syscall_dispatch(&frame)!=0||(s64)frame.RAX!=-14)return -1; + frame.RAX=BOB64_SYSCALL_WRITE_CHAR;frame.RCX='!'; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX|| + syscall_test_output_length!=1||syscall_test_output[0]!='!')return -1; + frame.RAX=BOB64_SYSCALL_WRITE_BUFFER;frame.RCX=first+16;frame.RDX=3; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX!=3|| + syscall_test_output_length!=4||memcmp(syscall_test_output,"!abc",4))return -1; + frame.RAX=BOB64_SYSCALL_WRITE_BUFFER;frame.RCX=first+BOB64_PAGE_SIZE;frame.RDX=1; + if(bob64_syscall_dispatch(&frame)!=0||(s64)frame.RAX!=-14)return -1; + frame.RAX=BOB64_SYSCALL_WRITE_FILE;frame.RCX=first+32;frame.RDX=4; + frame.R8=BOB64_PROCESS_STACK_GUARD;frame.R9=4; + if(bob64_syscall_dispatch(&frame)!=0||(s64)frame.RAX!=-14)return -1; + frame.RAX=BOB64_SYSCALL_WRITE_FILE; + frame.RCX=first+32;frame.R8=first+48; + frame.RDX=4;frame.R9=4; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX!=4|| + strcmp(syscall_test_file_name,"note")||syscall_test_file_length!=4|| + memcmp(syscall_test_file_data,"data",4))return -1; + frame.RAX=BOB64_SYSCALL_READ_FILE;frame.RCX=first+32;frame.RDX=4; + frame.R8=first+64;frame.R9=16; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX!=4|| + syscall_test_user_output_length!=4||memcmp(syscall_test_user_output,"data",4))return -1; + frame.RAX=BOB64_SYSCALL_OPEN_FILE;frame.RCX=first+32;frame.RDX=4; + frame.R8=BOB64_FILE_OPEN_READ|BOB64_FILE_OPEN_WRITE; + if(bob64_syscall_dispatch(&frame)!=0||!frame.RAX||(s64)frame.RAX<0)return -1; + u64 stream_handle=frame.RAX; + frame.RAX=BOB64_SYSCALL_READ_HANDLE;frame.RCX=stream_handle; + frame.RDX=first+64;frame.R8=2; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX!=2|| + memcmp(syscall_test_user_output,"da",2))return -1; + frame.RAX=BOB64_SYSCALL_SEEK_HANDLE;frame.RCX=stream_handle; + frame.RDX=0x100000123ULL; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX!=0x100000123ULL)return -1; + frame.RAX=BOB64_SYSCALL_SEEK_HANDLE;frame.RCX=stream_handle;frame.RDX=2; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX!=2)return -1; + frame.RAX=BOB64_SYSCALL_WRITE_HANDLE;frame.RCX=stream_handle; + frame.RDX=first+48;frame.R8=2; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX!=2|| + syscall_test_file_length!=4||memcmp(syscall_test_file_data,"dada",4))return -1; + frame.RAX=BOB64_SYSCALL_CLOSE_HANDLE;frame.RCX=stream_handle; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX)return -1; + frame.RAX=BOB64_SYSCALL_READ_HANDLE;frame.RCX=stream_handle; + frame.RDX=first+64;frame.R8=1; + if(bob64_syscall_dispatch(&frame)!=0||(s64)frame.RAX!=-9)return -1; + frame.RAX=BOB64_SYSCALL_OPEN_FILE;frame.RCX=first+32;frame.RDX=4; + frame.R8=BOB64_FILE_OPEN_WRITE|BOB64_FILE_OPEN_APPEND; + if(bob64_syscall_dispatch(&frame)!=0||!frame.RAX||(s64)frame.RAX<0)return -1; + stream_handle=frame.RAX; + frame.RAX=BOB64_SYSCALL_WRITE_HANDLE;frame.RCX=stream_handle; + frame.RDX=first+48;frame.R8=2; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX!=2|| + syscall_test_file_length!=6||memcmp(syscall_test_file_data,"dadada",6))return -1; + frame.RAX=BOB64_SYSCALL_CLOSE_HANDLE;frame.RCX=stream_handle; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX)return -1; + frame.RAX=BOB64_SYSCALL_READ_FILE;frame.RCX=first+32;frame.RDX=4; + frame.R8=first+BOB64_PAGE_SIZE;frame.R9=16; + if(bob64_syscall_dispatch(&frame)!=0||(s64)frame.RAX!=-14)return -1; + frame.RAX=BOB64_SYSCALL_READ_FILE;frame.RCX=first+32;frame.RDX=4; + frame.R8=first+2*BOB64_PAGE_SIZE;frame.R9=16; + if(bob64_syscall_dispatch(&frame)!=0||(s64)frame.RAX!=-14)return -1; + for(usize i=0;iName,"note")|| + ((BOB64_FILE_INFO *)syscall_test_user_output)->Size!=4)return -1; + frame.RAX=BOB64_SYSCALL_LIST_FILES;frame.RCX=first+2*BOB64_PAGE_SIZE+16; + frame.RDX=1; + if(bob64_syscall_dispatch(&frame)!=0||(s64)frame.RAX!=-14)return -1; + frame.RAX=BOB64_SYSCALL_LIST_FILES;frame.RCX=first+3*BOB64_PAGE_SIZE+16; + frame.RDX=BOB64_SYSCALL_MAX_FILES+1; + if(bob64_syscall_dispatch(&frame)!=0||(s64)frame.RAX!=-22)return -1; + frame.RAX=BOB64_SYSCALL_DELETE_FILE;frame.RCX=first+32;frame.RDX=4; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX)return -1; + frame.RAX=BOB64_SYSCALL_DELETE_FILE;frame.RCX=first+BOB64_PAGE_SIZE;frame.RDX=4; + if(bob64_syscall_dispatch(&frame)!=0||(s64)frame.RAX!=-14)return -1; + frame.RAX=BOB64_SYSCALL_CREATE_WINDOW;frame.RCX=1;frame.RDX=2; + frame.R8=2;frame.R9=2; + if(bob64_syscall_dispatch(&frame)!=0||!frame.RAX||(s64)frame.RAX<0)return -1; + window_handle=frame.RAX; + frame.RAX=BOB64_SYSCALL_FOCUS_WINDOW;frame.RCX=window_handle; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX|| + window_server.Manager.Focused!=window_handle)return -1; + frame.RAX=BOB64_SYSCALL_PRESENT_WINDOW;frame.RCX=window_handle; + frame.RDX=first+80;frame.R8=2;frame.R9=2; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX!=4|| + syscall_test_display_pixels[2*6+1]!=0x00ff0000u)return -1; + frame.RAX=BOB64_SYSCALL_PRESENT_WINDOW;frame.RCX=window_handle; + frame.RDX=first+80;frame.R8=1;frame.R9=2; + if(bob64_syscall_dispatch(&frame)!=0||(s64)frame.RAX!=-14)return -1; + frame.RAX=BOB64_SYSCALL_DESTROY_WINDOW;frame.RCX=window_handle; + if(bob64_syscall_dispatch(&frame)!=0||frame.RAX||window_server.Manager.Count) + return -1; + frame.RAX=BOB64_SYSCALL_READ_FILE;frame.RCX=first+32;frame.RDX=4; + frame.R8=first+3*BOB64_PAGE_SIZE+16; + frame.R9=BOB64_SYSCALL_MAX_BUFFER+1; + if(bob64_syscall_dispatch(&frame)!=0||(s64)frame.RAX!=-22)return -1; + frame.RAX=BOB64_SYSCALL_EXIT;frame.RCX=42; + if(bob64_syscall_dispatch(&frame)!=1||bob64_user_active|| + bob64_user_return_value!=42)return -1; + bob64_user_active=1;frame.RAX=99; + if(bob64_syscall_dispatch(&frame)!=1||bob64_user_return_value!=-38|| + bob64_user_active)return -1; + frame.CS=BOB64_GDT_KERNEL_CODE_SELECTOR;frame.RAX=BOB64_SYSCALL_EXIT; + if(bob64_syscall_dispatch(&frame)!=0||(s64)frame.RAX!=-1||bob64_user_active) + return -1; + bob64_syscall_set_write(0,0); + bob64_syscall_set_read_user(0,0); + bob64_syscall_set_write_user(0,0); + bob64_syscall_set_filesystem(0,0,0); + bob64_syscall_set_file_stream(0,0,0,0); + bob64_syscall_set_file_manager(0,0,0); + bob64_syscall_set_wait_event(0,0); + bob64_syscall_set_window_server(0,0); + bob64_syscall_set_address_space(0); + bob64_window_server_close(&window_server); + return 0; +} + +static u16 read16(const u8 *bytes) { + return (u16)(bytes[0]|((u16)bytes[1]<<8)); +} + +static u32 read32(const u8 *bytes) { + return (u32)bytes[0]|((u32)bytes[1]<<8)|((u32)bytes[2]<<16)|((u32)bytes[3]<<24); +} + +static u64 read64(const u8 *bytes) { + return (u64)read32(bytes)|((u64)read32(bytes+4)<<32); +} + +static int memory_tests(void) { + struct ExtendedDescriptor { EFI_MEMORY_DESCRIPTOR Descriptor;u64 Extension; } extended[2]={0}; + EFI_MEMORY_DESCRIPTOR allocation_map={EFI_MEMORY_CONVENTIONAL,0,0x400000,0, + BOB64_PAGE_ALLOCATION_LIMIT+1,0}; + EFI_MEMORY_DESCRIPTOR physical_limit_map={EFI_MEMORY_CONVENTIONAL,0, + 0x0001000000000000ULL-0x2000ULL,0,4,0}; + BOB64_PAGE_EXTENT allocation_extents[2]; + EFI_MEMORY_DESCRIPTOR map[5]={0}; + BOB64_PAGE_EXTENT extents[4]; + BOB64_PAGE_ALLOCATOR allocator; + map[0].Type=EFI_MEMORY_CONVENTIONAL;map[0].PhysicalStart=0x10000;map[0].NumberOfPages=0x80; + map[1].Type=EFI_MEMORY_CONVENTIONAL;map[1].PhysicalStart=0x100000;map[1].NumberOfPages=4; + map[2].Type=EFI_MEMORY_CONVENTIONAL;map[2].PhysicalStart=0x104000;map[2].NumberOfPages=4; + map[3].Type=1;map[3].PhysicalStart=0x108000;map[3].NumberOfPages=4; + map[4].Type=EFI_MEMORY_CONVENTIONAL;map[4].PhysicalStart=0x100000000ULL;map[4].NumberOfPages=3; + CHECK(bob64_page_allocator_init(&allocator,extents,4,48,map,sizeof(map),sizeof(map[0]))==2, + "build physical extents from conventional descriptors"); + CHECK(extents[0].Base==0x100000&&extents[0].Pages==8, + "discard low memory and merge adjacent 4 KiB ranges"); + CHECK(extents[1].Base==0x100000000ULL&&extents[1].Pages==3, + "preserve physical ranges above 4 GiB"); + extended[0].Descriptor.Type=EFI_MEMORY_CONVENTIONAL; + extended[0].Descriptor.PhysicalStart=0x200000;extended[0].Descriptor.NumberOfPages=2; + extended[1].Descriptor.Type=EFI_MEMORY_CONVENTIONAL; + extended[1].Descriptor.PhysicalStart=0x100200000ULL;extended[1].Descriptor.NumberOfPages=2; + CHECK(bob64_page_allocator_init(&allocator,extents,4,48,extended,sizeof(extended), + sizeof(extended[0]))==2&&extents[1].Base==0x100200000ULL, + "walk firmware descriptors with a larger versioned stride"); + CHECK(bob64_page_allocator_init(&allocator,extents,1,48,map,sizeof(map),sizeof(map[0]))== + BOB64_PAGE_ALLOC_FULL,"reject maps with more runs than allocator storage"); + CHECK(bob64_page_allocator_init(&allocator,extents,4,48,map,sizeof(map),sizeof(map[0]))==2, + "reinitialize allocator after rejected capacity"); + u64 low=bob64_page_alloc(&allocator,6); + CHECK(low==0x100000&&extents[0].Base==0x106000&&extents[0].Pages==2, + "allocate contiguous 4 KiB pages"); + CHECK(bob64_page_alloc(&allocator,2)==0x106000, + "consume the remainder of a physical extent"); + u64 high=bob64_page_alloc(&allocator,2); + CHECK(high==0x100000000ULL&&high>0xffffffffULL, + "allocate a physical page address above 4 GiB without truncation"); + CHECK(bob64_page_alloc(&allocator,2)==0,"report physical page exhaustion"); + CHECK(!bob64_page_free(&allocator,low,6),"free an allocated range"); + CHECK(!bob64_page_free(&allocator,0x106000,2)&&allocator.Count==2&& + extents[0].Base==0x100000&&extents[0].Pages==8, + "merge adjacent freed ranges"); + CHECK(bob64_page_free(&allocator,low,1)==BOB64_PAGE_ALLOC_INVALID, + "reject double free of overlapping pages"); + CHECK(bob64_page_free(&allocator,0x200000,1)==BOB64_PAGE_ALLOC_INVALID, + "reject freeing a page not allocated by the manager"); + CHECK(bob64_page_free(&allocator,0x100001,1)==BOB64_PAGE_ALLOC_INVALID, + "reject unaligned physical frees"); + CHECK(!bob64_page_free(&allocator,high,2)&&extents[1].Pages==3, + "free high physical addresses without narrowing"); + CHECK(bob64_page_allocator_init(&allocator,extents,4,48,map,sizeof(map),sizeof(map[0])-1)== + BOB64_PAGE_ALLOC_INVALID,"reject short memory-map descriptors"); + CHECK(bob64_page_allocator_init(&allocator,extents,4,48,map,sizeof(map)-1,sizeof(map[0]))== + BOB64_PAGE_ALLOC_INVALID,"reject a truncated memory map"); + map[4].PhysicalStart=0xfffffffffffff000ULL;map[4].NumberOfPages=2; + CHECK(bob64_page_allocator_init(&allocator,extents,4,48,map,sizeof(map),sizeof(map[0]))== + BOB64_PAGE_ALLOC_INVALID,"reject overflowing 64-bit physical ranges"); + CHECK(bob64_page_allocator_init(&allocator,extents,4,48,&physical_limit_map, + sizeof(physical_limit_map),sizeof(physical_limit_map))==1&&extents[0].Pages==2, + "clip conventional memory at the CPUID physical-address limit"); + physical_limit_map.PhysicalStart=0x0001000000000000ULL; + CHECK(bob64_page_allocator_init(&allocator,extents,4,48,&physical_limit_map, + sizeof(physical_limit_map),sizeof(physical_limit_map))==0, + "exclude ranges beginning above the CPUID physical-address limit"); + CHECK(bob64_page_allocator_init(&allocator,allocation_extents,2,48,&allocation_map, + sizeof(allocation_map),sizeof(allocation_map))==1, + "initialize a large range for page-table-frame allocation"); + for(usize i=0;iPagesUsed>=4)return 0; + *region=arena->Bytes+arena->PagesUsed*4096; + *region_size=4096; + arena->PagesUsed++; + return 1; +} + +static int heap_tests(void) { + HEAP_TEST_ARENA arena={0}; + BOB64_HEAP heap; + u8 *small,*large,*zero,*coalesced; + CHECK(!bob64_heap_init(&heap,sizeof(arena.Bytes),heap_test_grow,&arena), + "initialize a bounded 64-bit heap"); + small=(u8 *)bob64_heap_alloc(&heap,65); + large=(u8 *)bob64_heap_alloc(&heap,9000); + zero=(u8 *)bob64_heap_calloc(&heap,32,2); + CHECK(small&&large&&zero&&((uintptr_t)small&15)==0&& + ((uintptr_t)large&15)==0&&((uintptr_t)zero&15)==0&& + bob64_heap_mapped_bytes(&heap)==3*4096, + "grow the heap in contiguous pages and align allocations"); + small[0]=0x64;large[8999]=0x32; + for(usize i=0;i<64;i++)CHECK(zero[i]==0,"calloc clears all requested bytes"); + CHECK(small[0]==0x64&&large[8999]==0x32, + "heap allocations remain distinct and writable"); + CHECK(!bob64_heap_free(&heap,small)&&!bob64_heap_free(&heap,large)&& + !bob64_heap_free(&heap,zero)&&bob64_heap_free(&heap,zero)<0&& + bob64_heap_free(&heap,arena.Bytes)<0, + "free blocks, reject double free, and reject non-allocation pointers"); + coalesced=(u8 *)bob64_heap_alloc(&heap,9000); + CHECK(coalesced&&((uintptr_t)coalesced&15)==0, + "coalesce adjacent free blocks for a larger allocation"); + CHECK(!bob64_heap_free(&heap,coalesced),"free the coalesced allocation"); + CHECK(!bob64_heap_calloc(&heap,(usize)-1,2),"reject calloc multiplication overflow"); + return 0; +} + +static int snapshot_tests(void) { + HEAP_TEST_ARENA arena={0}; + BOB64_HEAP heap; + BOB64_FILESYSTEM source,target; + u8 snapshot[512]; + usize size,written,length; + const char *contents; + CHECK(!bob64_heap_init(&heap,sizeof(arena.Bytes),heap_test_grow,&arena)&& + !bob64_fs_init(&source,&heap)&&!bob64_fs_init(&target,&heap), + "initialize B64S test filesystems"); + CHECK(!bob64_fs_write(&source,"alpha.txt","bob64",5)&& + !bob64_fs_write(&source,"empty.txt",0,0)&& + !bob64_fs_write(&source,"data-2","64 bit",6), + "seed B64S with text and empty files"); + CHECK(!bob64_fs_snapshot_size(&source,&size)&&size>8); +} + +static void exec_write32(u8 *bytes,u32 value) { + for(u32 i=0;i<4;i++)bytes[i]=(u8)(value>>(i*8)); +} + +static void exec_write64(u8 *bytes,u64 value) { + exec_write32(bytes,(u32)value);exec_write32(bytes+4,(u32)(value>>32)); +} + +static u32 exec_test_checksum(const u8 *bytes,usize length) { + u32 value=0xffffffffu; + for(usize i=0;i>1)^(0xedb88320u&-(value&1u)); + } + return ~value; +} + +static u64 BOB64_MS_ABI abi_sum4(u64 a,u64 b,u64 c,u64 d) { + return a+b*2+c*3+d*4; +} + +static u64 BOB64_MS_ABI abi_sum6(u64 a,u64 b,u64 c,u64 d,u64 e,u64 f) { + return abi_sum4(a,b,c,d)+e*5+f*6; +} + +static s64 BOB64_MS_ABI abi_test_entry(const BOB64_APP_STARTUP *startup) { + if(!startup||startup->StructSize!=sizeof(*startup)|| + startup->AbiVersion!=BOB64_APP_ABI_VERSION||startup->Flags|| + startup->ArgumentCount!=3||!startup->Arguments|| + strcmp(startup->Arguments[0],"program")|| + strcmp(startup->Arguments[1],"two words")|| + strcmp(startup->Arguments[2],"last"))return -1; + return 42; +} + +#define TEST_APP_FRAME_LIMIT 32 +typedef struct { + u64 PhysicalAddress,VirtualAddress,Flags; + u8 Allocated,Mapped; + u8 Bytes[BOB64_PAGE_SIZE]; +} TEST_APP_FRAME; + +typedef struct { + TEST_APP_FRAME Frames[TEST_APP_FRAME_LIMIT]; + u64 NextPhysical; + usize AllocationCount,FreeCount,MapCount,UnmapCount,MapAttempts,FailMapAt; +} TEST_APP_MEMORY; + +static u64 app_test_allocate(void *context) { + TEST_APP_MEMORY *memory=(TEST_APP_MEMORY *)context; + for(usize i=0;iFrames[i].Allocated) { + TEST_APP_FRAME *frame=&memory->Frames[i]; + frame->Allocated=1;frame->Mapped=0; + frame->PhysicalAddress=memory->NextPhysical; + memory->NextPhysical+=BOB64_PAGE_SIZE;memory->AllocationCount++; + return frame->PhysicalAddress; + } + return 0; +} + +static int app_test_free(void *context,u64 physical) { + TEST_APP_MEMORY *memory=(TEST_APP_MEMORY *)context; + for(usize i=0;iFrames[i]; + if(frame->Allocated&&frame->PhysicalAddress==physical) { + if(frame->Mapped)return -1; + frame->Allocated=0;memory->FreeCount++;return 0; + } + } + return -1; +} + +static int app_test_map(void *context,u64 virtual_address,u64 physical,u64 flags, + u8 **writable) { + TEST_APP_MEMORY *memory=(TEST_APP_MEMORY *)context; + memory->MapAttempts++; + if(memory->FailMapAt&&memory->MapAttempts==memory->FailMapAt)return -1; + for(usize i=0;iFrames[i]; + if(frame->Allocated&&frame->PhysicalAddress==physical) { + if(frame->Mapped)return -1; + frame->Mapped=1;frame->VirtualAddress=virtual_address;frame->Flags=flags; + *writable=frame->Bytes;memory->MapCount++;return 0; + } + } + return -1; +} + +static int app_test_unmap(void *context,u64 virtual_address) { + TEST_APP_MEMORY *memory=(TEST_APP_MEMORY *)context; + for(usize i=0;iFrames[i]; + if(frame->Mapped&&frame->VirtualAddress==virtual_address) { + frame->Mapped=0;memory->UnmapCount++;return 0; + } + } + return -1; +} + +static TEST_APP_FRAME *app_test_find(TEST_APP_MEMORY *memory,u64 address); + +static int app_test_protect(void *context,u64 virtual_address,u64 flags) { + TEST_APP_MEMORY *memory=(TEST_APP_MEMORY *)context; + TEST_APP_FRAME *frame=app_test_find(memory,virtual_address); + if(!frame)return -1; + frame->Flags=flags;return 0; +} + +static TEST_APP_FRAME *app_test_find(TEST_APP_MEMORY *memory,u64 address) { + u64 page=address&~(BOB64_PAGE_SIZE-1); + for(usize i=0;iFrames[i].Mapped&&memory->Frames[i].VirtualAddress==page) + return memory->Frames+i; + return 0; +} + +static int app_test_read(TEST_APP_MEMORY *memory,u64 address,void *destination,usize length) { + u8 *output=(u8 *)destination; + while(length) { + TEST_APP_FRAME *frame=app_test_find(memory,address); + usize offset=(usize)(address&(BOB64_PAGE_SIZE-1)); + usize part=(usize)BOB64_PAGE_SIZE-offset; + if(!frame)return -1; + if(part>length)part=length; + memcpy(output,frame->Bytes+offset,part); + output+=part;address+=part;length-=part; + } + return 0; +} + +static int process_loader_tests(const void *file,usize file_size) { + TEST_APP_MEMORY memory={.NextPhysical=0x100000000ULL}; + BOB64_PROCESS_PAGE pages[24]; + BOB64_PROCESS process; + BOB64_PROCESS_OPERATIONS operations={app_test_allocate,app_test_free, + app_test_map,app_test_protect,app_test_unmap,&memory,1}; + const char *arguments[]={"program","two words","last"}; + BOB64_APP_STARTUP startup; + u64 argv_pointer,return_address; + u64 argv[4]; + u8 zero_check[8183]; + char text[16]; + CHECK(!bob64_process_init(&process,pages,24,&operations)&& + !bob64_process_load(&process,file,file_size,3,arguments), + "load a B64E image into separate 64-bit user code, data, and stack pages"); + CHECK(process.Loaded&&process.EntryAddress==BOB64_PROCESS_IMAGE_BASE+1&& + process.PageCount==19&&process.StartupAddress&& + process.InitialStackPointer>=BOB64_PROCESS_STACK_BASE&& + (process.InitialStackPointer&15)==8&& + app_test_find(&memory,BOB64_PROCESS_STACK_GUARD)==0, + "place the entry, startup frame, and guarded stack in the 64-bit app layout"); + TEST_APP_FRAME *code=app_test_find(&memory,BOB64_PROCESS_IMAGE_BASE); + TEST_APP_FRAME *data=app_test_find(&memory,BOB64_PROCESS_IMAGE_BASE+BOB64_PAGE_SIZE); + TEST_APP_FRAME *stack=app_test_find(&memory,BOB64_PROCESS_STACK_BASE); + CHECK(code&&data&&stack&&code->PhysicalAddress>0xffffffffULL&& + (code->Flags&BOB64_PAGE_USER)&&!(code->Flags&BOB64_PAGE_WRITE)&& + !(code->Flags&BOB64_PAGE_NX)&&(data->Flags&BOB64_PAGE_WRITE)&& + (data->Flags&BOB64_PAGE_NX)&&(stack->Flags&BOB64_PAGE_USER)&& + (stack->Flags&BOB64_PAGE_WRITE)&&(stack->Flags&BOB64_PAGE_NX), + "enforce read-only executable code and writable non-executable user memory"); + CHECK(!app_test_read(&memory,process.StartupAddress,&startup,sizeof(startup))&& + startup.StructSize==sizeof(startup)&&startup.AbiVersion==BOB64_APP_ABI_VERSION&& + startup.ArgumentCount==3, + "construct the versioned startup structure in application memory"); + argv_pointer=(u64)(uintptr_t)startup.Arguments; + CHECK(!app_test_read(&memory,argv_pointer,argv,sizeof(argv))&&argv[3]==0, + "construct a 64-bit, null-terminated app argv array"); + CHECK(!app_test_read(&memory,argv[0],text,8)&&!strcmp(text,"program")&& + !app_test_read(&memory,argv[1],text,10)&&!strcmp(text,"two words")&& + !app_test_read(&memory,argv[2],text,5)&&!strcmp(text,"last"), + "copy argument strings into the app-owned stack"); + CHECK(!app_test_read(&memory,process.InitialStackPointer,&return_address, + sizeof(return_address))&&return_address==0&& + !app_test_read(&memory,process.EntryAddress+4104,zero_check,sizeof(zero_check)), + "set up the Microsoft x64 entry stack and zero data/BSS beyond the file image"); + for(usize i=0;iBytes+46:(const u8 *)"\0\0\0\0"); + CHECK(process.EntryAddress==BOB64_PROCESS_IMAGE_BASE&&process.PageCount==18&& + code&&data&&code->PhysicalAddress>0xffffffffULL&& + !(code->Flags&BOB64_PAGE_WRITE)&&!(code->Flags&BOB64_PAGE_NX)&& + (data->Flags&BOB64_PAGE_WRITE)&&(data->Flags&BOB64_PAGE_NX)&& + !memcmp(code->Bytes,"\x48\x83\xec\x28",4)&& + !memcmp(data->Bytes,"bob!",4)&& + string_address==BOB64_PROCESS_IMAGE_BASE+BOB64_PAGE_SIZE&& + string_address>0xffffffffULL, + "map compiler-generated machine code RX and string data RW/NX above 4 GiB"); + CHECK(!bob64_process_unload(&process)&&memory.AllocationCount==memory.FreeCount&& + memory.MapCount==memory.UnmapCount, + "release every page after unloading the compiler-produced app"); + return 0; +} + +static int executable_tests(void) { + u8 file[BOB64_EXEC_HEADER_SIZE+4096+9]={0}; + u8 loaded[12288],before[12288]; + BOB64_EXEC_IMAGE parsed; + const char *arguments[]={"program","two words","last",0}; + BOB64_APP_STARTUP startup={sizeof(startup),BOB64_APP_ABI_VERSION,3,arguments,0}; + BOB64_APP_ENTRY app_entry=abi_test_entry; + u64 entry=0; + CHECK(sizeof(BOB64_APP_STARTUP)==32&&app_entry(&startup)==42, + "pass a versioned app-owned startup block through the x64 entry ABI"); + CHECK(abi_sum6(1,2,3,4,5,6)==91, + "preserve Microsoft x64 register and stack arguments across nested calls"); + file[0]='B';file[1]='6';file[2]='4';file[3]='E'; + exec_write16(file+4,BOB64_EXEC_VERSION); + exec_write16(file+6,BOB64_EXEC_HEADER_SIZE); + exec_write32(file+8,BOB64_EXEC_ABI_VERSION); + exec_write64(file+16,4096+9);exec_write64(file+24,sizeof(loaded)); + exec_write64(file+32,1);exec_write64(file+40,4096); + memset(file+BOB64_EXEC_HEADER_SIZE,0x90,4096); + for(usize i=0;i<9;i++)file[BOB64_EXEC_HEADER_SIZE+4096+i]=(u8)(0xa0+i); + exec_write32(file+48,exec_test_checksum(file+BOB64_EXEC_HEADER_SIZE,4096+9)); + CHECK(!bob64_exec_parse(file,sizeof(file),&parsed)&&parsed.FileSize==4096+9&& + parsed.MemorySize==sizeof(loaded)&&parsed.EntryOffset==1&&parsed.CodeSize==4096&& + parsed.AbiVersion==BOB64_EXEC_ABI_VERSION, + "parse a bounded B64E image with a versioned 64-bit memory/entry layout"); + CHECK(process_loader_tests(file,sizeof(file))==0, + "B64E application loader maps, initializes, and releases user memory"); + memset(loaded,0xcc,sizeof(loaded)); + CHECK(!bob64_exec_load(&parsed,0x123456780000ULL,loaded,sizeof(loaded),&entry)&& + entry==0x123456780001ULL&&entry>0xffffffffULL&& + !memcmp(loaded,file+BOB64_EXEC_HEADER_SIZE,4096+9), + "load at a synthetic address above 4 GiB without truncating the entry"); + for(usize i=4096+9;iLength+1Text)) + output->Text[output->Length++]=*text++; + output->Text[output->Length]=0; +} + +static void shell_test_clear(void *context) { + SHELL_TEST_OUTPUT *output=(SHELL_TEST_OUTPUT *)context; + output->ClearCount++; +} + +static s64 shell_test_run(void *context,const char *name,usize argument_count, + const char *const *arguments,int *started) { + SHELL_TEST_OUTPUT *output=(SHELL_TEST_OUTPUT *)context; + usize name_length=strlen(name); + output->RunCount++;output->RunArgumentCount=argument_count; + if(name_length>=sizeof(output->RunName))return -1; + memcpy(output->RunName,name,name_length+1); + for(usize i=0;i=sizeof(output->RunArguments[i]))return -1; + memcpy(output->RunArguments[i],arguments[i],length+1); + } + *started=output->RunStarted; + return -7; +} + +static int shell_test_compile(void *context,const char *source,const char *output, + usize *error_offset) { + static u8 compiled[BOB64_COMPILER_IMAGE_LIMIT]; + SHELL_TEST_OUTPUT *result=(SHELL_TEST_OUTPUT *)context; + const char *source_text;usize source_length,compiled_length; + if(strlen(source)>=sizeof(result->CompileSource)|| + strlen(output)>=sizeof(result->CompileOutput)||!result->Filesystem|| + bob64_fs_read(result->Filesystem,source,&source_text,&source_length))return -1; + strcpy(result->CompileSource,source);strcpy(result->CompileOutput,output); + int compile_result=bob64_compile_c(source_text,source_length,compiled, + sizeof(compiled),&compiled_length,error_offset); + if(compile_result)return compile_result; + if(bob64_fs_write(result->Filesystem,output,compiled,compiled_length))return -1; + result->CompileCount++; + return 0; +} + +static void shell_test_command(BOB64_SHELL *shell,const char *command) { + while(*command)bob64_shell_input(shell,(u8)*command++); + bob64_shell_input(shell,'\n'); +} + +static usize count_text(const char *text,const char *needle) { + usize count=0,length=strlen(needle); + while((text=strstr(text,needle))!=0){count++;text+=length;} + return count; +} + +static int shell_tests(void) { + SHELL_TEST_OUTPUT output={0}; + BOB64_SHELL shell; + BOB64_PAGE_ALLOCATOR allocator={0}; + BOB64_PAGE_EXTENT extent={0x200000,3}; + HEAP_TEST_ARENA arena={0}; + BOB64_HEAP heap; + BOB64_FILESYSTEM filesystem; + const char *file_data; + usize file_length; + allocator.Count=1;allocator.Capacity=1;allocator.Extents=&extent; + allocator.AllocatedCount=1;allocator.Allocated[0].Pages=2; + CHECK(!bob64_heap_init(&heap,sizeof(arena.Bytes),heap_test_grow,&arena)&& + !bob64_fs_init(&filesystem,&heap)&& + !bob64_fs_write(&filesystem,"seed.txt","initial",7), + "initialize shell filesystem over the kernel heap"); + CHECK(!bob64_fs_read(&filesystem,"seed.txt",&file_data,&file_length)&& + file_length==7&&!strcmp(file_data,"initial")&& + !bob64_fs_write(&filesystem,"seed.txt","updated",7)&& + !bob64_fs_read(&filesystem,"seed.txt",&file_data,&file_length)&& + !strcmp(file_data,"updated"), + "read and atomically replace heap-backed text files"); + char binary_data[3]={'a',0,'b'}; + CHECK(!bob64_fs_write(&filesystem,"binary.b64e",binary_data,sizeof(binary_data))&& + !bob64_fs_read(&filesystem,"binary.b64e",&file_data,&file_length)&& + file_length==sizeof(binary_data)&&!memcmp(file_data,binary_data,sizeof(binary_data))&& + !bob64_fs_write(&filesystem,"seed.txt","updated",7), + "store arbitrary binary executable data without changing text files"); + CHECK(!bob64_shell_init(&shell,&allocator,&heap,&filesystem,shell_test_write, + shell_test_clear,&output),"initialize the command shell"); + output.Filesystem=&filesystem; + shell_test_command(&shell,"save"); + shell_test_command(&shell,"rm seed.txt"); + CHECK(filesystem.FileCount==1,"remove one file after creating a shell checkpoint"); + shell_test_command(&shell,"restore"); + CHECK(filesystem.FileCount==2&& + !bob64_fs_read(&filesystem,"seed.txt",&file_data,&file_length)&& + !strcmp(file_data,"updated"),"restore the shell B64S checkpoint"); + CHECK(!bob64_fs_read(&filesystem,"binary.b64e",&file_data,&file_length)&& + file_length==sizeof(binary_data)&&!memcmp(file_data,binary_data,sizeof(binary_data)), + "restore a binary executable file from B64S"); + shell_test_command(&shell,"cat binary.b64e"); + CHECK(strstr(output.Text,"a\\x00b")!=0, + "render embedded binary NUL bytes safely in the shell"); + shell_test_command(&shell,"eCho Bob!"); + CHECK(strstr(output.Text,"Bob!\r\n")!=0&&shell.Length==0, + "shell edits and executes case-insensitive commands"); + shell_test_command(&shell,"mem"); + CHECK(strstr(output.Text,"free pages=0x0000000000000003")!=0&& + strstr(output.Text,"allocated pages=0x0000000000000002")!=0&& + strstr(output.Text,"heap mapped=0x0000000000001000 bytes")!=0, + "shell reports physical allocator and heap statistics"); + shell_test_command(&shell,"write notes.txt bob64 is alive"); + shell_test_command(&shell,"cat notes.txt"); + CHECK(strstr(output.Text,"saved\r\n")!=0&& + strstr(output.Text,"bob64 is alive\r\n")!=0, + "shell creates and reads text files"); + shell_test_command(&shell,"ls"); + CHECK(strstr(output.Text,"notes.txt")!=0&&filesystem.FileCount==3, + "shell lists files backed by the kernel heap"); + shell_test_command(&shell,"rm notes.txt"); + CHECK(filesystem.FileCount==2&&filesystem.BytesUsed==10, + "shell deletes files and returns heap blocks"); + CHECK(!bob64_fs_delete(&filesystem,"binary.b64e"), + "remove the binary file after testing binary snapshot round-trip"); + usize streamed=0;u8 stream_buffer[8]; + CHECK(!bob64_fs_write(&filesystem,"stream.bin","abc",3)&& + !bob64_fs_read_at(&filesystem,"stream.bin",1,stream_buffer,2,&streamed)&& + streamed==2&&!memcmp(stream_buffer,"bc",2)&& + !bob64_fs_write_at(&filesystem,"stream.bin",5,"Z",1)&& + !bob64_fs_read(&filesystem,"stream.bin",&file_data,&file_length)&& + file_length==6&&!memcmp(file_data,"abc\0\0Z",6)&& + !bob64_fs_read_at(&filesystem,"stream.bin",6,stream_buffer,sizeof(stream_buffer),&streamed)&& + streamed==0&&bob64_fs_write_at(&filesystem,"stream.bin",~(u64)0,"x",1)<0&& + !bob64_fs_delete(&filesystem,"stream.bin"), + "stream file ranges with 64-bit offsets, sparse zero-fill, EOF and overflow checks"); + static const char resident_source[]= + "int main(void) { bob64_app_write(\"bob!\", 4); return 0; }"; + CHECK(!bob64_fs_write(&filesystem,"bob.c",resident_source, + sizeof(resident_source)-1), + "place resident C source in the shell filesystem"); + shell_test_command(&shell,"ab\bc"); + CHECK(strstr(output.Text,"unknown command: ac")!=0, + "shell backspace edits the command buffer"); + shell_test_command(&shell,"clear"); + CHECK(output.ClearCount==1&&strstr(output.Text,"bob64! kernel shell")!=0, + "clear command resets the display"); + shell_test_command(&shell,"help"); + CHECK(strstr(output.Text,"version show kernel version")!=0&& + strstr(output.Text,"restore restore RAM checkpoint")!=0&& + strstr(output.Text,"cc SOURCE [OUTPUT]")!=0&& + strstr(output.Text,"desktop.b64e [FILE]")!=0, + "help lists available commands"); + bob64_shell_set_runner(&shell,shell_test_run); + bob64_shell_set_compiler(&shell,shell_test_compile); + shell_test_command(&shell,"cc bob.c demo.b64e"); + CHECK(output.CompileCount==1&&!strcmp(output.CompileSource,"bob.c")&& + !strcmp(output.CompileOutput,"demo.b64e")&& + strstr(output.Text,"compiled to demo.b64e")!=0, + "shell routes source and destination to the resident compiler"); + const char *compiled_file;usize compiled_file_length;BOB64_EXEC_IMAGE compiled_image; + CHECK(!bob64_fs_read(&filesystem,"demo.b64e",&compiled_file,&compiled_file_length)&& + !bob64_exec_parse(compiled_file,compiled_file_length,&compiled_image)&& + !memcmp(compiled_image.Image+BOB64_PAGE_SIZE,"bob!",4), + "save the resident compiler's validated B64E output in the filesystem"); + output.RunStarted=1; + shell_test_command(&shell,"run demo.b64e first second"); + CHECK(output.RunCount==1&&output.RunArgumentCount==3&& + !strcmp(output.RunName,"demo.b64e")&& + !strcmp(output.RunArguments[0],"demo.b64e")&& + !strcmp(output.RunArguments[1],"first")&& + !strcmp(output.RunArguments[2],"second")&& + strstr(output.Text,"application exit status=0xfffffffffffffff9")!=0, + "launch a named app with argv and display its 64-bit exit status"); + output.RunStarted=0; + shell_test_command(&shell,"run missing.b64e"); + CHECK(output.RunCount==2&&strstr(output.Text,"unable to start application")!=0, + "report app loader failures without claiming an app was started"); + usize prompts=count_text(output.Text,"bob64> "); + for(const char *character="version";*character;character++) + bob64_shell_input(&shell,(u8)*character); + bob64_shell_input(&shell,'\r');bob64_shell_input(&shell,'\n'); + CHECK(count_text(output.Text,"bob64> ")==prompts+1&& + strstr(output.Text,"bob64 kernel 0.1")!=0, + "consume CRLF as one Enter key and execute one command"); + CHECK(bob64_fs_write(&filesystem,"../escape","x",1)<0&& + bob64_fs_write(&filesystem,"bad-name/part","x",1)<0, + "reject path separators in flat RAM filesystem names"); + return 0; +} + +static int contains_bytes(const u8 *bytes,usize length,const char *needle,usize needle_length) { + if(needle_length>length)return 0; + for(usize i=0;i<=length-needle_length;i++) + if(!memcmp(bytes+i,needle,needle_length))return 1; + return 0; +} + +int main(int argc,char **argv) { + FILE *file; + long file_size; + u8 *image; + u32 pe_offset,entry_rva,relocation_rva,relocation_size; + u16 sections,optional_size; + usize i; + int found_rdmsr=0; + uintptr_t synthetic=(uintptr_t)0x1234567887654321ULL; + + CHECK(argc>=2&&argc<=5,"expected BOOTX64.EFI and optional B64E app paths"); + CHECK(sizeof(void *)==8&&sizeof(uintptr_t)==8&&sizeof(usize)==8, + "the test and target use 64-bit pointers and sizes"); + CHECK(sizeof(char)==1&&sizeof(short)==2&&sizeof(int)==4&&sizeof(long long)==8, + "bob64 fixed-width scalar model"); + CHECK(libc_tests()==0,"bob64 C runtime tests"); + CHECK(compiler_tests()==0,"resident x86-64 C compiler tests"); + CHECK(compiler_arithmetic_tests()==0,"64-bit resident compiler arithmetic tests"); + CHECK(compiler_local_tests()==0,"resident compiler local-variable tests"); + CHECK(memory_tests()==0,"physical page allocator regression tests"); + CHECK(console_tests()==0,"GOP framebuffer console regression tests"); + CHECK(heap_tests()==0,"64-bit heap allocator regression tests"); + CHECK(snapshot_tests()==0,"versioned B64S snapshot regression tests"); + CHECK(executable_tests()==0,"versioned 64-bit native executable regression tests"); + CHECK(compiler_process_tests(resident_compiler_image, + resident_compiler_image_length)==0, + "resident compiler output integration with the process loader"); + CHECK(keyboard_tests()==0,"PS/2 keyboard scan-code regression tests"); + CHECK(mouse_tests()==0,"PS/2 mouse packet and pointer regression tests"); + CHECK(window_manager_tests()==0,"64-bit GUI window-manager regression tests"); + CHECK(window_server_tests()==0,"64-bit kernel window-server regression tests"); + CHECK(editor_tests()==0,"native GUI text-editor buffer regression tests"); + CHECK(shell_tests()==0,"interactive shell command regression tests"); + CHECK(paging_tests()==0,"four-level x86-64 page table regression tests"); + CHECK(process_address_space_tests()==0, + "isolated process page-table root regression tests"); + CHECK(bootstrap_tests()==0,"kernel bootstrap address-space regression tests"); + CHECK(cpu_tests()==0,"CPUID feature decoder regression tests"); + CHECK(descriptor_tests()==0,"64-bit GDT/IDT descriptor regression tests"); + CHECK(syscall_tests()==0,"versioned write and process-exit syscall tests"); + CHECK(syscall_context_tests()==0, + "nested syscall service contexts restore callbacks and enforce depth"); + CHECK(synthetic>0xffffffffu&&synthetic+0x1000u==0x1234567887655321ULL, + "synthetic pointer arithmetic preserves bits above 4 GiB"); + + file=fopen(argv[1],"rb");CHECK(file,"open UEFI image"); + CHECK(!fseek(file,0,SEEK_END),"seek UEFI image"); + file_size=ftell(file);CHECK(file_size>0&&file_size<16000000,"reasonable UEFI image size"); + CHECK(!fseek(file,0,SEEK_SET),"rewind UEFI image"); + image=(u8 *)malloc((usize)file_size);CHECK(image,"allocate image buffer"); + CHECK(fread(image,1,(usize)file_size,file)==(usize)file_size,"read UEFI image"); + CHECK(!fclose(file),"close UEFI image"); + CHECK(file_size>=64&&image[0]=='M'&&image[1]=='Z',"DOS-compatible PE header"); + pe_offset=read32(image+0x3c); + CHECK((u64)pe_offset+24u<=(u64)file_size,"PE header lies inside image"); + CHECK(image[pe_offset]=='P'&&image[pe_offset+1]=='E'&& + image[pe_offset+2]==0&&image[pe_offset+3]==0,"PE signature"); + CHECK(read16(image+pe_offset+4)==0x8664,"AMD64 machine type"); + sections=read16(image+pe_offset+6); + optional_size=read16(image+pe_offset+20); + CHECK(sections>0&&optional_size>=112,"PE32+ optional header is present"); + usize optional=(usize)pe_offset+24u; + CHECK(optional+(usize)optional_size<=(usize)file_size,"optional header bounds"); + CHECK(read16(image+optional)==0x20b,"PE32+ (64-bit) optional header"); + entry_rva=read32(image+optional+16); + CHECK(entry_rva!=0,"UEFI entry point is set"); + CHECK(read64(image+optional+24)!=0,"64-bit image base is represented"); + CHECK(read16(image+optional+68)==10,"EFI application subsystem"); + CHECK(read16(image+optional+70)&0x40,"UEFI image advertises relocatable loading"); + relocation_rva=read32(image+optional+112+5*8); + relocation_size=read32(image+optional+112+5*8+4); + CHECK(relocation_rva&&relocation_size>=8, + "PE image has a base relocation directory for firmware-selected load addresses"); + CHECK(contains_bytes(image,(usize)file_size,"B64E",4)&& + contains_bytes(image,(usize)file_size,"bob!",4)&& + contains_bytes(image,(usize)file_size,"int main(void)",14), + "embed the C-compiled app and resident compiler source in the kernel image"); + for(i=0;i+1<(usize)file_size;i++)if(image[i]==0x0f&&image[i+1]==0x32){found_rdmsr=1;break;} + CHECK(found_rdmsr,"image contains the EFER.LMA long-mode check"); + + if(argc>=3) { + BOB64_EXEC_IMAGE app; + unsigned char *app_file; + long app_file_size; + FILE *app_stream=fopen(argv[2],"rb"); + CHECK(app_stream,"open compiler-produced B64E application"); + CHECK(!fseek(app_stream,0,SEEK_END)&&(app_file_size=ftell(app_stream))>0&& + !fseek(app_stream,0,SEEK_SET),"measure compiler-produced B64E application"); + app_file=(unsigned char *)malloc((usize)app_file_size); + CHECK(app_file,"allocate compiler-produced B64E application buffer"); + CHECK(fread(app_file,1,(usize)app_file_size,app_stream)==(usize)app_file_size&& + !fclose(app_stream),"read compiler-produced B64E application"); + usize app_size=(usize)app_file_size; + CHECK(app_file,"read compiler-produced B64E application"); + CHECK(!bob64_exec_parse(app_file,app_size,&app)&& + app.AbiVersion==BOB64_APP_ABI_VERSION&&app.EntryOffset>0&& + app.CodeSize==BOB64_PAGE_SIZE&&app.FileSize>app.CodeSize&& + app.MemorySize>=app.FileSize&&app.MemorySize<=BOB64_PROCESS_IMAGE_LIMIT, + "parse compiler-produced B64E metadata and bounded memory layout"); + CHECK(app.Image[app.EntryOffset]==0x48&&app.Image[app.EntryOffset+1]==0x83&& + app.Image[app.EntryOffset+2]==0xec&&app.Image[app.EntryOffset+3]==0x28&& + contains_bytes(app.Image,(usize)app.FileSize,"bob!",4), + "preserve the x64 app entry stub and compiled message bytes"); + free(app_file); + } + + if(argc>=4) { + BOB64_EXEC_IMAGE app; + unsigned char *app_file; + long app_file_size; + FILE *app_stream=fopen(argv[3],"rb"); + CHECK(app_stream,"open graphics surface B64E application"); + CHECK(!fseek(app_stream,0,SEEK_END)&&(app_file_size=ftell(app_stream))>0&& + !fseek(app_stream,0,SEEK_SET),"measure graphics surface application"); + app_file=(unsigned char *)malloc((usize)app_file_size); + CHECK(app_file,"allocate graphics application buffer"); + CHECK(fread(app_file,1,(usize)app_file_size,app_stream)==(usize)app_file_size&& + !fclose(app_stream),"read graphics surface application"); + CHECK(!bob64_exec_parse(app_file,(usize)app_file_size,&app)&& + app.AbiVersion==BOB64_APP_ABI_VERSION&&app.EntryOffset>0&& + app.MemorySize>1024u*768u*sizeof(u32)&& + contains_bytes(app.Image,(usize)app.FileSize,"bob!",4), + "package a native graphics app with a full-screen frame and bob! output"); + free(app_file); + } + + if(argc==5) { + BOB64_EXEC_IMAGE app; + unsigned char *app_file; + long app_file_size; + FILE *app_stream=fopen(argv[4],"rb"); + CHECK(app_stream,"open multi-window desktop B64E application"); + CHECK(!fseek(app_stream,0,SEEK_END)&&(app_file_size=ftell(app_stream))>0&& + !fseek(app_stream,0,SEEK_SET),"measure desktop application"); + app_file=(unsigned char *)malloc((usize)app_file_size); + CHECK(app_file,"allocate desktop application buffer"); + CHECK(fread(app_file,1,(usize)app_file_size,app_stream)==(usize)app_file_size&& + !fclose(app_stream),"read desktop application"); + CHECK(!bob64_exec_parse(app_file,(usize)app_file_size,&app)&& + app.AbiVersion==BOB64_APP_ABI_VERSION&&app.EntryOffset>0&& + app.MemorySize>1024u*768u*sizeof(u32)&& + contains_bytes(app.Image,(usize)app.FileSize,"BOB64 DESKTOP",13)&& + contains_bytes(app.Image,(usize)app.FileSize,"CTRL S SAVE",11)&& + contains_bytes(app.Image,(usize)app.FileSize,"ESC AGAIN TO QUI",16)&& + contains_bytes(app.Image,(usize)app.FileSize,"notes.txt",9)&& + contains_bytes(app.Image,(usize)app.FileSize,"bob!",4), + "package a multi-window editor desktop with save support and bob! output"); + free(app_file); + } + + free(image); + puts("bob!"); + puts("64-bit UEFI image checks passed."); + return 0; +} diff --git a/tests/test_cpu.c b/tests/test_cpu.c index 4474a29..fe2b568 100644 --- a/tests/test_cpu.c +++ b/tests/test_cpu.c @@ -38,6 +38,27 @@ static void bad_image(const char *executable,const unsigned char *bytes,size_t l char command[4096];snprintf(command,sizeof(command),"\"%s\" --load-fixture build/cpu-bad.b32 > build/cpu-bad.out 2>&1",executable); verify(system(command)!=0,"invalid wide image rejected"); } +static void input_event_decoding(void) { + unsigned buttons=0;int type=0,value=0,x=0,y=0; + verify(terminalEventDecode(1,1,'a',65,0,0,0,&buttons,&type,&value,&x,&y) && + type==OS_EVENT_CHAR&&value=='a',"event decoder returns typed characters"); + verify(terminalEventDecode(1,0,'a',65,0,0,0,&buttons,&type,&value,&x,&y) && + type==OS_EVENT_KEY_UP&&value=='a',"event decoder returns character key releases"); + verify(terminalEventDecode(1,1,0,38,0,0,0,&buttons,&type,&value,&x,&y) && + type==OS_EVENT_KEY_DOWN&&value==256,"event decoder normalizes special keys"); + verify(terminalEventDecode(2,1,0,0,17,9,0,&buttons,&type,&value,&x,&y) && + type==OS_EVENT_MOUSE_MOVE&&x==17&&y==9,"event decoder reports mouse coordinates"); + verify(terminalEventDecode(2,0,0,0,17,9,1,&buttons,&type,&value,&x,&y) && + type==OS_EVENT_MOUSE_BUTTON_DOWN&&value==1&&buttons==1,"event decoder reports button press"); + verify(!terminalEventDecode(2,0,0,0,17,9,1,&buttons,&type,&value,&x,&y), + "event decoder filters unchanged mouse button state"); + verify(terminalEventDecode(2,0,0,0,18,9,0,&buttons,&type,&value,&x,&y) && + type==OS_EVENT_MOUSE_BUTTON_UP&&value==0&&buttons==0,"event decoder reports button release"); + verify(terminalEventDecode(2,0,4,0,18,9,120u<<16,&buttons,&type,&value,&x,&y) && + type==OS_EVENT_MOUSE_WHEEL&&value==120&&x==18&&y==9,"event decoder reports upward mouse-wheel delta"); + verify(terminalEventDecode(2,0,4,0,18,9,0xff880000u,&buttons,&type,&value,&x,&y) && + type==OS_EVENT_MOUSE_WHEEL&&value==-120,"event decoder reports downward mouse-wheel delta"); +} int main(int argc,char **argv) { if(argc>1 && !strcmp(argv[1],"--emulator"))return bob_emulator_main(argc-1,argv+1); if(argc==3 && !strcmp(argv[1],"--load-fixture")){bootImage(argv[2]);return 0;} @@ -54,6 +75,7 @@ int main(int argc,char **argv) { memoryWrite(0x10003,'b');memoryWrite(0x10004,'!');step(0xf200); return cpu.ir==0xf200?0:1; } + input_event_decoding(); for(unsigned bits=1;bits<=16;bits++) { verify(sext((int16_t)((1u<>(8*i))&255,old_snapshot)==EOF)return 1; - if(fseek(old_snapshot,16,SEEK_SET))return 1; - for(unsigned i=0;i>(8*b))&255,old_snapshot)==EOF)return 1; if(fclose(old_snapshot))return 1; - ram.memory[0xf000]=0;ram.memory[0xf002]=0; - verify(snapshotService(0x300,1)==0 && ram.memory[0xf000]==0x12345678 && ram.memory[0xf002]=='b',"legacy fixed-slot B32S snapshot converts to packed filesystem layout"); + FILE *old_write=fopen("build/cpu-snapshot.b32","wb");if(!old_write)return 1; + uint32_t old_hash=snapshotHash(old_words,SNAP_WORDS);unsigned char old_header[16]={'B','3','2','S',2,0,0,0}; + for(unsigned i=0;i<4;i++){old_header[8+i]=(unsigned char)(kernelIdentity>>(8*i));old_header[12+i]=(unsigned char)(old_hash>>(8*i));} + if(fwrite(old_header,1,16,old_write)!=16)return 1; + for(unsigned i=0;i>(8*b))&255,old_write)==EOF)return 1; + if(fclose(old_write))return 1; + memoryWrite(WIDE_FILE_BASE,0);memoryWrite(WIDE_FILE_BASE+2,0); + verify(snapshotService(0x300,1)==0 && memoryRead(WIDE_FILE_BASE)==0x12345678 && memoryRead(WIDE_FILE_BASE+2)=='b',"B32S v2 packed snapshot restores into expanded storage"); + uint32_t fixed_native[2]={old_words[216],old_words[217]},fixed_text[5]; + for(unsigned i=0;i<5;i++)fixed_text[i]=old_words[218+i]; + memset(old_words+216,0,SNAP_OLD_FILE_WORDS*sizeof(uint32_t)); + for(unsigned i=0;i<2;i++)old_words[216+i]=fixed_native[i]; + for(unsigned i=0;i<5;i++)old_words[216+512+i]=fixed_text[i]; + old_hash=snapshotHash(old_words,SNAP_WORDS);old_header[4]=1; + for(unsigned i=0;i<4;i++)old_header[12+i]=(unsigned char)(old_hash>>(8*i)); + old_write=fopen("build/cpu-snapshot.b32","wb");if(!old_write)return 1; + if(fwrite(old_header,1,16,old_write)!=16)return 1; + for(unsigned i=0;i>(8*b))&255,old_write)==EOF)return 1; + if(fclose(old_write))return 1; + memoryWrite(WIDE_FILE_BASE,0);memoryWrite(WIDE_FILE_BASE+2,0); + verify(snapshotService(0x300,1)==0 && memoryRead(WIDE_FILE_BASE)==0x12345678 && memoryRead(WIDE_FILE_BASE+2)=='b',"B32S v1 fixed-slot snapshot converts into expanded packed storage"); cpu32=false;ram.memory[0xf000]=42; verify(snapshotService(0x300,1)==-2 && ram.memory[0xf000]==42,"legacy rejects wide snapshot without modifying RAM"); cpu32=true;kernelIdentity++; verify(snapshotService(0x300,1)==1,"wide snapshot reports changed kernel identity"); - verify(ram.memory[0x520]==0 && ram.memory[0x521]==1 && ram.memory[0xf000]=='b' && ram.memory[0xf003]=='!',"wide kernel change drops binaries and preserves text"); + verify(ram.memory[0x520]==0 && ram.memory[0x521]==1 && memoryRead(WIDE_FILE_BASE)=='b' && memoryRead(WIDE_FILE_BASE+3)=='!',"wide kernel change drops binaries and preserves text"); kernelIdentity--; if(storage_path(""))return 1; - uint32_t snapshot[SNAP_WORDS]={0}; + uint32_t snapshot[SNAP_WIDE_WORDS]={0}; verify(snapshotValid(snapshot),"empty snapshot metadata"); snapshot[0]='b';snapshot[1]='o';snapshot[2]='b';snapshot[3]='!';snapshot[192]=4;snapshot[208]=1; snapshot[216]='b';snapshot[217]='o';snapshot[218]='b';snapshot[219]='!'; verify(snapshotValid(snapshot),"valid text snapshot metadata"); snapshot[218]=0;verify(!snapshotValid(snapshot),"text snapshot rejects embedded terminator");snapshot[218]='b'; snapshot[220]=1;verify(!snapshotValid(snapshot),"snapshot rejects missing content terminator");snapshot[220]=0; - snapshot[192]=512;verify(!snapshotValid(snapshot),"snapshot rejects excessive length");snapshot[192]=4; + snapshot[192]=SNAP_FILE_WORDS;verify(!snapshotValid(snapshot),"snapshot rejects excessive length");snapshot[192]=4; snapshot[208]=2;verify(!snapshotValid(snapshot),"snapshot rejects invalid used flag");snapshot[208]=1; snapshot[200]=2;verify(snapshotValid(snapshot),"bob32 snapshots accept native program files"); snapshot[200]=4;verify(!snapshotValid(snapshot),"snapshot rejects invalid kind");snapshot[200]=0; @@ -342,15 +378,15 @@ int main(int argc,char **argv) { reset_cpu(1);ram.memory[0x300]=0xf000;ram.memory[0x301]=7; ram.memory[0xf000]=0x4233324b;ram.memory[0xf001]=0x00180002;ram.memory[0xf002]=0x20000;ram.memory[0xf003]=0x20000; ram.memory[0xf004]=1;ram.memory[0xf005]=0xe000;ram.memory[0xf006]=0xe000; - verify(runWidePackedFromGuest(0x300)==0,"native app loads and executes from packed guest RAM image"); + verify(runWidePackedFromGuest(0x300,NULL)==0,"native app loads and executes from packed guest RAM image"); reset_cpu(1);ram.memory[0x300]=0xf000;ram.memory[0x301]=7; ram.memory[0xf000]=0x4233324b;ram.memory[0xf001]=0x00180002;ram.memory[0xf002]=0x20000;ram.memory[0xf003]=0x20000; ram.memory[0xf004]=1;ram.memory[0xf005]=0xe000;ram.memory[0xf006]=0; - verify(runWidePackedFromGuest(0x300)==-4,"native app checksum corruption rejected before execution"); + verify(runWidePackedFromGuest(0x300,NULL)==-4,"native app checksum corruption rejected before execution"); reset_cpu(1);ram.memory[0x300]=0xf000;ram.memory[0x301]=7; ram.memory[0xf000]=0x4233324b;ram.memory[0xf001]=0x00180002;ram.memory[0xf002]=0x20000;ram.memory[0xf003]=0x20000; ram.memory[0xf004]=1;ram.memory[0xf005]=0xe000;ram.memory[0xf006]=0xe000;failNextSparsePageAllocation=1; - verify(runWidePackedFromGuest(0x300)==-5 && memoryPage(0x10,0)==NULL,"native app reports insufficient sparse memory without partial load"); + verify(runWidePackedFromGuest(0x300,NULL)==-5 && memoryPage(0x10,0)==NULL,"native app reports insufficient sparse memory without partial load"); f=fopen("build/cpu-import.b32","wb");if(!f)return 1; fwrite("B32K",1,4,f);put16(f,2);put16(f,24);put32(f,0x20000);put32(f,0x20000);put32(f,1);put32(f,0xe000);put32(f,0xe000);if(fclose(f))return 1; reset_cpu(1);const char *import_path="build/cpu-import.b32"; @@ -360,7 +396,7 @@ int main(int argc,char **argv) { ram.memory[0x302]=8; verify(importWideImageFromGuest(0x300)==7 && ram.memory[0xf006]==0xe000,"native image import validates and packs a B32K v2 image"); ram.memory[0x310]=0xf000;ram.memory[0x311]=7; - verify(runWidePackedFromGuest(0x310)==0,"imported native image executes from packed filesystem storage"); + verify(runWidePackedFromGuest(0x310,NULL)==0,"imported native image executes from packed filesystem storage"); bootImage("build/kernel.b16");verify(!cpu32,"legacy image selects compatibility mode"); f=fopen("build/cpu-input.basm","w");if(!f)return 1; fputs("lea r0 2\ntrap 2\ntrap 0\n.stringz bob!\n",f);fclose(f); diff --git a/tests/test_os.c b/tests/test_os.c index 0a0a4ab..89ae7d6 100644 --- a/tests/test_os.c +++ b/tests/test_os.c @@ -54,9 +54,9 @@ static void guest32(const char *source) { write_text("build/wide-lib.c",source); check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/wide-lib.c -o build/wide-lib.i > build/compiler.log 2>&1")==0,"bob32 library guest preprocessing"); check(system(COMPILER " build/wide-lib.i build/wide-lib.basm build/wide-lib.b32 --wide > build/compiler.log 2>&1")==0,"bob32 library guest compilation"); - write_text("build/check.in",""); - check(system(BOB32 " --boot build/wide-lib.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"bob32 library guest execution"); - char *output=read_text("build/check.out");check(!strcmp(output,"bob!\n"),"bob32 library success marker");free(output); + write_text("build/check.in","run32 build/wide-lib.b32\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"bob32 library guest execution under OS services"); + char *output=read_text("build/check.out");contains(output,"bob!");free(output); } static void native_string_library(void) { guest32( @@ -96,15 +96,305 @@ static void native_string_library(void) { check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"bob32 string-library app survives snapshot restore"); output=read_text("build/check.out");contains(output,"Files restored;");contains(output,"bob> bob!\nExit 0");free(output); write_text("build/argv-app.c", - "#include \"bob.h\"\n#include \"bob_string.h\"\n" - "int main(int argc,char **argv){if(argc!=5)return argc;" + "#include \"bob.h\"\n#include \"bob_string.h\"\n#include \"bob_fs.h\"\n" + "int main(int argc,char **argv){char data[16];char name[24];int size;int kind;int i;int old;" + "if(argc!=4)return argc;" "if(bob_strcmp(argv[0],\"argvapp\")||bob_strcmp(argv[1],\"Bob OS\")||bob_strcmp(argv[2],\"escaped token\")||bob_strcmp(argv[3],\"\"))return 2;" + "old=bob_file_read(\"note\",data,16);if(old>=0&&(old!=4||bob_strcmp(data,\"bob!\")))return 3;" + "if(old<0&&bob_file_write(\"note\",\"bob!\",4))return 4;" + "if(bob_file_read(\"note\",data,16)!=4||bob_strcmp(data,\"bob!\"))return 5;" + "if(bob_file_write(\"temp\",\"x\",1)||bob_file_delete(\"temp\"))return 6;" + "for(i=0;i<8;i++){kind=bob_file_list(i,name,24,&size);if(kind<0)continue;" + "if(!bob_strcmp(name,\"note\")){if(kind||size!=4)return 7;break;}}if(i==8)return 8;" "bob_puts(\"bob!\");return 0;}\n"); check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/argv-app.c -o build/argv-app.i > build/compiler.log 2>&1")==0,"bob32 argv app preprocessing"); check(system(COMPILER " build/argv-app.i build/argv-app.basm build/argv-app.b32 --wide-app > build/compiler.log 2>&1")==0,"bob32 argv app compilation"); write_text("build/check.in","import32 build/argv-app.b32 argvapp\nrun argvapp \"Bob OS\" escaped\\ token \"\"\nhalt\n"); check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"bob32 passes quoted arguments to native apps"); output=read_text("build/check.out");contains(output,"bob> bob!\nExit 0");free(output); + write_text("build/memory-app.c", + "#include \"bob.h\"\n#include \"bob_memory.h\"\n" + "int main(void){int storage[8];int used=0;int *first;int *second;" + "first=bob_arena_alloc(storage,8,&used,3);second=bob_arena_alloc(storage,8,&used,5);" + "if(first!=storage||second!=storage+3)return 2;first[2]=42;" + "if(first[2]!=42||bob_arena_used(&used)!=8||bob_arena_remaining(8,&used)!=0)return 3;" + "if(bob_arena_alloc(storage,8,&used,1)||bob_arena_alloc(storage,8,&used,0)||bob_arena_alloc(storage,8,&used,-1))return 4;" + "if(bob_arena_reset(&used)||bob_arena_used(&used)||bob_arena_remaining(8,&used)!=8)return 5;" + "if(bob_arena_alloc(storage,8,&used,8)!=storage)return 6;bob_puts(\"bob!\");return 0;}\n"); + check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/memory-app.c -o build/memory-app.i > build/compiler.log 2>&1")==0,"bob32 app arena fixture preprocessing"); + check(system(COMPILER " build/memory-app.i build/memory-app.basm build/memory-app.b32 --wide-app > build/compiler.log 2>&1")==0,"bob32 app arena fixture compilation"); + write_text("build/check.in","import32 build/memory-app.b32 memoryapp\nrun memoryapp\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"native word arena allocates, bounds-checks and resets caller-owned storage"); + output=read_text("build/check.out");contains(output,"bob> bob!\nExit 0");free(output); + write_text("build/time-app.c", + "#include \"bob.h\"\n#include \"bob_time.h\"\n" + "int main(void){int words[2];if(bob_time_utc_seconds(words)!=2)return 1;" + "if(words[0]<=0||words[1]<0||words[1]>1000)return 2;" + "bob_puts(\"bob!\");return 0;}\n"); + check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/time-app.c -o build/time-app.i > build/compiler.log 2>&1")==0,"bob32 time app preprocessing"); + check(system(COMPILER " build/time-app.i build/time-app.basm build/time-app.b32 --wide-app > build/compiler.log 2>&1")==0,"bob32 time app compilation"); + write_text("build/word-fs-app.c", + "#include \"bob.h\"\n#include \"bob_fs.h\"\n#include \"bob_string.h\"\n" + "int main(int argc,char **argv){int source[3]={0x12345678,-1,0};int data[3];char name[24];int size;int kind;int i;int stored;" + "stored=bob_file_read_words(\"binary\",data,3);if(stored<0){if(argc!=2||bob_strcmp(argv[1],\"create\"))return 1;" + "if(bob_file_write_words(\"binary\",source,3,BOB_FILE_KIND_BOB32_PROGRAM))return 1;}else if(stored!=3)return 1;" + "if(bob_file_read_words(\"binary\",data,2)!=-2)return 2;" + "if(bob_file_read_words(\"binary\",data,3)!=3||data[0]!=source[0]||data[1]!=-1||data[2]!=0)return 3;" + "for(i=0;i<8;i++){kind=bob_file_list(i,name,24,&size);if(kind<0)continue;if(!bob_strcmp(name,\"binary\"))break;}" + "if(i==8||kind!=BOB_FILE_KIND_BOB32_PROGRAM||size!=3)return 4;" + "if(argc==1&&bob_file_delete(\"binary\"))return 5;bob_puts(\"bob!\");return 0;}\n"); + check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/word-fs-app.c -o build/word-fs-app.i > build/compiler.log 2>&1")==0,"native word filesystem fixture preprocessing"); + check(system(COMPILER " build/word-fs-app.i build/word-fs-app.basm build/word-fs-app.b32 --wide-app > build/compiler.log 2>&1")==0,"native word filesystem fixture compilation"); + storage_path("build/word-fs-snapshot.b32"); + write_text("build/check.in","import32 build/word-fs-app.b32 wordfs\nrun wordfs create\nsave\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"native filesystem writes binary program words into the snapshot"); + output=read_text("build/check.out");contains(output,"bob> bob!\nExit 0");free(output); + write_text("build/check.in","restore yes\nrun wordfs\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"binary program words survive snapshot restore and can be deleted by a native app"); + output=read_text("build/check.out");contains(output,"Files restored;");contains(output,"bob> bob!\nExit 0");free(output); + write_text("build/check.in","import32 build/time-app.b32 timeapp\nrun timeapp\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"native app reads UTC time through the versioned OS service"); + output=read_text("build/check.out");contains(output,"bob> bob!\nExit 0");free(output); + write_text("build/native-api-app.c", + "#include \"bob_native.h\"\n" + "int main(void){char text[8]=\"bob\";char loaded[8];int arena_words[4];int used=0;int clock_words[2];" + "if(bob_strcat(text,\"!\")!=text)return 1;" + "if(bob_arena_alloc(arena_words,4,&used,2)!=arena_words||used!=2)return 2;" + "if(bob_file_write(\"umbrella\",text,bob_strlen(text)))return 3;" + "if(bob_file_read(\"umbrella\",loaded,8)!=4||bob_strcmp(loaded,\"bob!\"))return 4;" + "if(bob_time_utc_seconds(clock_words)!=2||clock_words[0]<=0)return 5;" + "if(bob_file_delete(\"umbrella\"))return 6;bob_puts(\"bob!\");return 0;}\n"); + check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/native-api-app.c -o build/native-api-app.i > build/compiler.log 2>&1")==0,"common native API umbrella preprocessing"); + check(system(COMPILER " build/native-api-app.i build/native-api-app.basm build/native-api-app.b32 --wide-app > build/compiler.log 2>&1")==0,"common native API umbrella compilation"); + write_text("build/check.in","import32 build/native-api-app.b32 nativeapi\nrun nativeapi\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"native API umbrella works end to end across common services"); + output=read_text("build/check.out");contains(output,"bob> bob!\nExit 0");free(output); + storage_path("build/snapshot.b16"); +} +static void native_gui_geometry(void) { + guest32( + "#include \"bob.h\"\n#include \"bob_gui.h\"\n#include \"bob_event_queue.h\"\n" + "int main(void){int rect[4]={3,3,34,12};int drag[3]={0,0,0};" + "int button[4]={5,5,10,3};int state[2]={0,0};int event[4]={0,0,7,6};" + "int field[4]={5,5,8,3};int edit[3];char text[16]=\"bob\";char long_text[8]=\"\";int long_edit[3];" + "int area[4]={5,5,12,5};int area_state[4];char multiline[32]=\"ab\\ncd\";" + "int wheel_state[4];char wheel_text[32]=\"1\\n2\\n3\\n4\\n5\";" + "int stack[8]={0,0,10,10,5,5,10,10};int order[2]={0,1};" + "int menu[4]={10,5,20,5};int menu_state[2]={0,-1};int placed[4];" + "int queue_state[2],queue_storage[12],queued[4],dequeued[4];" + "int wm[10],wm_windows[21],wm_order[3],wm_routed[4],wm_a,wm_b;" + "if(!bob_gui_window_hit(3,3,rect)||bob_gui_window_hit(37,3,rect))return 1;" + "if(bob_gui_window_at(6,6,stack,order,2)!=1||!bob_gui_raise_window(order,2,0)||bob_gui_window_at(6,6,stack,order,2)!=0)return 19;" + "if(order[0]!=1||order[1]!=0||bob_gui_raise_window(order,2,3)||bob_gui_window_at(20,20,stack,order,2)!=-1)return 20;" + "if(!bob_gui_drag_start(rect,drag,8,3)||!drag[0]||drag[1]!=5)return 2;" + "if(!bob_gui_drag_update(rect,drag,15,9,80,25)||rect[0]!=10||rect[1]!=9)return 3;" + "bob_gui_drag_update(rect,drag,200,40,80,25);" + "if(rect[0]!=46||rect[1]!=13)return 4;" + "if(!bob_gui_drag_stop(drag)||bob_gui_drag_update(rect,drag,0,0,80,25))return 5;" + "if(bob_gui_drag_start(rect,drag,47,14))return 6;" + "event[0]=BOB_EVENT_MOUSE_MOVE;if(bob_gui_button_event(button,state,event)||!state[0])return 7;" + "event[0]=BOB_EVENT_MOUSE_BUTTON_DOWN;event[1]=BOB_MOUSE_BUTTON_RIGHT;" + "if(bob_gui_button_event(button,state,event)||state[1])return 8;" + "event[1]=BOB_MOUSE_BUTTON_LEFT;if(bob_gui_button_event(button,state,event)||!state[1])return 9;" + "event[0]=BOB_EVENT_MOUSE_BUTTON_UP;event[1]=0;" + "if(!bob_gui_button_event(button,state,event)||state[1])return 10;" + "event[0]=BOB_EVENT_MOUSE_BUTTON_DOWN;event[1]=BOB_MOUSE_BUTTON_LEFT;bob_gui_button_event(button,state,event);" + "event[0]=BOB_EVENT_MOUSE_BUTTON_UP;event[1]=0;event[2]=20;" + "if(bob_gui_button_event(button,state,event)||state[1])return 11;" + "if(bob_gui_text_field_init(text,edit,16)!=3||edit[1]!=3)return 12;" + "event[0]=BOB_EVENT_MOUSE_BUTTON_DOWN;event[2]=7;event[3]=6;" + "bob_gui_text_field_event(field,text,edit,16,event);if(!edit[0]||edit[1]!=1)return 13;" + "event[0]=BOB_EVENT_CHAR;event[1]='!';" + "if(!bob_gui_text_field_event(field,text,edit,16,event)||text[0]!='b'||text[1]!='!'||text[2]!='o')return 14;" + "event[0]=BOB_EVENT_KEY_DOWN;event[1]=259;bob_gui_text_field_event(field,text,edit,16,event);" + "event[0]=BOB_EVENT_CHAR;event[1]=8;bob_gui_text_field_event(field,text,edit,16,event);" + "if(text[0]!='b'||text[1]!='!'||text[2]!='b'||text[3])return 15;" + "event[0]=BOB_EVENT_KEY_DOWN;event[1]=260;bob_gui_text_field_event(field,text,edit,16,event);" + "event[1]=262;bob_gui_text_field_event(field,text,edit,16,event);if(text[0]!='!'||text[1]!='b'||text[2])return 16;" + "event[0]=BOB_EVENT_MOUSE_BUTTON_DOWN;event[2]=20;bob_gui_text_field_event(field,text,edit,16,event);" + "event[0]=BOB_EVENT_CHAR;event[1]='x';bob_gui_text_field_event(field,text,edit,16,event);" + "if(edit[0]||text[0]!='!'||text[1]!='b')return 17;" + "bob_gui_text_field_init(long_text,long_edit,8);long_edit[0]=1;" + "for(int i=0;i<7;i++){event[0]=BOB_EVENT_CHAR;event[1]='a'+i;bob_gui_text_field_event(field,long_text,long_edit,8,event);}" + "if(long_edit[1]!=7||long_edit[2]!=2||long_text[7])return 18;" + "if(bob_gui_text_area_init(multiline,area_state,32)!=5||area_state[1]!=5||area_state[2]!=0)return 21;" + "event[0]=BOB_EVENT_MOUSE_BUTTON_DOWN;event[1]=BOB_MOUSE_BUTTON_LEFT;event[2]=8;event[3]=7;" + "bob_gui_text_area_event(area,multiline,area_state,32,event);if(!area_state[0])return 26;" + "event[0]=BOB_EVENT_KEY_DOWN;event[1]=256;bob_gui_text_area_event(area,multiline,area_state,32,event);" + "if(area_state[1]!=2)return 22;event[0]=BOB_EVENT_CHAR;event[1]='X';bob_gui_text_area_event(area,multiline,area_state,32,event);" + "if(multiline[0]!='a'||multiline[1]!='b'||multiline[2]!='X'||multiline[3]!='\\n')return 23;" + "event[0]=BOB_EVENT_KEY_DOWN;event[1]=257;bob_gui_text_area_event(area,multiline,area_state,32,event);" + "if(area_state[1]!=6)return 24;event[0]=BOB_EVENT_CHAR;event[1]=8;bob_gui_text_area_event(area,multiline,area_state,32,event);" + "if(multiline[4]!='c'||multiline[5])return 25;" + "if(bob_gui_text_area_init(wheel_text,wheel_state,32)!=9)return 27;" + "bob_gui_text_area_reveal(wheel_text,wheel_state,area);if(wheel_state[2]!=2)return 28;" + "event[0]=BOB_EVENT_MOUSE_WHEEL;event[1]=120;event[2]=6;event[3]=6;" + "bob_gui_text_area_event(area,wheel_text,wheel_state,32,event);if(wheel_state[2]!=1)return 29;" + "bob_gui_text_area_event(area,wheel_text,wheel_state,32,event);if(wheel_state[2]!=0)return 30;" + "bob_gui_text_area_event(area,wheel_text,wheel_state,32,event);if(wheel_state[2]!=0)return 31;" + "event[1]=-120;bob_gui_text_area_event(area,wheel_text,wheel_state,32,event);" + "bob_gui_text_area_event(area,wheel_text,wheel_state,32,event);if(wheel_state[2]!=2)return 32;" + "bob_gui_text_area_event(area,wheel_text,wheel_state,32,event);if(wheel_state[2]!=2)return 33;" + "bob_event_queue_init(queue_state);if(bob_event_queue_pop(queue_state,queue_storage,3,dequeued)!=0)return 42;" + "event[0]=BOB_EVENT_KEY_DOWN;event[1]=257;event[2]=11;event[3]=12;" + "if(bob_event_queue_push(queue_state,queue_storage,3,event)!=1)return 43;" + "event[1]=258;if(bob_event_queue_push(queue_state,queue_storage,3,event)!=1)return 44;" + "event[1]=259;if(bob_event_queue_push(queue_state,queue_storage,3,event)!=1)return 45;" + "if(bob_event_queue_push(queue_state,queue_storage,3,event)!=0)return 46;" + "if(bob_event_queue_pop(queue_state,queue_storage,3,dequeued)!=1||dequeued[1]!=257||dequeued[2]!=11)return 47;" + "event[1]=260;if(bob_event_queue_push(queue_state,queue_storage,3,event)!=1)return 48;" + "if(bob_event_queue_pop(queue_state,queue_storage,3,dequeued)!=1||dequeued[1]!=258)return 49;" + "if(bob_event_queue_pop(queue_state,queue_storage,3,dequeued)!=1||dequeued[1]!=259)return 50;" + "if(bob_event_queue_pop(queue_state,queue_storage,3,dequeued)!=1||dequeued[1]!=260)return 51;" + "if(bob_event_queue_pop(queue_state,queue_storage,3,dequeued)!=0)return 52;" + "if(bob_event_queue_push(queue_state,queue_storage,0,event)!=-1)return 53;" + "if(bob_wm_init(wm,wm_windows,wm_order,3,80,25))return 54;" + "wm_a=bob_wm_create(wm,wm_windows,wm_order,5,5,20,10);wm_b=bob_wm_create(wm,wm_windows,wm_order,10,8,20,10);" + "if(wm_a!=0||wm_b!=1||wm[2]!=wm_b||wm_order[0]!=wm_a||wm_order[1]!=wm_b)return 55;" + "event[0]=BOB_EVENT_KEY_DOWN;event[1]=256;if(bob_wm_dispatch(wm,wm_windows,wm_order,event,wm_routed)!=wm_b)return 56;" + "event[0]=BOB_EVENT_MOUSE_BUTTON_DOWN;event[1]=BOB_MOUSE_BUTTON_LEFT;event[2]=12;event[3]=9;" + "if(bob_wm_dispatch(wm,wm_windows,wm_order,event,wm_routed)!=wm_b||wm[2]!=wm_b||wm_routed[2]!=2||wm_routed[3]!=1)return 57;" + "event[2]=6;event[3]=6;if(bob_wm_dispatch(wm,wm_windows,wm_order,event,wm_routed)!=wm_a||wm[2]!=wm_a||wm_order[1]!=wm_a)return 58;" + "event[0]=BOB_EVENT_KEY_DOWN;event[1]=257;event[2]=0;event[3]=0;if(bob_wm_dispatch(wm,wm_windows,wm_order,event,wm_routed)!=wm_a)return 59;" + "event[2]=6;event[3]=5;if(bob_wm_dispatch(wm,wm_windows,wm_order,event,wm_routed)!=wm_a||wm[3]!=wm_a)return 60;" + "event[0]=BOB_EVENT_MOUSE_MOVE;event[2]=79;event[3]=24;" + "if(bob_wm_dispatch(wm,wm_windows,wm_order,event,wm_routed)!=wm_a||wm_windows[0]!=60||wm_windows[1]!=15||wm_routed[2]!=19||wm_routed[3]!=9)return 61;" + "event[2]=0;event[3]=0;bob_wm_dispatch(wm,wm_windows,wm_order,event,wm_routed);" + "if(wm_windows[0]!=0||wm_windows[1]!=0)return 62;event[0]=BOB_EVENT_MOUSE_BUTTON_UP;" + "if(bob_wm_dispatch(wm,wm_windows,wm_order,event,wm_routed)!=wm_a||wm[3]!=-1)return 63;" + "bob_wm_begin_draw(wm,wm_windows,wm_order);if(bob_wm_next_dirty(wm,wm_windows,wm_order)!=wm_b||bob_wm_next_dirty(wm,wm_windows,wm_order)!=wm_a||bob_wm_next_dirty(wm,wm_windows,wm_order)!=-1)return 64;" + "bob_wm_invalidate(wm,wm_windows,wm_order,wm_a);bob_wm_begin_draw(wm,wm_windows,wm_order);" + "if(bob_wm_next_dirty(wm,wm_windows,wm_order)!=wm_b||bob_wm_next_dirty(wm,wm_windows,wm_order)!=wm_a)return 65;" + "if(bob_wm_show(wm,wm_windows,wm_order,wm_a,0)!=1||wm[2]!=wm_b)return 66;" + "event[0]=BOB_EVENT_KEY_DOWN;if(bob_wm_dispatch(wm,wm_windows,wm_order,event,wm_routed)!=wm_b)return 67;" + "if(bob_wm_destroy(wm,wm_windows,wm_order,wm_b)||wm[2]!=-1||wm[1]!=1)return 68;" + "if(bob_wm_destroy(wm,wm_windows,wm_order,wm_b)!=-1||bob_wm_create(wm,wm_windows,wm_order,0,0,81,10)!=-1)return 69;" + "if(bob_wm_create(wm,wm_windows,wm_order,1,1,4,3)!=wm_b||bob_wm_destroy(wm,wm_windows,wm_order,wm_b))return 70;" + "if(bob_wm_init(wm,wm_windows,wm_order,9,80,25)!=-1)return 71;" + "if(bob_gui_menu_place(placed,76,23,20,3,80,25)||placed[0]!=60||placed[1]!=20||placed[2]!=20||placed[3]!=5)return 39;" + "if(bob_gui_menu_place(placed,-4,-2,20,3,80,25)||placed[0]!=0||placed[1]!=0)return 40;" + "if(bob_gui_menu_place(placed,0,0,90,3,80,25)!=-1)return 41;" + "if(bob_gui_menu_event(menu,3,menu_state,event)!=-1||menu_state[0]!=0)return 34;" + "event[0]=BOB_EVENT_KEY_DOWN;event[1]=257;bob_gui_menu_event(menu,3,menu_state,event);if(menu_state[0]!=1)return 35;" + "event[0]=BOB_EVENT_CHAR;event[1]=10;if(bob_gui_menu_event(menu,3,menu_state,event)!=1)return 36;" + "event[1]=27;if(bob_gui_menu_event(menu,3,menu_state,event)!=-2)return 37;" + "event[0]=BOB_EVENT_MOUSE_BUTTON_DOWN;event[1]=BOB_MOUSE_BUTTON_LEFT;event[2]=12;event[3]=8;" + "bob_gui_menu_event(menu,3,menu_state,event);event[0]=BOB_EVENT_MOUSE_BUTTON_UP;event[1]=0;" + "if(bob_gui_menu_event(menu,3,menu_state,event)!=1)return 38;" + "bob_puts(\"bob!\");return 0;}\n"); +} +static void native_filesystem_apps(void) { + write_text("build/notes-check.c",""); + check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel apps/notes.c -o build/notes-check.i > build/compiler.log 2>&1")==0,"notes app preprocessing"); + check(system(COMPILER " build/notes-check.i build/notes-check.basm build/notes-check.b32 --wide-app > build/compiler.log 2>&1")==0,"notes app compilation"); + const char *utilities[]={"echo","ls","cat","sysinfo","graphics_demo","gui_demo","launcher"}; + for(int i=0;i<7;i++) { + char command[512]; + snprintf(command,sizeof(command),"gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel apps/%s.c -o build/%s-check.i > build/compiler.log 2>&1",utilities[i],utilities[i]); + check(system(command)==0,"native utility preprocessing"); + snprintf(command,sizeof(command),COMPILER " build/%s-check.i build/%s-check.basm build/%s-check.b32 --wide-app > build/compiler.log 2>&1",utilities[i],utilities[i],utilities[i]); + check(system(command)==0,"native utility compilation"); + } + storage_path("build/notes-snapshot.b32"); + write_text("build/check.in","import32 build/notes-check.b32 notes\nrun notes put journal \"bob! saved note\"\nrun notes edit journal \"bob! edited note\"\nrun notes add journal \"second line\"\nrun notes show journal\nsave\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"native notes app creates and reads a text file"); + char *output=read_text("build/check.out");contains(output,"Imported native app as notes");contains(output,"Saved.");contains(output,"bob! edited note\nsecond line\nExit 0");contains(output,"Files saved to bob-files.b32");free(output); + write_text("build/check.in","restore yes\nrun notes show journal\nrun notes delete notes\nrun notes delete journal\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"native notes and files survive snapshot restore"); + output=read_text("build/check.out");contains(output,"bob! edited note\nsecond line\nExit 0");contains(output,"Not a text note.\nExit 1");contains(output,"Deleted.\nExit 0");contains(output,"Files restored;");free(output); + write_text("build/check.in","import32 build/echo-check.b32 echo\nrun echo bob! \"two words\"\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"native echo receives command-line arguments"); + output=read_text("build/check.out");contains(output,"bob! two words\nExit 0");free(output); + write_text("build/check.in","run32 build/ls-check.b32\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"native ls lists guest files"); + output=read_text("build/check.out");contains(output,"bob.c 45 text");free(output); + storage_path("build/launcher-snapshot.b32"); + write_text("build/check.in","import32 build/launcher-check.b32 launcher\nimport32 build/echo-check.b32 echo\nimport32 build/notes-check.b32 notes\nrun launcher\nrun launcher echo \"nested saved note\"\nrun launcher notes put childnote \"written by child\"\nrun notes show childnote\nsave\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"expanded filesystem holds multiple apps and launcher persists child writes"); + output=read_text("build/check.out");contains(output,"Native apps:");contains(output,"launcher");contains(output,"echo");contains(output,"notes");contains(output,"Child exit:\n0\n");contains(output,"Saved.\nChild exit:\n0\n");contains(output,"written by child\nExit 0");contains(output,"Files saved to bob-files.b32");free(output); + FILE *wide_snapshot=fopen("build/launcher-snapshot.b32","rb");check(wide_snapshot!=NULL,"expanded B32S snapshot exists");if(wide_snapshot){unsigned char header[8];check(fread(header,1,8,wide_snapshot)==8&&!memcmp(header,"B32S\3\0\0\0",8),"expanded filesystem uses B32S v3");fseek(wide_snapshot,0,SEEK_END);check(ftell(wide_snapshot)==16+(216+8192)*4,"B32S v3 stores the full expanded payload");fclose(wide_snapshot);} + write_text("build/check.in","restore yes\nrun launcher echo \"snapshot child\"\nrun notes show childnote\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"nested apps and child-written files survive snapshot restore"); + output=read_text("build/check.out");contains(output,"Files restored;");contains(output,"snapshot child\nChild exit:\n0\n");contains(output,"written by child\nExit 0");free(output); + write_text("build/check.in","run32 build/sysinfo-check.b32\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"native sysinfo queries the OS service API"); + output=read_text("build/check.out");contains(output,"bob32 system information");contains(output,"System API version: 1");contains(output,"Cell framebuffer: available");contains(output,"Display width (cells): 80");contains(output,"Display height (cells): 25");contains(output,"Keyboard input: available");contains(output,"Filesystem words free: ");free(output); + write_text("build/check.in","run32 build/graphics_demo-check.b32\nx\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"graphics demo draws, reads a key, and returns to the shell"); + output=read_text("build/check.out");contains(output,"BOB32 GRAPHICS DEMO");contains(output,"Press any key to return to the shell");contains(output,"bob!\nExit 0");free(output); + write_text("build/gui-child.c","#include \"bob.h\"\nint main(void){bob_puts(\"GUI child reached\");return 7;}\n"); + check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/gui-child.c -o build/gui-child.i > build/compiler.log 2>&1")==0,"GUI launcher child preprocessing"); + check(system(COMPILER " build/gui-child.i build/gui-child.basm build/gui-child.b32 --wide-app > build/compiler.log 2>&1")==0,"GUI launcher child compilation"); + write_text("build/check.in","import32 build/gui-child.b32 gui_child\nrun32 build/gui_demo-check.b32\n\t\tar\x1b\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"GUI launcher starts a stored native app and returns to the desktop"); + output=read_text("build/check.out");contains(output,"Application launcher");contains(output,"GUI child reached");contains(output,"App exit 7");contains(output,"bob!\nExit 0");free(output); + write_text("build/check.in","run32 build/gui_demo-check.b32\n?\x1b\x1b\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"GUI bitmap-font help overlay opens and returns cleanly"); + output=read_text("build/check.out");contains(output,"Desktop help");contains(output,"##### #### # ####");contains(output,"bob!\nExit 0");free(output); + write_text("build/check.in","run32 build/gui_demo-check.b32\n\t\tm\n\x1b\x1b\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"GUI popup menu opens, navigates, and edits a selected text file"); + output=read_text("build/check.out");contains(output,"File menu: M or click File");contains(output,"Open selected text");contains(output,"Delete selected");contains(output,"Editing selected file.");contains(output,"bob!\nExit 0");free(output); + write_text("build/font-demo.c", + "#include \"bob.h\"\n#include \"bob_font.h\"\n" + "int main(void){if(bob_gfx_enter()||bob_gfx_clear('.',1))return 1;" + "if(bob_gfx_bitmap_text(2,2,\"BOB!\",14)||bob_gfx_present()||bob_gfx_leave())return 2;" + "bob_puts(\"bob!\");return 0;}\n"); + check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/font-demo.c -o build/font-demo.i > build/compiler.log 2>&1")==0,"bitmap font fixture preprocessing"); + check(system(COMPILER " build/font-demo.i build/font-demo.basm build/font-demo.b32 --wide-app > build/compiler.log 2>&1")==0,"bitmap font fixture compilation"); + write_text("build/check.in","run32 build/font-demo.b32\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"native bitmap font draws text through the graphics service"); + output=read_text("build/check.out");contains(output,"####...###..####....#");contains(output,"bob!\nExit 0");free(output); + write_text("build/event-poll.c", + "#include \"bob.h\"\n#include \"bob_event.h\"\n" + "int main(void){int event[4];if(bob_event_poll(event)!=0)return 1;" + "if(bob_event_wait(event)!=1||event[0]!=BOB_EVENT_CHAR||event[1]!='k')return 2;" + "bob_puts(\"bob!\");return 0;}\n"); + check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/event-poll.c -o build/event-poll.i > build/compiler.log 2>&1")==0,"nonblocking input fixture preprocessing"); + check(system(COMPILER " build/event-poll.i build/event-poll.basm build/event-poll.b32 --wide-app > build/compiler.log 2>&1")==0,"nonblocking input fixture compilation"); + write_text("build/check.in","run32 build/event-poll.b32\nk\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"nonblocking event poll leaves redirected input for blocking wait"); + output=read_text("build/check.out");contains(output,"bob!\nExit 0");free(output); + write_text("build/color-blit.c", + "#include \"bob.h\"\n#include \"bob_gfx.h\"\n" + "int main(void){int icon[4]={0x141,0x242,0,0x343};int bad[1]={0x1000};" + "if(bob_gfx_enter()||bob_gfx_clear(' ',7))return 1;" + "if(bob_gfx_blit_color(2,2,1,1,bad)!=-1)return 2;" + "if(bob_gfx_blit_color(2,2,2,2,icon)||bob_gfx_present()||bob_gfx_leave())return 3;" + "bob_puts(\"bob!\");return 0;}\n"); + check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/color-blit.c -o build/color-blit.i > build/compiler.log 2>&1")==0,"colored bitmap fixture preprocessing"); + check(system(COMPILER " build/color-blit.i build/color-blit.basm build/color-blit.b32 --wide-app > build/compiler.log 2>&1")==0,"colored bitmap fixture compilation"); + write_text("build/check.in","run32 build/color-blit.b32\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"colored transparent bitmap app renders through the OS graphics service"); + output=read_text("build/check.out");contains(output,"AB");contains(output," C");contains(output,"bob!\nExit 0");free(output); + write_text("build/gui-seed.c", + "#include \"bob.h\"\n#include \"bob_fs.h\"\n#include \"bob_string.h\"\n" + "int main(void){char data[256];int i;for(i=0;i<210;i++)data[i]='a';" + "bob_strcpy(data+210,\"PREVIEW-CONTENT-42\");" + "if(bob_file_write(\"gui.txt\",data,210+bob_strlen(data+210)))return 1;return 0;}\n"); + check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/gui-seed.c -o build/gui-seed.i > build/compiler.log 2>&1")==0,"GUI long-preview fixture preprocessing"); + check(system(COMPILER " build/gui-seed.i build/gui-seed.basm build/gui-seed.b32 --wide-app > build/compiler.log 2>&1")==0,"GUI long-preview fixture compilation"); + storage_path("build/gui-files-snapshot.b32"); + write_text("build/check.in","import32 build/cat-check.b32 cat\nrun32 build/gui-seed.b32\nrun32 build/gui_demo-check.b32\n\t\tnndxnxy\x13\x1b\nrun cat gui.txt\nsave\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"GUI file editor saves a text file and returns cleanly"); + output=read_text("build/check.out");contains(output,"Text editor");contains(output,"Window B");contains(output,"bob.c");contains(output,"gui.txt");contains(output,"PREVIEW-CONTENT-42");char *first_confirmation=strstr(output,"Delete? Y/N");check(first_confirmation&&strstr(first_confirmation+1,"Delete? Y/N"),"GUI delete cancellation leaves file available for confirmation");contains(output,"Delete selected text file?");contains(output,"Yes, delete");contains(output,"Cancel");contains(output,"Deleted.");contains(output,"new.txt");contains(output,"Cannot read text file.\nExit 1");contains(output,"Files saved to bob-files.b32");contains(output,"bob!\nExit 0");free(output); + write_text("build/check.in","restore yes\nrun cat new.txt\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"GUI-created file survives snapshot restore"); + output=read_text("build/check.out");contains(output,"Files restored;");contains(output,"bob!\nExit 0");free(output); + write_text("build/gui-edit-seed.c","#include \"bob.h\"\n#include \"bob_fs.h\"\n#include \"bob_string.h\"\nint main(void){return bob_file_write(\"multi.txt\",\"first\\nsecond\",bob_strlen(\"first\\nsecond\"))!=0;}\n"); + check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/gui-edit-seed.c -o build/gui-edit-seed.i > build/compiler.log 2>&1")==0,"GUI multiline edit fixture preprocessing"); + check(system(COMPILER " build/gui-edit-seed.i build/gui-edit-seed.basm build/gui-edit-seed.b32 --wide-app > build/compiler.log 2>&1")==0,"GUI multiline edit fixture compilation"); + write_text("build/check.in","import32 build/cat-check.b32 cat\nrun32 build/gui-edit-seed.b32\nrun32 build/gui_demo-check.b32\n\t\tnne!\x13\x1b\nrun cat multi.txt\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"GUI opens, edits, and saves a multiline text file"); + output=read_text("build/check.out");contains(output,"E opens text. Tab changes focus.");contains(output,"Editing selected file.");contains(output,"first\nsecond!\nExit 0");contains(output,"bob!\nExit 0");free(output); + write_text("build/check.in","import32 build/cat-check.b32 cat\nwrite sample.c bob!\nrun cat sample.c\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"native cat reads guest text files"); + output=read_text("build/check.out");contains(output,"bob!\nExit 0");free(output); + write_text("build/cat-lines.c","#include \"bob.h\"\n#include \"bob_fs.h\"\nint main(void){if(bob_file_write(\"trail\",\"line\\n\",5))return 1;if(bob_file_write(\"empty\",\"\",0))return 2;return 0;}\n"); + check(system("gcc -E -P -nostdinc -undef -DBOBC_LEGACY=0 -I kernel build/cat-lines.c -o build/cat-lines.i > build/compiler.log 2>&1")==0,"cat newline fixture preprocessing"); + check(system(COMPILER " build/cat-lines.i build/cat-lines.basm build/cat-lines.b32 --wide-app > build/compiler.log 2>&1")==0,"cat newline fixture compilation"); + write_text("build/check.in","import32 build/cat-check.b32 cat\nrun32 build/cat-lines.b32\nrun cat trail\nrun cat empty\nhalt\n"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"native cat preserves existing newlines and handles empty files"); + output=read_text("build/check.out");contains(output,"line\nExit 0\nbob> Exit 0");free(output); storage_path("build/snapshot.b16"); } static void wide_guest(void) { @@ -193,6 +483,9 @@ static void input_bounds(void) { char commands[400];memset(commands,'x',200);strcpy(commands+200,"\necho bob!\nhalt\n"); char *output=shell(commands);contains(output,"Command too long.");contains(output,"bob> bob!\n"); not_contains(output,"Unknown command");free(output); + output=shell("echo old\necho bob!\nhistory\nhistory extra\nhalt\n"); + contains(output,"1 echo old");contains(output,"2 echo bob!");contains(output,"3 history"); + contains(output,"Usage: history");free(output); output=shell("");check(!strcmp(output,"bob!\nbob16 OS: help COMMAND for usage; go bob.c runs the example.\nFiles are in RAM; halt exits. Type help to get started.\nbob> \n"),"EOF exits shell");free(output); output=shell("echo bxo\b\bbob!\nhalt\n");contains(output,"bob> bbob!\n");free(output); } @@ -737,7 +1030,7 @@ static void storage_path(const char *path) { static void wide_kernel_workflow(void) { storage_path("build/wide-snapshot.b32");remove("build/wide-snapshot.b32"); write_text("build/check.in","mem\nalloc 4\npoke 0xd000 77\npeek 0xd000\npoke 0xc000 88\npeek 0xc000\ngo bob.c\nedit compat.c\nint main(void) {\nint n=0x12345678;\nif(n+1!=0x12345679 || n*2!=0x2468ACF0 || n/3!=101806632 || n%3)return 1;\nprintln(\"bob!\");\nreturn 0;\n}\n.\ngo compat.c\ndelete compat.c\nedit tern.c\nint main(void) {\nint a=0;\nint b=1?2:3;\nint c=0?4:1?5:6;\nint d=1?7:a++;\nif(b==2&&c==5&&d==7&&a==0)println(\"bob!\");\nreturn 0;\n}\n.\ngo tern.c\ndelete tern.c\nedit loops.c\nint main(void) {\nint i=0;\nint calls=0;\ndo { i++; if(i==2)continue; calls++; if(i==4)break; } while(i<10);\ndo { calls++; } while(0);\nif(calls==4)println(\"bob!\");\nreturn 0;\n}\n.\ngo loops.c\ndelete loops.c\nedit assign.c\nint main(void) {\nint a=0; int b=1; int i=0;\nint x=(a=b=3);\na+=2; b<<=2; b>>=1;\nif(x==3&&a==5&&b==6&&((i=i+1)==1))println(\"bob!\");\nreturn 0;\n}\n.\ngo assign.c\ndelete assign.c\nedit funcs.c\nint main(void) {\nannounce();\nif(add(fact(5),2)==122)println(\"bob!\");\nreturn 0;\n}\nint announce(void) {\nprintln(\"bob!\");\nreturn 0;\n}\nint fact(int n) {\nif(n<2)return 1;\nreturn n*fact(n-1);\n}\nint add(int x,int y) {\nint value=x+y;\nreturn value;\n}\n.\ngo funcs.c\ndelete funcs.c\nedit scope.c\nint main(void) {\nint value=3;\n{int value=8;if(value!=8)return 1;}\n{int value=9;if(value!=9)return 2;}\nint count=99;\nfor(int count=0;count<2;count++){int inner=count;if(inner!=count)return 3;}\nif(value==3&&count==99)println(\"bob!\");\nreturn 0;\n}\n.\ngo scope.c\ndelete scope.c\nwrite hex.c int main(void){print_hex(4660);println(\"bob!\");return 0;}\ngo hex.c\nload old 0xD002 0xF200 0xF000 0x0062 0x006F 0x0062 0x0021 0x0000\nrun old\nedit note\nbob!\n.\nread note\nls\ncc bob.c app\nrun app\nsave\nhalt\n"); - check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 50000000 < build/check.in > build/check.out 2> build/check.err")==0,"bob32 OS shell workflow"); + check(system(BOB32 " --boot build/kernel32.b32 --max-cycles 60000000 < build/check.in > build/check.out 2> build/check.err")==0,"bob32 OS shell workflow"); char *output=read_text("build/check.out");int successful_apps=0;const char *success_cursor=output; while((success_cursor=strstr(success_cursor,"bob!\nExit 0"))){successful_apps++;success_cursor+=11;} check(successful_apps==9,"B32 resident programs all complete successfully"); @@ -1392,6 +1685,6 @@ static void basm_route(void) { int main(void) { console_and_commands();input_bounds();allocator_and_files();resident_compiler(); compiler_extensions();wide_guest();editor_and_aliases(); - program_loading_and_recovery();native_string_library();host_compiler_and_runtime();host_language_rejections();file_management();compile_workflow();usability();persistence();shell_editing();image_validation();basm_route();wide_kernel_workflow();wide_local_arrays();wide_array_parameters();wide_resident_large_output();wide_function_prototypes();wide_function_pointers();wide_local_offset_limit(); + program_loading_and_recovery();native_string_library();native_gui_geometry();native_filesystem_apps();host_compiler_and_runtime();host_language_rejections();file_management();compile_workflow();usability();persistence();shell_editing();image_validation();basm_route();wide_kernel_workflow();wide_local_arrays();wide_array_parameters();wide_resident_large_output();wide_function_prototypes();wide_function_pointers();wide_local_offset_limit(); printf("bob!\n%d checks passed.\n",checks);return 0; } diff --git a/tools/bob64cc.c b/tools/bob64cc.c new file mode 100644 index 0000000..07d8d11 --- /dev/null +++ b/tools/bob64cc.c @@ -0,0 +1,193 @@ +/* Build a small freestanding C program into bob64's versioned B64E format. */ +#include +#include +#include +#include +#include +#ifdef _WIN32 +#include +#define make_dir(path) _mkdir(path) +#define APP_EXE ".exe" +#else +#include +#define make_dir(path) mkdir(path,0777) +#define APP_EXE "" +#endif + +#define APP_BASE 0x0000004000000000ULL +#define APP_LIMIT (16ULL*1024ULL*1024ULL) +#define PAGE_SIZE 4096u +#define HEADER_SIZE 64u +#define APP_ABI_VERSION 1u +#define EXEC_VERSION 1u + +static uint16_t read16(const unsigned char *p) { + return (uint16_t)(p[0]|((uint16_t)p[1]<<8)); +} +static uint32_t read32(const unsigned char *p) { + return (uint32_t)p[0]|((uint32_t)p[1]<<8)|((uint32_t)p[2]<<16)|((uint32_t)p[3]<<24); +} +static uint64_t read64(const unsigned char *p) { + return (uint64_t)read32(p)|((uint64_t)read32(p+4)<<32); +} +static void write16(unsigned char *p,uint16_t v) { + p[0]=(unsigned char)v;p[1]=(unsigned char)(v>>8); +} +static void write32(unsigned char *p,uint32_t v) { + for(unsigned i=0;i<4;i++)p[i]=(unsigned char)(v>>(i*8)); +} +static void write64(unsigned char *p,uint64_t v) { + write32(p,(uint32_t)v);write32(p+4,(uint32_t)(v>>32)); +} +static uint32_t crc32(const unsigned char *p,size_t n) { + uint32_t value=0xffffffffu; + for(size_t i=0;i>1)^(0xedb88320u&-(value&1u)); + } + return ~value; +} +static unsigned char *read_file(const char *path,size_t *length) { + FILE *f=fopen(path,"rb"); + unsigned char *bytes; + long size; + if(!f){perror(path);return NULL;} + if(fseek(f,0,SEEK_END)||(size=ftell(f))<0||size>64*1024*1024L|| + fseek(f,0,SEEK_SET)) {fclose(f);fprintf(stderr,"bob64cc: invalid input size\n");return NULL;} + bytes=(unsigned char *)malloc((size_t)size? (size_t)size:1); + if(!bytes){fclose(f);fprintf(stderr,"bob64cc: out of memory\n");return NULL;} + if(fread(bytes,1,(size_t)size,f)!=(size_t)size||fclose(f)) { + free(bytes);fprintf(stderr,"bob64cc: cannot read %s\n",path);return NULL; + } + *length=(size_t)size;return bytes; +} +static int write_b64e(const char *path,const unsigned char *pe,size_t pe_size, + const unsigned char *payload,size_t payload_size) { + uint32_t pe_offset,entry_rva,section_alignment,size_of_image; + uint64_t image_base,lowest_rva=UINT64_MAX,highest_virtual=0,code_end=0; + uint64_t entry_offset,code_size,memory_size; + uint16_t section_count,optional_size; + size_t section_table; + int executable_at_lowest=0; + unsigned char *image; + FILE *out; + if(pe_size<64||pe[0]!='M'||pe[1]!='Z')goto bad_pe; + pe_offset=read32(pe+0x3c); + if((uint64_t)pe_offset+24>pe_size||memcmp(pe+pe_offset,"PE\0\0",4))goto bad_pe; + const unsigned char *coff=pe+pe_offset+4; + if(read16(coff)!=0x8664)goto bad_pe; + section_count=read16(coff+2);optional_size=read16(coff+16); + if(!section_count||section_count>32||optional_size<112|| + (uint64_t)pe_offset+24+optional_size>pe_size)goto bad_pe; + const unsigned char *optional=coff+20; + if(read16(optional)!=0x20b)goto bad_pe; + entry_rva=read32(optional+16);image_base=read64(optional+24); + section_alignment=read32(optional+32);size_of_image=read32(optional+56); + if(section_alignment!=PAGE_SIZE||!entry_rva|| + !size_of_image||size_of_image>APP_LIMIT+PAGE_SIZE)goto bad_pe; + if((read16(optional+70)&0x40u)||optional_size<160|| + read32(optional+112+5*8)||read32(optional+112+5*8+4))goto bad_pe; + section_table=(size_t)pe_offset+24+optional_size; + if(section_count>(pe_size-section_table)/40)goto bad_pe; + for(uint16_t i=0;iraw_size?virtual_size:raw_size; + if((uint64_t)rva+span>APP_LIMIT+PAGE_SIZE|| + (raw_size&&(uint64_t)raw_offset+raw_size>pe_size))goto bad_pe; + if(span&&rvahighest_virtual) + highest_virtual=(uint64_t)rva+virtual_size; + if(characteristics&0x20000000u) { + if(rvacode_end)code_end=(uint64_t)rva+span; + if(rva==lowest_rva)executable_at_lowest=1; + } + } + if(lowest_rva==UINT64_MAX||image_base>UINT64_MAX-lowest_rva|| + image_base+lowest_rva!=APP_BASE|| + !executable_at_lowest||entry_rva=code_end||code_end<=lowest_rva)goto bad_pe; + entry_offset=(uint64_t)entry_rva-lowest_rva; + code_size=(code_end-lowest_rva+PAGE_SIZE-1)&~(uint64_t)(PAGE_SIZE-1); + memory_size=(highest_virtual-lowest_rva+PAGE_SIZE-1)&~(uint64_t)(PAGE_SIZE-1); + if(payload_size>memory_size)memory_size=(payload_size+PAGE_SIZE-1)&~(uint64_t)(PAGE_SIZE-1); + if(!code_size||code_size>payload_size||payload_size>APP_LIMIT|| + memory_size>APP_LIMIT||entry_offset>=code_size)goto bad_pe; + image=(unsigned char *)calloc(1,HEADER_SIZE+payload_size); + if(!image){fprintf(stderr,"bob64cc: out of memory\n");return -1;} + image[0]='B';image[1]='6';image[2]='4';image[3]='E'; + write16(image+4,EXEC_VERSION);write16(image+6,HEADER_SIZE); + write32(image+8,APP_ABI_VERSION);write64(image+16,payload_size); + write64(image+24,memory_size);write64(image+32,entry_offset); + write64(image+40,code_size);memcpy(image+HEADER_SIZE,payload,payload_size); + write32(image+48,crc32(image+HEADER_SIZE,payload_size)); + out=fopen(path,"wb"); + if(!out){perror(path);free(image);return -1;} + int failed=fwrite(image,1,HEADER_SIZE+payload_size,out)!=HEADER_SIZE+payload_size; + if(fclose(out))failed=1; + free(image); + if(failed){fprintf(stderr,"bob64cc: failed writing %s\n",path);return -1;} + printf("Built B64E v1: entry=0x%llx code=%llu file=%llu memory=%llu bytes\n", + (unsigned long long)entry_offset,(unsigned long long)code_size, + (unsigned long long)payload_size,(unsigned long long)memory_size); + return 0; +bad_pe: + fprintf(stderr,"bob64cc: compiler output is not a supported bob64 app image\n"); + return -1; +} +static int quote(char *out,size_t capacity,const char *value) { + size_t length=strlen(value); + if(length+3>capacity||strchr(value,'"'))return -1; + out[0]='"';memcpy(out+1,value,length);out[length+1]='"';out[length+2]=0; + return 0; +} +int main(int argc,char **argv) { + const char *compiler=getenv("BOB64_CC"),*objcopy=getenv("BOB64_OBJCOPY"); + char q_source[4096],q_output[4096]; + char command[16384],exe_path[256],bin_path[256]; + size_t pe_size=0,payload_size=0; + unsigned char *pe=NULL,*payload=NULL; + int result=1; + if(argc!=3) { + fprintf(stderr,"Usage: bob64cc SOURCE.c OUTPUT.b64e\n");return 2; + } + if(!strcmp(argv[1],argv[2])) { + fprintf(stderr,"bob64cc: source and output paths must be different\n");return 2; + } + if(!compiler||!*compiler)compiler="x86_64-w64-mingw32-gcc"; + if(!objcopy||!*objcopy)objcopy="objcopy"; + if(quote(q_source,sizeof(q_source),argv[1])|| + quote(q_output,sizeof(q_output),argv[2])||strchr(compiler,'"')|| + strchr(objcopy,'"')) { + fprintf(stderr,"bob64cc: invalid or overly long path\n");return 2; + } + if(make_dir("build")&&errno!=EEXIST) {perror("build");return 1;} + if(make_dir("build/bob64-app")&&errno!=EEXIST) {perror("build/bob64-app");return 1;} + snprintf(exe_path,sizeof(exe_path),"build/bob64-app/image%s",APP_EXE); + snprintf(bin_path,sizeof(bin_path),"build/bob64-app/image.bin"); + char q_exe[512],q_bin[512],q_entry[512]; + if(quote(q_exe,sizeof(q_exe),exe_path)||quote(q_bin,sizeof(q_bin),bin_path)|| + quote(q_entry,sizeof(q_entry),"bob64/app_entry.S")) { + fprintf(stderr,"bob64cc: temporary path too long\n");return 2; + } + snprintf(command,sizeof(command), + "%s -I. -DBOB64_UEFI_ABI -std=c11 -O2 -Wall -Wextra -Werror -ffreestanding " + "-fno-builtin -fno-stack-protector -fno-stack-check -fno-unwind-tables " + "-fno-asynchronous-unwind-tables -fPIC -mno-red-zone -nostdlib bob64/libc.c %s %s " + "-Wl,--image-base,0x3ffffff000 -Wl,--disable-dynamicbase " + "-Wl,--disable-reloc-section -Wl,-e,bob64_app_entry -o %s", + compiler,q_entry,q_source,q_exe); + if(system(command)!=0)goto done; + snprintf(command,sizeof(command),"%s -O binary %s %s",objcopy,q_exe,q_bin); + if(system(command)!=0)goto done; + pe=read_file(exe_path,&pe_size);payload=read_file(bin_path,&payload_size); + if(!pe||!payload||write_b64e(argv[2],pe,pe_size,payload,payload_size))goto done; + result=0; +done: + free(pe);free(payload);remove(exe_path);remove(bin_path); + return result; +} diff --git a/tools/bobcc.c b/tools/bobcc.c index d73e8a8..cb030d6 100644 --- a/tools/bobcc.c +++ b/tools/bobcc.c @@ -1315,12 +1315,13 @@ static void expr(Node *n) { else if(!strcmp(n->name,"bob_run_image")){vector=12;expected=1;} else if(!strcmp(n->name,"bob_run_native")){vector=13;expected=1;} else if(!strcmp(n->name,"bob_import_image")){vector=14;expected=1;} + else if(!strcmp(n->name,"bob_os_service") || !strcmp(n->name,"bob_fs_register")){vector=15;expected=1;} else if(!strcmp(n->name,"bob_key"))vector=8; else if(!strcmp(n->name,"bob_terminal"))vector=9; else if(!strcmp(n->name,"bob_columns"))vector=10; else if(!strcmp(n->name,"bob_rows"))vector=11; if(vector>=0) {if(count!=expected)error("wrong argument count for %s",n->name); - int first_type=(vector==2 || vector==12)?pointer_to_const(4):vector==3?pointer_to(4):vector==7 || vector==13 || vector==14?pointer_to(0):0; + int first_type=(vector==2 || vector==12)?pointer_to_const(4):vector==3?pointer_to(4):vector==7 || vector==13 || vector==14 || vector==15?pointer_to(0):0; if(count)assignment_compatible(first_type,n->a); if(expected==2)assignment_compatible(0,n->a->next); if(expected==2){expr(n->a->next);push(0);expr(n->a);pop(1);}else if(count)expr(n->a); diff --git a/tools/build.c b/tools/build.c index 2f16425..6a951c9 100644 --- a/tools/build.c +++ b/tools/build.c @@ -8,11 +8,15 @@ #include #define EXE ".exe" #define BUILD_DIR "build\\" +#define BOB64_BOOT_PATH "build\\bob64\\EFI\\BOOT\\BOOTX64.EFI" +#define BOB64_HANDOFF_BOOT_PATH "build\\bob64-handoff\\EFI\\BOOT\\BOOTX64.EFI" #define BOB_COMMAND "bob.exe" #define BOB32_COMMAND "bob32.exe" #else #define EXE "" #define BUILD_DIR "./build/" +#define BOB64_BOOT_PATH "build/bob64/EFI/BOOT/BOOTX64.EFI" +#define BOB64_HANDOFF_BOOT_PATH "build/bob64-handoff/EFI/BOOT/BOOTX64.EFI" #define BOB_COMMAND "./bob" #define BOB32_COMMAND "./bob32" #endif @@ -20,9 +24,50 @@ static void run(const char *command) { if(system(command)!=0){fprintf(stderr,"Build failed: %s\n",command);exit(1);} } +static void ensure_directory(const char *path) { +#ifdef _WIN32 + if(_mkdir(path) && errno!=EEXIST){perror(path);exit(1);} +#else + if(mkdir(path,0777) && errno!=EEXIST){perror(path);exit(1);} +#endif +} +static void build_bob64(int handoff) { + const char *compiler=getenv("BOB64_CC"); + const char *output_path=handoff?BOB64_HANDOFF_BOOT_PATH:BOB64_BOOT_PATH; + const char *handoff_define=handoff?"-DBOB64_ENABLE_HANDOFF ":""; + char command[2048]; + ensure_directory("build"); + ensure_directory("build/bob64-app"); + run("gcc -std=c11 -O2 -Wall -Wextra -Werror tools/bob64cc.c -o build/bob64cc" EXE); + run(BUILD_DIR "bob64cc" EXE " apps/bob64_smoke.c build/bob64-app/smoke.b64e"); + run(BUILD_DIR "bob64cc" EXE " apps/bob64_display.c build/bob64-app/display.b64e"); + run(BUILD_DIR "bob64cc" EXE " apps/bob64_gui.c build/bob64-app/gui.b64e"); + ensure_directory(handoff?"build/bob64-handoff":"build/bob64"); + if(handoff) { + ensure_directory("build/bob64-handoff/EFI"); + ensure_directory("build/bob64-handoff/EFI/BOOT"); + } else { + ensure_directory("build/bob64/EFI"); + ensure_directory("build/bob64/EFI/BOOT"); + } + if(!compiler || !*compiler) { +#ifdef _WIN32 + compiler="gcc"; +#else + compiler="x86_64-w64-mingw32-gcc"; +#endif + } + if(snprintf(command,sizeof(command),"%s -std=c11 -O2 -Wall -Wextra -Werror -DBOB64_UEFI_ABI %s-ffreestanding -fno-stack-protector -fno-stack-check -fshort-wchar -mno-red-zone -nostdlib -Wl,--subsystem,10 -Wl,-e,efi_main -Wl,--image-base,0x100000 -Wl,--enable-reloc-section -Wl,--dynamicbase -Wl,--file-alignment,0x200 -Wl,--section-alignment,0x1000 bob64/boot.c bob64/memory.c bob64/paging.c bob64/cpu.c bob64/descriptors.c bob64/interrupts.c bob64/interrupts.S bob64/syscall.c bob64/window_server.c bob64/bootstrap.c bob64/kernel.c bob64/console.c bob64/heap.c bob64/keyboard.c bob64/mouse.c bob64/shell.c bob64/filesystem.c bob64/snapshot.c bob64/exec.c bob64/process.c bob64/compiler.c bob64/embedded_app.S bob64/handoff.S -o %s",compiler,handoff_define,output_path)>=(int)sizeof(command)) { + fprintf(stderr,"bob64 compiler command is too long\n");exit(1); + } + run(command); +} int main(int argc,char **argv) { - if(argc>2||(argc==2&&strcmp(argv[1],"--run")&&strcmp(argv[1],"--run32")&&strcmp(argv[1],"--test"))) { - fprintf(stderr,"Usage: build [--run | --run32 | --test] (from repository root)\n");return 1; + int bob64Handoff=argc==2&&(!strcmp(argv[1],"--bob64-handoff")||!strcmp(argv[1],"--bob64-handoff-test")); + int bob64Only=argc==2&&(!strcmp(argv[1],"--bob64")||!strcmp(argv[1],"--bob64-test")||bob64Handoff); + int bob64Test=argc==2&&(!strcmp(argv[1],"--bob64-test")||!strcmp(argv[1],"--bob64-handoff-test")); + if(argc>2||(argc==2&&!bob64Only&&strcmp(argv[1],"--run")&&strcmp(argv[1],"--run32")&&strcmp(argv[1],"--test"))) { + fprintf(stderr,"Usage: build [--run | --run32 | --test | --bob64 | --bob64-test | --bob64-handoff | --bob64-handoff-test] (from repository root)\n");return 1; } #ifdef _WIN32 int directory_result=_mkdir("build"); @@ -40,6 +85,15 @@ int main(int argc,char **argv) { if(!is_directory){ fprintf(stderr,"build must be a directory\n");return 1; } + if(bob64Only) { + build_bob64(bob64Handoff); + if(bob64Test) { + run("gcc -std=c11 -O2 -Wall -Wextra -Werror tests/test_bob64.c bob64/libc.c bob64/compiler.c bob64/memory.c bob64/paging.c bob64/cpu.c bob64/descriptors.c bob64/interrupts.c bob64/interrupts.S bob64/syscall.c bob64/window_server.c bob64/bootstrap.c bob64/console.c bob64/heap.c bob64/keyboard.c bob64/mouse.c bob64/shell.c bob64/filesystem.c bob64/snapshot.c bob64/exec.c bob64/process.c -o build/test_bob64" EXE); + if(bob64Handoff) run(BUILD_DIR "test_bob64" EXE " " BOB64_HANDOFF_BOOT_PATH " build/bob64-app/smoke.b64e build/bob64-app/display.b64e build/bob64-app/gui.b64e"); + else run(BUILD_DIR "test_bob64" EXE " " BOB64_BOOT_PATH " build/bob64-app/smoke.b64e build/bob64-app/display.b64e build/bob64-app/gui.b64e"); + } + return 0; + } run("gcc -std=gnu11 -O2 -Wall -Wextra -Werror main.c -o bob" EXE); run("gcc -std=gnu11 -O2 -Wall -Wextra -Werror main.c -o bob32" EXE); run("gcc -std=c11 -O2 -Wall -Wextra -Werror tools/bobcc.c -o build/bobcc" EXE); diff --git a/tools/test_bob64_qemu.ps1 b/tools/test_bob64_qemu.ps1 new file mode 100644 index 0000000..2954b57 --- /dev/null +++ b/tools/test_bob64_qemu.ps1 @@ -0,0 +1,104 @@ +param( + [Parameter(Mandatory = $true)] + [string]$QemuPath, + [Parameter(Mandatory = $true)] + [string]$OvmfCodePath, + [string]$ImageRoot = (Join-Path (Split-Path -Parent $PSScriptRoot) 'build\bob64-handoff'), + [int]$TimeoutSeconds = 45 +) + +$ErrorActionPreference = 'Stop' +$requiredMarkers = @( + 'bob64: long mode active', + 'bob64: exiting UEFI boot services', + 'bob64 kernel: ring-3 bob! app passed', + 'bob64 kernel: native streaming app passed', + 'bob64 kernel: read-only code protection passed', + 'bob64 kernel: non-executable data protection passed', + 'bob64 kernel: memory checks passed', + 'bob64 kernel: timer IRQ enabled', + 'bob64 kernel: keyboard IRQ enabled', + 'bob64 kernel: PS/2 mouse IRQ enabled', + 'bob64! kernel shell; type help' +) + +foreach ($path in @($QemuPath, $OvmfCodePath, $ImageRoot)) { + if (-not (Test-Path -LiteralPath $path)) { + throw "Required QEMU runtime path does not exist: $path" + } +} + +$efiPath = Join-Path $ImageRoot 'EFI\BOOT\BOOTX64.EFI' +if (-not (Test-Path -LiteralPath $efiPath)) { + throw "The handoff image is missing: $efiPath" +} + +$qemuDirectory = Split-Path -Parent (Resolve-Path -LiteralPath $QemuPath).Path +$shareDirectory = Join-Path $qemuDirectory 'share' +if (-not (Test-Path -LiteralPath $shareDirectory -PathType Container)) { + throw "QEMU's share directory does not exist: $shareDirectory" +} +$imagePath = (Resolve-Path -LiteralPath $ImageRoot).Path.Replace('\', '/') +$firmwarePath = (Resolve-Path -LiteralPath $OvmfCodePath).Path +$serialPath = Join-Path ([IO.Path]::GetTempPath()) ("bob64-qemu-{0}.log" -f [guid]::NewGuid()) + +$portProbe = [Net.Sockets.TcpListener]::new([Net.IPAddress]::Loopback, 0) +$portProbe.Start() +$monitorPort = ([Net.IPEndPoint]$portProbe.LocalEndpoint).Port +$portProbe.Stop() + +$arguments = @( + '-machine', 'q35', '-m', '512M', '-cpu', 'max', '-L', $shareDirectory, + '-drive', "if=pflash,format=raw,unit=0,file=$firmwarePath,readonly=on", + '-drive', "format=raw,file=fat:rw:$imagePath", + '-boot', 'order=c', '-display', 'none', '-serial', "file:$serialPath", + '-monitor', "tcp:127.0.0.1:$monitorPort,server=on,wait=off", '-no-reboot' +) + +$startInfo = [Diagnostics.ProcessStartInfo]::new() +$startInfo.FileName = (Resolve-Path -LiteralPath $QemuPath).Path +$startInfo.UseShellExecute = $false +$startInfo.CreateNoWindow = $true +$startInfo.Arguments = (($arguments | ForEach-Object { + '"' + ([string]$_).Replace('"', '\"') + '"' +}) -join ' ') + +$process = $null +try { + $process = [Diagnostics.Process]::Start($startInfo) + $deadline = [DateTime]::UtcNow.AddSeconds($TimeoutSeconds) + $serialText = '' + while ([DateTime]::UtcNow -lt $deadline) { + if (Test-Path -LiteralPath $serialPath) { + $serialText = [string](Get-Content -LiteralPath $serialPath -Raw) + $allPresent = $true + foreach ($marker in $requiredMarkers) { + if ([string]::IsNullOrEmpty($serialText) -or -not $serialText.Contains($marker)) { + $allPresent = $false + break + } + } + if ($allPresent) { + Write-Output 'UEFI runtime checks passed:' + foreach ($marker in $requiredMarkers) { + Write-Output " $marker" + } + exit 0 + } + } + if ($process.HasExited) { + throw "QEMU exited before the kernel reached its shell (exit code $($process.ExitCode)).`n$serialText" + } + Start-Sleep -Milliseconds 250 + } + throw "Timed out waiting for the UEFI kernel smoke checks.`n$serialText" +} +finally { + if ($process -and -not $process.HasExited) { + $process.Kill() + $process.WaitForExit() + } + if (Test-Path -LiteralPath $serialPath) { + Remove-Item -LiteralPath $serialPath -Force + } +}