1
0

5 Коммиты 346fd927bf ... c5f21a2ab9

Автор SHA1 Сообщение Дата
  Johannes Zellner c5f21a2ab9 Use the Adwaita cursor set instead of the single arrow 4 дней назад
  Johannes Zellner ce76a5ac91 Add browser visit history with URL-bar autocomplete 4 дней назад
  Johannes Zellner d00a58bec0 Use the Adwaita symbolic icons for ngui 4 дней назад
  Johannes Zellner 9eb38faa14 Fix xHCI EP0 max packet size so the VL805 sees the boot stick 6 дней назад
  Johannes Zellner 7254b400be Render google.com: inert noscript, 4 KB URLs and author-styled controls 6 дней назад
100 измененных файлов с 2109 добавлено и 230 удалено
  1. 5 0
      .gitignore
  2. 164 23
      AGENTS.md
  3. 55 12
      Makefile
  4. 10 0
      assets/cursors/adwaita/COPYING
  5. 7 0
      assets/cursors/adwaita/COPYING_CCBYSA3
  6. 165 0
      assets/cursors/adwaita/COPYING_LGPL
  7. 19 0
      assets/cursors/adwaita/README
  8. BIN
      assets/cursors/adwaita/alias
  9. BIN
      assets/cursors/adwaita/all-resize
  10. BIN
      assets/cursors/adwaita/all-scroll
  11. BIN
      assets/cursors/adwaita/cell
  12. BIN
      assets/cursors/adwaita/col-resize
  13. BIN
      assets/cursors/adwaita/context-menu
  14. BIN
      assets/cursors/adwaita/copy
  15. BIN
      assets/cursors/adwaita/crosshair
  16. BIN
      assets/cursors/adwaita/default
  17. BIN
      assets/cursors/adwaita/e-resize
  18. BIN
      assets/cursors/adwaita/ew-resize
  19. BIN
      assets/cursors/adwaita/grab
  20. BIN
      assets/cursors/adwaita/grabbing
  21. BIN
      assets/cursors/adwaita/help
  22. BIN
      assets/cursors/adwaita/n-resize
  23. BIN
      assets/cursors/adwaita/ne-resize
  24. BIN
      assets/cursors/adwaita/nesw-resize
  25. BIN
      assets/cursors/adwaita/no-drop
  26. BIN
      assets/cursors/adwaita/not-allowed
  27. BIN
      assets/cursors/adwaita/ns-resize
  28. BIN
      assets/cursors/adwaita/nw-resize
  29. BIN
      assets/cursors/adwaita/nwse-resize
  30. BIN
      assets/cursors/adwaita/pointer
  31. BIN
      assets/cursors/adwaita/progress
  32. BIN
      assets/cursors/adwaita/row-resize
  33. BIN
      assets/cursors/adwaita/s-resize
  34. BIN
      assets/cursors/adwaita/se-resize
  35. BIN
      assets/cursors/adwaita/sw-resize
  36. BIN
      assets/cursors/adwaita/text
  37. BIN
      assets/cursors/adwaita/vertical-text
  38. BIN
      assets/cursors/adwaita/w-resize
  39. BIN
      assets/cursors/adwaita/wait
  40. BIN
      assets/cursors/adwaita/zoom-in
  41. BIN
      assets/cursors/adwaita/zoom-out
  42. 10 0
      assets/icons/adwaita/COPYING
  43. 7 0
      assets/icons/adwaita/COPYING_CCBYSA3
  44. 165 0
      assets/icons/adwaita/COPYING_LGPL
  45. 21 0
      assets/icons/adwaita/README
  46. 1 0
      assets/icons/adwaita/drive-harddisk-symbolic.svg
  47. 1 0
      assets/icons/adwaita/folder-symbolic.svg
  48. 1 0
      assets/icons/adwaita/go-home-symbolic.svg
  49. 1 0
      assets/icons/adwaita/go-next-symbolic.svg
  50. 1 0
      assets/icons/adwaita/go-previous-symbolic.svg
  51. 1 0
      assets/icons/adwaita/go-up-symbolic.svg
  52. 1 0
      assets/icons/adwaita/list-add-symbolic.svg
  53. 1 0
      assets/icons/adwaita/open-menu-symbolic.svg
  54. 1 0
      assets/icons/adwaita/process-stop-symbolic.svg
  55. 1 0
      assets/icons/adwaita/system-search-symbolic.svg
  56. 1 0
      assets/icons/adwaita/text-x-generic-symbolic.svg
  57. 1 0
      assets/icons/adwaita/view-refresh-symbolic.svg
  58. 1 0
      assets/icons/adwaita/window-close-symbolic.svg
  59. 3 1
      docs/boot.html
  60. 2 1
      docs/development.html
  61. 1 1
      docs/drivers.html
  62. 58 2
      docs/graphics.html
  63. 1 1
      docs/index.html
  64. 1 1
      docs/network.html
  65. 5 2
      docs/userland.html
  66. 22 16
      host/fs.c
  67. 1 0
      host/host.h
  68. 8 2
      host/main.c
  69. 4 0
      host/syscall.c
  70. 9 0
      host/window.c
  71. 3 0
      host/window.h
  72. 42 1
      host/window_headless.c
  73. 47 0
      host/window_sdl3.c
  74. 87 0
      include/cursor_abi.h
  75. 42 0
      include/icon_abi.h
  76. 4 0
      include/syscall.h
  77. 44 28
      kernel/cirrus.c
  78. 5 2
      kernel/cirrus.h
  79. 145 0
      kernel/cursor.c
  80. 29 0
      kernel/cursor.h
  81. 48 27
      kernel/intel.c
  82. 11 5
      kernel/intel.h
  83. 2 0
      kernel/kernel.c
  84. 219 50
      kernel/mouse.c
  85. 8 0
      kernel/mouse.h
  86. 49 35
      kernel/radeon.c
  87. 6 3
      kernel/radeon.h
  88. 3 0
      kernel/ramfs.c
  89. 10 0
      kernel/sys_wm.c
  90. 2 0
      kernel/sys_wm.h
  91. 4 0
      kernel/syscall.c
  92. 61 0
      kernel/wm.c
  93. 5 0
      kernel/wm.h
  94. 125 16
      kernel/xhci.c
  95. 40 0
      testdata/browser/compat/072-styled-controls.html
  96. 21 0
      testdata/browser/compat/073-noscript.html
  97. 1 1
      testdata/browser/compat/README
  98. 2 0
      testdata/browser/compat/index.html
  99. 104 0
      tools/cursor_test.c
  100. 184 0
      tools/mkcursors.c

+ 5 - 0
.gitignore

@@ -36,3 +36,8 @@ host/build/
 browser-host
 host-curl
 firmware/
+/mkcursors
+/cursors/
+/mkicons
+/icons/
+/cursor_test

+ 164 - 23
AGENTS.md

@@ -16,7 +16,8 @@ Targets i586 (first-gen Pentium); runs under QEMU or on real hardware.
 | `user/` | `ucmd_lib.h` (the ring-3 syscall wrappers) and `ucmd.ld` |
 | `user/apps/<name>/` | One ring-3 program per directory: entry file `ucmd_<name>.c` plus private modules (`browser/` holds `browser.c`, `browser_html.c`, `js_*.c`, `svg_raster.c`; `chat/` holds `chat_login.c`; `gallery/` holds the real `gallery.c` behind the `ucmd_gallery.c` launcher; `hello/` has its own `hello.ld`) |
 | `user/lib/<lib>/` | Ring-3 libraries: `libc`, `ngui`, `ufont`, `img`, `tls` (crypto incl. `wpa_crypto.c`), `uhttp`, `ujson`, `uwm` (`uwm_lib.c`), `wifi` (`wifi_store.c`, `wpa.c`); host tests live next to their library |
-| `tools/` | Host tools (`mkpack.c`, `mkrootfs.c`, `mkrtwtbl.c`, `kexec_send.c`, `netkexec_send.c`, `netmonitor.c`, `flash.sh`) and the QMP test scripts |
+| `tools/` | Host tools (`mkpack.c`, `mkrootfs.c`, `mkrtwtbl.c`, `mkcursors.c`, `mkicons.c`, `kexec_send.c`, `netkexec_send.c`, `netmonitor.c`, `flash.sh`, `xcursor_trim.py`), the QMP test scripts and `cursor_test.c` |
+| `assets/` | Imported assets: `assets/cursors/adwaita/` (the Adwaita 24 px Xcursor files) and `assets/icons/adwaita/` (the Adwaita symbolic SVGs used as UI icons), both LGPL-3 / CC-BY-SA-3.0, with README and licences |
 | `host/` | Linux SDL3 browser harness |
 
 The top-level `Makefile` builds everything.  Objects go to `build/`
@@ -116,6 +117,7 @@ make test-font  # host TrueType parser/rasterizer specimen test
 make test-font-asan  # ASan/UBSan variant
 make test-svg   # host tests for the inline-SVG rasterizer (ASan/UBSan)
 make test-touchpad  # host tests for the contact gesture engine
+make test-cursors   # host test for the NBCUR1 cursor bundle (mkcursors output)
 make test-wpa   # host tests for the WPA2-PSK supplicant (SHA-1/PBKDF2/PRF/AES, 4-way)
 make test-wifi-store  # host tests for the saved-network list file
 make test-chat  # host tests: JSON parser, cookie jar, chat login parsers (ASan)
@@ -133,7 +135,10 @@ make clean
   host files/sockets and `fork/exec` for `curl __serve`).  Run
   `./browser-host [--size WxH] [--root DIR] URL|FILE`, or
   `./browser-host --headless --wait 3000 --shot out.ppm URL` to render the
-  compat ladder without a display.  It needs the multilib `lib32-sdl3`,
+  compat ladder without a display; `--keys 'clo{down}{enter}'` types into
+  the headless window (100 ms per key from 300 ms after the first frame;
+  `{enter} {esc} {tab} {bs} {del} {up} {down} {left} {right} {ctrl-l}
+  {wait}`).  It needs the multilib `lib32-sdl3`,
   `lib32-wayland` and `lib32-libxkbcommon`; host sockets replace the NebOS TCP
   stack and the kernel/WM paths are not exercised.
 - QEMU guests default to 512 MB (`QEMU_MEM`, e.g. `make run QEMU_MEM=1G`),
@@ -142,8 +147,10 @@ make clean
   to `cmds_pack_gz.bin`, wrapped by `mkrootfs` with a one-sector `NBROOT1`
   header into `cmds.img` (the 8 MB USB partition image) and `BOOTX64.EFI`.
   The floppy images append `rootfs.bin`, built the same way from
-  `cmds-lite.pack` (everything but `firmware/*`), because the ~1 MB WiFi
-  firmware does not fit a 1.44 MB floppy.  The kernel itself no longer
+  `cmds-lite.pack` (everything but `firmware/*`, the cursor bundle,
+  `install/kernel.bin` and `bin/browser.app`), because the ~1 MB WiFi
+  firmware and the ~500 KB gzip browser do not fit a 1.44 MB floppy; a
+  floppy boot runs the browser from `BROWSER` on `root.img`.  The kernel itself no longer
   carries the pack; the boot path loads it into RAM and `ramfs_init` takes a
   private copy (`bin/<name>` mounted at `/ramfs`).
 - The WiFi firmware `firmware/iwlwifi-7265D-29.ucode` (Chromebook) and
@@ -472,6 +479,8 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   input.  `SYS_WIN_SCROLL` returns scroll accumulated for the canvas window
   under the pointer, in pixels (`+dy` = later content), so every client sees
   one unit independent of whether it came from the touchpad or a wheel.
+  `SYS_WIN_SET_CURSOR` (117) sets the caller's content cursor and
+  `SYS_WM_SET_CURSOR` (118) the WM's override (see the Mouse cursors bullet).
   `SYS_WIN_RESIZE_SELF` (115) lets a canvas window grow or shrink itself and
   `SYS_SCREEN_INFO` (116) returns the framebuffer dimensions; the panel uses
   them to collapse to the pills or grow over an expanded section.  The kernel
@@ -489,7 +498,7 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   press/release edges with a capture window, so a click that starts in a
   window still gets its release after the pointer leaves.  The userland
   `ngui.c/h` immediate-mode toolkit builds on those: clipped RGB565
-  primitives, buttons, text input, procedural icons and scrolling panes
+  primitives, buttons, text input, the Adwaita symbolic icons and scrolling panes
   (`ngui_scroll`; `hide_bar` keeps wheel/key scrolling without drawing a
   scrollbar).
   `files` (`ucmd_files.c`) is its first user; `gallery` (`gallery.c`) is the
@@ -1004,9 +1013,75 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `wifi.c` reloads on the next use.  Tested by QEMU `usb-host` passthrough
   on xHCI (C-cut chip, firmware 42.4): 2.4 + 5 GHz scan, WPA2-PSK connect
   and DHCP through the control panel.
+- **Mouse cursors**: the set is GNOME's Adwaita theme (adwaita-cursors 51,
+  LGPL-3 or CC-BY-SA-3.0).  `assets/cursors/adwaita/` holds its Xcursor
+  files trimmed to the 24 px images (`tools/xcursor_trim.py`; the X11 alias
+  symlinks and `X_cursor` are not copied); `tools/mkcursors.c` converts them
+  into one `NBCUR1` bundle (`include/cursor_abi.h`: header, per-shape
+  w/h/hotspot/frames/delay/offset, premultiplied ARGB8888 frames), packed as
+  `cursors/adwaita24.cur` in the **full pack only** (~146 KB, ~18 KB gzip;
+  the floppy lite pack had ~2 KB of room left, so a floppy boot keeps the
+  built-in 16x16 arrow of `cursor_shape.h`).  `CURSOR_LIST` (an X-macro in
+  `cursor_abi.h`) is the shape id order, the bundle order and the CSS name
+  table: 35 CSS cursor names (`move` maps to Adwaita's `all-resize`, since
+  its `move` is a symlink to the arrow).  `wait`/`progress` keep every
+  fourth of Adwaita's 60 x 16 ms frames (15 x 64 ms).  `cursor.c/h` copies
+  the bundle out of the ramfs into its own pages after `ramfs_init()` and in
+  `ramfs_replace()` (which frees the old pack), calls `mouse_cursor_reload()`
+  and only then frees the previous copy.  `wm.c` resolves the shape in every
+  `SYS_WM_POLL`: the WM override (`SYS_WM_SET_CURSOR`), else the cursor of
+  the window holding the pointer capture, else the content cursor
+  (`SYS_WIN_SET_CURSOR`, `struct window.cursor`) of the window under the
+  pointer (not on a normal window's 16 px grip), else `CURSOR_DEFAULT`; a WM
+  restart clears the override.  The ring-3 WM overrides with resize arrows
+  on the grip and while resizing, the move cross during a title-bar drag
+  (once it moved), and a hand over launchers and the status area.  ngui
+  resets `ui->cursor` to the arrow for every redrawn frame (begin returned
+  1), `ngui_text_input` asks for the I-beam (not-allowed when disabled),
+  apps use `ngui_cursor_rect()`/`ngui_set_cursor()`, and `ngui_end_ex()`
+  sends it when it changed.  The terminal sets the I-beam once; the browser
+  parses the inherited CSS `cursor` (the keyword after the last comma;
+  `br_style.cursor` is shape + 1, 0 = auto) and for `auto` uses a hand over
+  links, the I-beam over text fields and `progress` while loading; the
+  gallery's Cursors section shows every shape; `browser-host` maps the
+  shapes to SDL system cursors.
+- **UI icons**: ngui's icons are GNOME Adwaita symbolic icons
+  (adwaita-icon-theme 51, LGPL-3 or CC-BY-SA-3.0).  `assets/icons/adwaita/`
+  holds the unchanged `*-symbolic.svg` files; `ICON_LIST` (an X-macro in
+  `include/icon_abi.h`: enum suffix, short name, theme file) is the icon id
+  order and the bundle order, so append only, and it generates
+  `enum ngui_icon` (`NGUI_ICON_FOLDER` .. `NGUI_ICON_MENU`,
+  `NGUI_ICON_COUNT`) and `ngui_icon_name()`.  `tools/mkicons.c` rasterizes
+  each SVG with the browser's `svg_raster.c` into a 16x16 8-bit coverage
+  mask and writes one `NBICO1` bundle (16-byte header + masks, ~3.3 KB,
+  ~0.8 KB gzip) packed as `icons/adwaita16.icn` in **both** packs.  Its XML
+  reader handles only what symbolic icons use (`<svg viewBox>`, `<g>`,
+  `<path>`, `<rect>`, `<circle>`, `<ellipse>`, fill/fill-rule/opacity) and
+  fails the build on transforms, strokes, `style` or unknown elements.
+  `ngui_icon()` reads the bundle once per process into a BSS buffer (not
+  the libc heap, so the browser's `heap_reset()` cannot free it; the read is
+  capped at the ids this build knows, so a newer bundle with appended icons
+  still works) and blends the mask tinted with the caller's colour, centred
+  in the rectangle and clipped.  There is no line-drawn fallback: without
+  the bundle an icon is left blank (the old procedural drawings cost ~2 KB
+  of code per app and the floppy has a few hundred bytes to spare).
+  `browser-host` symlinks the repository's `icons/` into its `/ramfs` like
+  `fonts/`.
 - **Mouse**: `mouse.c/h` — cursor move/draw shared by the PS/2 path
-  (IntelliMouse including the 4th-byte wheel, Cirrus/Radeon hardware
-  cursor) and the USB backend.  Scroll from every backend accumulates in
+  (IntelliMouse including the 4th-byte wheel, Cirrus/Radeon/Intel hardware
+  cursor) and the USB backend.  `cur_x/cur_y` are the hotspot; the image is
+  drawn with its top-left at hotspot minus the image hotspot, so it can be
+  partly off the top/left edge.  The software cursor saves up to 32x32
+  pixels (`CURSOR_MAX_DIM`) and blends the premultiplied ARGB over them
+  (decoding RGB565 or BGR from the saved background); a shape change
+  presents the union of the old and new rectangles at once.  Intel
+  Ironlake and Radeon copy the image into their 64x64 ARGB planes (Intel's
+  CURPOS takes sign-magnitude negatives; Radeon clamps the position at 0
+  and skips the hidden part with `HORZ_VERT_OFF` and a `CUR_OFFSET` shifted
+  by 256 bytes per row, like Linux's legacy path); Cirrus thresholds alpha
+  at 50% into its AND/XOR planes (white/black by luminance) and clamps the
+  position at 0.  An image upload never runs from IRQ12, which only moves.
+  Animated shapes advance from `mouse_poll_update()`.  Scroll from every backend accumulates in
   `mouse_scroll_y` and `mouse_scroll_take()` hands it to the WM in pixels;
   one PS/2 wheel notch is 48 px.  `usbhid.c/h` — USB HID boot devices: find
   + configure a mouse and/or keyboard, arm their interrupt endpoints, decode
@@ -1268,8 +1343,8 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   is the variant that runs the bookkeeping without publishing the canvas, for
   apps that poll input without redrawing.
 - **Gallery**: `gallery.c` is the ngui widget gallery: typography and
-  truncation, the drawing primitives and clip stack, the theme palette, all
-  nine icons, live buttons/icon buttons, text fields (including a disabled,
+  truncation, the drawing primitives and clip stack, the theme palette, every
+  icon in `ICON_LIST`, live buttons/icon buttons, text fields (including a disabled,
   read-only field) with event feedback, a nested draggable scroll pane and the
   `ngui_cut_*` layout helpers.  The real
   ELF ships in the pack as `bin/gallery.app`; `ucmd_gallery.c` is the tiny
@@ -1285,7 +1360,8 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   with mirrored corner indices, notched corners and pixel-art J/Q/K portraits;
   the back is the castle.  The bar's "Cards" button launches
   `/ramfs/bin/solitaire`.
-- **Browser**: the real browser ships in the pack as `bin/browser.app`
+- **Browser**: the real browser ships in the full pack as `bin/browser.app`
+  (not in the floppy lite pack: floppy boots load `BROWSER` from `root.img`)
   (it links ngui, the full image library, inflate, TLS, uhttp and the
   vendored QuickJS engine in `third_party/quickjs/`, but the rootfs is no longer
   constrained by the kernel's low-memory window).
@@ -1387,6 +1463,25 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   so later visits to a bare domain go straight to its canonical scheme/host.
   Remote stylesheets are cached under `/share/bcss-*` for the current boot, so
   a reload or a fresh browser launch does not fetch the same CSS sheets again.
+  **Visit history and URL-bar autocomplete**: every page that finishes
+  loading (not `about:`, URLs under 512 bytes) is recorded in a 128-entry
+  BSS table (`hist_tab`: URL, title, visit count, stamp; the page heap is
+  reset per navigation, so it cannot live there).  The stamp is a counter
+  carried in the file (max + 1 per visit), so it orders visits across
+  windows and reboots without a wall clock; a full table evicts the lowest
+  stamp.  The boot's windows share `/share/bhist`, rewritten on every visit
+  after merging the current file in (max visits, newest title), and
+  `persist_tick()` copies it to `/data/BHIST.DAT` (8.3, plaintext
+  `NBHIST1\n` then `<visits> <stamp> <url>\t<title>\n`); startup reads
+  `/share` first, else `/data`.  While the address bar has the focus a
+  dropdown lists up to six entries: an empty bar shows the top sites, typing
+  ranks prefixes of the URL (also without scheme or `www.`) over URL and
+  then title substrings, plus visits and recency.  Typing at the end also
+  completes inline to the next `/` of the best prefix match, selected, and
+  Enter on that text opens the URL it came from (scheme included).
+  Up/Down preview a row in the bar, Delete forgets the highlighted row,
+  Esc closes the list (and drops the completion), a click opens a row.
+  The in-session back/forward stack (`history[]`, 16 entries) is separate.
   Images are prefetched up to four at a time and only when their measured
   position is within the viewport plus 160 px; deferred images are loaded as
   the page scrolls.  Network work runs in up to `FETCH_WORKERS` (four)
@@ -1627,7 +1722,21 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `value`/`checked`/`selectedIndex` properties read/write the live control
   state.  Forms expose `elements`/`length`/`submit()`/`reset()`; typing and
   checkbox/select changes fire `input` and `change`, and submit/reset fire
-  their cancellable events.  Flex/grid, basic tables, inline SVG and CSS
+  their cancellable events.  A control with author CSS (background, border
+  or radius -- `background:transparent;border:none` counts, which is why
+  `background: transparent|none` is a real cascaded value, `PROP_BG_NONE`)
+  is painted with that background/border/radius and text colour and sized
+  from its padding, height, min-width and margins (buttons border-box);
+  unstyled controls keep the ngui theme look.  Scripting is always on, so
+  `<noscript>` is a raw-text, `display:none` element: google.com's
+  noscript meta refresh plus `table,div,span,p{display:none}` used to hide
+  the whole page.  URLs (`BR_URL_MAX`, `href`/`src` attributes, the helper
+  request/meta files, `UHTTP_PATH_MAX`) hold 4 KB: google.com's script URL
+  is ~3.7 KB.  Inline `<style>` text is collected up to 256 KB
+  (`BR_CSS_SIZE`; google.com inlines ~94 KB).  Media features with a known
+  answer are evaluated (`forced-colors: none`, normal contrast,
+  `hover: hover`, `pointer: fine`); unknown ones stay true.  Flex/grid,
+  basic tables, inline SVG and CSS
   variables are supported (see known issue 22 for the remaining CSS and DOM
   gaps).  `SYS_SPAWN`
   loads FAT ELFs through `kmalloc` now (the old 16 KB `fat_load_buf` is gone)
@@ -1685,7 +1794,7 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   deletion); uhttp stores every `Set-Cookie` (redirects too), sends matching
   cookies on each hop, splits requests/bodies into 1024-byte TLS records or
   MSS-sized TCP sends, takes `accept`/`extra_headers`, follows up to 8
-  redirects with 1 KB paths and 1.5 KB header lines, and treats 1xx/204/304
+  redirects with 4 KB paths and 4.5 KB header lines, and treats 1xx/204/304
   as bodyless.  `ujson.c/h` is the arena JSON DOM parser (caller-owned node
   and string pools, \uXXXX/surrogates to UTF-8, depth 48).  Host tests:
   `make test-chat`; `tools/mock_chat.py` mocks Chat + the OIDC provider on
@@ -1884,9 +1993,11 @@ inflates it into page-allocated memory and mounts it read-only at `/ramfs`.
 The kernel image no longer contains it, so the pack no longer moves `_end`;
 the high-memory legacy path supports up to 2 MB (known issue 8).  The UI
 font subsets live in the pack under `fonts/`, the WiFi firmware under
-`firmware/`, and the flat kernel at `install/kernel.bin` (full pack only;
+`firmware/`, the mouse cursors at `cursors/adwaita24.cur` (full pack only),
+the UI icons at `icons/adwaita16.icn` (both packs) and the flat kernel at `install/kernel.bin` (full pack only;
 `install self` reads it).  The floppy images use `cmds-lite.pack` (no
-firmware and no `install/kernel.bin`, to stay inside 1.44 MB).
+firmware, cursor bundle, `install/kernel.bin` or `bin/browser.app`, to stay
+inside 1.44 MB; the browser launcher falls back to `BROWSER` on `root.img`).
 
 `rootfs.bin` is the floppy append (header + lite pack); `rootfs-full.bin`
 is the header + full gzip pack used by `make net-install`; `cmds.img` is the
@@ -2075,10 +2186,20 @@ briefly reporting disconnected.
   bounded wait for the BIOS-owned semaphore to clear, and only programs
   `CONFIG`/`DCBAAP`/scratchpads/`CRCR`/`ERST` once the post-reset controller
   is halted.  Port reset clears stale change latches, waits for `PRC` then
-  `PED`, and adds the 10 ms USB2 reset-recovery delay.  The BSR Address
-  Device uses the port-speed EP0 max packet size (64 for high/full speed,
-  8 for low speed); using 8 for a high-speed slot leaves EP0 unusable on
-  real xHCs.  Enumeration uses the traditional scheme: **SET_ADDRESS before
+  `PED`, and adds the 10 ms USB2 reset-recovery delay.  Only a USB2 port
+  is disabled (PED write) before the reset: on a SuperSpeed port that puts
+  the link into SS.Disabled, which a hot reset does not leave.  Address
+  Device programs the speed's fixed EP0 max packet size (8 low, 64 high,
+  512 SuperSpeed) whatever the core passes; only a full-speed EP0 takes the
+  core's 8-byte first guess and is then corrected with an **Evaluate
+  Context** once the core reads the real `bMaxPacketSize0`.  Without that
+  the VIA VL805 (`1106:3483`) on the 970A-DS3P kept an 8-byte EP0 for a
+  high-speed stick, and the 18-byte descriptor read failed with Babble
+  Detected, so a USB-booted stick never became `usb0` for `install`.  The
+  Setup TRB's Transfer Type field is only set on xHCI >= 1.0 (reserved in
+  0.96).  The init line (`xhci: <pci id> hci <ver> ...`) and every failed
+  control transfer (request, completion code, PORTSC, slot/EP0 state) are
+  always logged to COM1/netmon.  Enumeration uses the traditional scheme: **SET_ADDRESS before
   the first descriptor read**.  The xHCI SET_ADDRESS intercept creates the
   slot in the Enabled state and issues Address Device with **BSR=0**
   directly (Enabled -> Addressed), never leaving the slot in the Default
@@ -2348,8 +2469,9 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
    ~204 KiB gzip), the RTL8821A firmware and tables (31,898 + 11,668
    bytes) and `install/kernel.bin` is ~1.88 MiB gzip (~120 KB under the
    cap), inflating to ~3.6 MB, which adds about
-   half a second to the boot; the floppy lite pack is ~930 KiB gzip and
-   deliberately omits the firmware and `install/kernel.bin`.  `libdeflate-gzip -12` is still preferred.  Over
+   half a second to the boot; the floppy lite pack is ~580 KiB gzip and
+   deliberately omits the firmware, `install/kernel.bin` and the browser
+   (`BROWSER` on `root.img` is the floppy copy).  `libdeflate-gzip -12` is still preferred.  Over
    115200 serial a raw `cmds-dev` pack (3.5 MiB) now takes about four
    minutes; use `net-cmds`.
 9. SMP is **ACPI/MADT only**: no Intel MP-table fallback, so a Pentium II SMP
@@ -2417,9 +2539,9 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     (8 slots x 1 KB), and the FAT listing cache another 5 KB.  The command
     pack is out of the kernel now; after the WiFi/netmenu/install code and the
     per-connection TCP queues moved to the frame allocator, `_end` is
-    ~0x8a440 (with the 6200/6300 DVM layer, the RTL8821AU driver, the
+    ~0x8eb20 (with the 6200/6300 DVM layer, the RTL8821AU driver, the
     8×16 boot-console font, the IOAPIC/AMD-thermal additions and the safe
-    AMD MTRR path), ~23 KB below the `0x90000` wall, and the remaining limit
+    AMD MTRR path and the 32x32 cursor save buffer), ~5 KB below the `0x90000` wall, and the remaining limit
     is kernel code/buffers only.
 
 22. Browser limits: JavaScript runs inline and external classic scripts on
@@ -2487,7 +2609,12 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     painting without moving flow (and joins the deferred stack when it has a
     z-index), and `position:sticky` supports top and
     bottom offsets and clamps to the containing block.  `prefers-color-scheme`
-    media queries are ignored so the page's base palette is used.  Block
+    media queries are ignored so the page's base palette is used, and
+    `forced-colors`/`prefers-contrast`/`hover`/`pointer` are answered for a
+    normal-contrast mouse screen.  A flex row narrower than 160 px is still a
+    row when its items fit, and `align-self` overrides the row's
+    `align-items`; a clamped `max-width` makes `margin: auto` centre the
+    box.  Block
     `width`/`max-width`/`min-width`, content-box `height` with `min`/`max`,
     `box-sizing: border-box`, `margin: 0 auto` and `calc(percent ± px)`
     work in widths, margins/padding, heights and min/max;
@@ -2804,3 +2931,17 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     for a few seconds on the first `wifi` command.  A plugged-in stick
     always wins over the built-in Intel card; there is no command to pick
     the Intel card while it is attached.
+
+39. Mouse cursor limits: one fixed 24 px theme (no HiDPI size selection or
+    user theme switch), no CSS `url()` cursors (the fallback keyword after
+    the last comma is used) and no `none`/hidden cursor (it maps to the
+    arrow).  Floppy boots have only the built-in 16x16 arrow, because the
+    lite pack has no room for the ~18 KB gzip bundle.  Cirrus is
+    two-colour, and its position cannot go negative, so near the top/left
+    edge the hotspot is off by up to the image's hotspot offset.  The
+    Intel/Radeon image upload (16 KB, plus `wbinvd` on Intel) also runs
+    for every spinner frame; both paths were written from the Linux
+    drivers and only Cirrus and the software cursor are tested in QEMU.
+    The cursor shape follows the WM poll, so it can lag the pointer by
+    one WM loop.  The 4 KB save buffer and the cursor code (~8 KB in all) leave `_end` at
+    ~0x8eb20, ~5 KB below the `0x90000` wall.

+ 55 - 12
Makefile

@@ -71,7 +71,7 @@ EFI_LDFLAGS = -nostdlib -Wl,--subsystem,10 -Wl,-e,efi_main \
               -Wl,--image-base,0x0 -Wl,--dynamicbase \
               -Wl,--enable-reloc-section -Wl,--no-insert-timestamp
 
-.PHONY: all clean run run-smp run-floppy run-usb run-uhci run-ehci run-ehci-asix run-xhci run-xhci-asix run-net run-rndis run-e1000 run-ahci run-amd test-amd test-usb test-install run-serial floppy usb uefi run-uefi test-uefi flash dev net-dev net-install cmds-dev net-cmds browser-dev gallery-dev compat-serve netmon monitor test-crypto test-wpa test-ccmp test-images test-images-asan test-libc test-js test-font test-font-asan test-svg test-touchpad test-chat test-chat-e2e test-wifi-store fonts kernel-dev kernel-net-dev rootfs nowm
+.PHONY: all clean run run-smp run-floppy run-usb run-uhci run-ehci run-ehci-asix run-xhci run-xhci-asix run-net run-rndis run-e1000 run-ahci run-amd test-amd test-usb test-install run-serial floppy usb uefi run-uefi test-uefi flash dev net-dev net-install cmds-dev net-cmds browser-dev gallery-dev compat-serve netmon monitor test-crypto test-wpa test-ccmp test-images test-images-asan test-libc test-js test-font test-font-asan test-svg test-touchpad test-chat test-chat-e2e test-wifi-store test-cursors fonts kernel-dev kernel-net-dev rootfs nowm
 
 all: floppy.img usb.img final.bin root.img image.bin
 
@@ -113,7 +113,7 @@ KERNEL_LINK_ORDER = vesa_stage entry kernel timer switch sched process mm \
 	terminal wm reboot poweroff disk fat serial serial_ring_buf serial_loop \
 	vga blit cpu thermal it87 tpec ec cros_ec power_src power vga_copy \
 	gfxbench gpu backlight ati cirrus intel nvidia nv50 radeon mtrr \
-	font_8x8 font_8x16 fbtext gfx display mouse i2c touchpad \
+	font_8x8 font_8x16 fbtext gfx display cursor mouse i2c touchpad \
 	touchpad_gesture uhci ohci ehci xhci asix rndis iwl_trans iwl_mvm \
 	iwl_dvm wifi_fw rtl8821au wifi ccmp usb usbmsc usbhid lsusb panic \
 	bootcon blkdev sdhci ata ahci fatdetect fatformat format install vfs \
@@ -471,7 +471,8 @@ $(call app,chat).elf: $(call app,chat).o $(CHAT_LOGIN) $(UJSON) $(UHTTP_OBJS) $(
 gallery.elf: $(U)/apps/gallery/gallery.o $(NGUI_APP) $(UCMD_LD) $(LIBC_A)
 	$(ULINK)
 
-# browser: the real app ships as bin/browser.app (and BROWSER on root.img)
+# browser: the real app ships as bin/browser.app in the full pack (and
+# BROWSER on root.img, which floppy boots use)
 # because it links ngui, the image library, TLS, uhttp and QuickJS;
 # ucmd_browser.c is the tiny PATH launcher.  Compiled with function sections
 # and linked with --gc-sections: unreachable image, TLS and UI paths are
@@ -567,7 +568,7 @@ $(HOST_BUILD)/js_prelude.o: user/apps/browser/js_prelude.S user/apps/browser/js_
 $(HOST_BUILD)/user/apps/browser/browser.o: HOST_EXTRA = -D_start=browser_start
 $(HOST_BUILD)/user/apps/curl/ucmd_curl.o: HOST_EXTRA = -D_start=curl_start
 
-browser-host: host-curl $(HOST_BROWSER_OBJS)
+browser-host: host-curl $(HOST_BROWSER_OBJS) | icons/adwaita16.icn
 	$(HOST_CC) $(HOST_LDFLAGS) -o $@ $(filter-out host-curl,$^) $(HOST_LDLIBS)
 
 host-curl: $(HOST_CURL_OBJS)
@@ -754,6 +755,15 @@ netkexec_send: tools/netkexec_send.c
 netmonitor: tools/netmonitor.c
 	gcc -O2 -o $@ $<
 
+mkicons: tools/mkicons.c include/icon_abi.h user/apps/browser/svg_raster.c user/apps/browser/svg_raster.h
+	gcc -O2 -Wall -Wextra -Iinclude -o $@ tools/mkicons.c user/apps/browser/svg_raster.c -lm
+
+mkcursors: tools/mkcursors.c include/cursor_abi.h
+	gcc -O2 -Wall -Wextra -Iinclude -o $@ $<
+
+cursor_test: tools/cursor_test.c include/cursor_abi.h
+	gcc -O1 -g -Wall -Wextra -fsanitize=address,undefined -Iinclude -o $@ $<
+
 # ---- Command pack (the system rootfs) ---------------------------------------
 #
 # The ring-3 command ELFs plus hello and the browser/gallery apps, packed
@@ -761,13 +771,44 @@ netmonitor: tools/netmonitor.c
 FONT_FILES = fonts/sans.ttf fonts/sans-b.ttf fonts/sans-i.ttf \
              fonts/sans-bi.ttf fonts/mono.ttf fonts/emoji.ttf
 
+# Mouse cursors: the Adwaita theme's 24 px images (assets/cursors/adwaita/,
+# LGPL-3 / CC-BY-SA-3.0) converted to one NBCUR1 bundle (include/cursor_abi.h)
+# that kernel/cursor.c loads from /ramfs/cursors/adwaita24.cur.  Full pack
+# only (~18 KB gzip): the floppy lite pack has no room, and its kernel keeps
+# the built-in 16x16 arrow.
+CURSOR_THEME = assets/cursors/adwaita
+CURSOR_FILE = cursors/adwaita24.cur
+$(CURSOR_FILE): mkcursors $(filter-out %/README %/COPYING%,$(wildcard $(CURSOR_THEME)/*))
+	@mkdir -p cursors
+	./mkcursors $(CURSOR_THEME) 24 $@
+
+# Defined after CURSOR_FILE: make expands a rule's prerequisites at once.
+test-cursors: cursor_test $(CURSOR_FILE)
+	./cursor_test $(CURSOR_FILE)
+
+# UI icons: the Adwaita symbolic SVGs (assets/icons/adwaita/, LGPL-3 /
+# CC-BY-SA-3.0) rasterized by mkicons (with the browser's svg_raster.c) into
+# one NBICO1 bundle of 16 px coverage masks (include/icon_abi.h) that ngui
+# loads from /ramfs/icons/adwaita16.icn and tints.  ~3.3 KB (~0.8 KB gzip),
+# so the floppy lite pack carries it as well.
+ICON_THEME = assets/icons/adwaita
+ICON_FILE = icons/adwaita16.icn
+$(ICON_FILE): mkicons $(wildcard $(ICON_THEME)/*.svg)
+	@mkdir -p icons
+	./mkicons $(ICON_THEME) 16 $@
+
 HELLO_ELF = $(U)/apps/hello/hello.elf
 PACK_FILES = $(foreach a,$(UCMDS),bin/$(a)=$(call app,$(a)).elf) \
              bin/hello=$(HELLO_ELF) \
-             bin/browser.app=browser.elf \
              bin/gallery.app=gallery.elf \
-             $(foreach f,$(FONT_FILES),$(f)=$(f))
-PACK_DEPS = $(UCMD_ELFS) $(HELLO_ELF) browser.elf gallery.elf $(FONT_FILES) mkpack
+             $(foreach f,$(FONT_FILES),$(f)=$(f)) \
+             $(ICON_FILE)=$(ICON_FILE)
+PACK_DEPS = $(UCMD_ELFS) $(HELLO_ELF) browser.elf gallery.elf $(FONT_FILES) \
+            $(ICON_FILE) mkpack
+PACK_CURSOR_FILES = $(CURSOR_FILE)=$(CURSOR_FILE)
+# The browser (~500 KB gzip) is in the full pack only: a floppy boot runs it
+# from BROWSER on root.img, which the bin/browser launcher already tries.
+PACK_BROWSER_FILES = bin/browser.app=browser.elf
 
 # `install self` reads the flat kernel from the full pack.  The lite/floppy
 # pack deliberately omits it (no room on a 1.44 MB disk).
@@ -818,11 +859,13 @@ firmware/rtl8821a.tbl: mkrtwtbl
 	@mkdir -p firmware
 	./mkrtwtbl $@
 
-cmds.pack: $(PACK_DEPS) $(WIFI_FW_FILE) kernel.bin
-	./mkpack $@ $(PACK_FILES) $(PACK_INSTALL_FILES) $(PACK_FW_FILES)
+cmds.pack: $(PACK_DEPS) $(WIFI_FW_FILE) $(CURSOR_FILE) kernel.bin
+	./mkpack $@ $(PACK_FILES) $(PACK_BROWSER_FILES) $(PACK_CURSOR_FILES) \
+	    $(PACK_INSTALL_FILES) \
+	    $(PACK_FW_FILES)
 
 # The floppy images cannot hold the ~1 MB firmware: they get the same pack
-# without firmware/*.
+# without firmware/* (and without the cursor bundle or bin/browser.app).
 cmds-lite.pack: $(PACK_DEPS)
 	./mkpack $@ $(PACK_FILES)
 
@@ -1184,8 +1227,8 @@ clean:
 	      BOOTX64.EFI browser.elf gallery.elf *.boot.tmp \
 	      cmds.pack cmds-lite.pack cmds_pack_gz.bin cmds_lite_gz.bin \
 	      rootfs.bin rootfs-full.bin cmds.img \
-	      firmware/*.ucode firmware/*.tbl firmware/*.bin \
-	      mkpack mkrootfs mkrtwtbl kexec_send netkexec_send netmonitor \
+	      firmware/*.ucode firmware/*.tbl firmware/*.bin cursors/*.cur icons/*.icn \
+	      mkpack mkrootfs mkrtwtbl mkcursors mkicons cursor_test kexec_send netkexec_send netmonitor \
 	      browser-host host-curl \
 	      ufont_test ufont_test_asan svg_test touchpad_gesture_test \
 	      ujson_test uhttp_cookie_test chat_login_test tls_test wpa_test \

+ 10 - 0
assets/cursors/adwaita/COPYING

@@ -0,0 +1,10 @@
+This work is licenced under the terms of either the GNU LGPL v3 or
+Creative Commons Attribution-Share Alike 3.0 United States License.
+
+To view a copy of the CC-BY-SA licence, visit
+http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
+Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA.
+
+When attributing the artwork, using "GNOME Project" is enough.
+Please link to http://www.gnome.org where available.
+

+ 7 - 0
assets/cursors/adwaita/COPYING_CCBYSA3

@@ -0,0 +1,7 @@
+This work is licenced under the Creative Commons Attribution-Share Alike 3.0
+United States License. To view a copy of this licence, visit
+http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
+Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA.
+
+When attributing the artwork, using "GNOME Project" is enough. 
+Please link to http://www.gnome.org where available.

+ 165 - 0
assets/cursors/adwaita/COPYING_LGPL

@@ -0,0 +1,165 @@
+                   GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+  This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+  0. Additional Definitions.
+
+  As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+  "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+  An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+  A "Combined Work" is a work produced by combining or linking an
+Application with the Library.  The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+  The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+  The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+  1. Exception to Section 3 of the GNU GPL.
+
+  You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+  2. Conveying Modified Versions.
+
+  If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+   a) under this License, provided that you make a good faith effort to
+   ensure that, in the event an Application does not supply the
+   function or data, the facility still operates, and performs
+   whatever part of its purpose remains meaningful, or
+
+   b) under the GNU GPL, with none of the additional permissions of
+   this License applicable to that copy.
+
+  3. Object Code Incorporating Material from Library Header Files.
+
+  The object code form of an Application may incorporate material from
+a header file that is part of the Library.  You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+   a) Give prominent notice with each copy of the object code that the
+   Library is used in it and that the Library and its use are
+   covered by this License.
+
+   b) Accompany the object code with a copy of the GNU GPL and this license
+   document.
+
+  4. Combined Works.
+
+  You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+   a) Give prominent notice with each copy of the Combined Work that
+   the Library is used in it and that the Library and its use are
+   covered by this License.
+
+   b) Accompany the Combined Work with a copy of the GNU GPL and this license
+   document.
+
+   c) For a Combined Work that displays copyright notices during
+   execution, include the copyright notice for the Library among
+   these notices, as well as a reference directing the user to the
+   copies of the GNU GPL and this license document.
+
+   d) Do one of the following:
+
+       0) Convey the Minimal Corresponding Source under the terms of this
+       License, and the Corresponding Application Code in a form
+       suitable for, and under terms that permit, the user to
+       recombine or relink the Application with a modified version of
+       the Linked Version to produce a modified Combined Work, in the
+       manner specified by section 6 of the GNU GPL for conveying
+       Corresponding Source.
+
+       1) Use a suitable shared library mechanism for linking with the
+       Library.  A suitable mechanism is one that (a) uses at run time
+       a copy of the Library already present on the user's computer
+       system, and (b) will operate properly with a modified version
+       of the Library that is interface-compatible with the Linked
+       Version.
+
+   e) Provide Installation Information, but only if you would otherwise
+   be required to provide such information under section 6 of the
+   GNU GPL, and only to the extent that such information is
+   necessary to install and execute a modified version of the
+   Combined Work produced by recombining or relinking the
+   Application with a modified version of the Linked Version. (If
+   you use option 4d0, the Installation Information must accompany
+   the Minimal Corresponding Source and Corresponding Application
+   Code. If you use option 4d1, you must provide the Installation
+   Information in the manner specified by section 6 of the GNU GPL
+   for conveying Corresponding Source.)
+
+  5. Combined Libraries.
+
+  You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+   a) Accompany the combined library with a copy of the same work based
+   on the Library, uncombined with any other library facilities,
+   conveyed under the terms of this License.
+
+   b) Give prominent notice with the combined library that part of it
+   is a work based on the Library, and explaining where to find the
+   accompanying uncombined form of the same work.
+
+  6. Revised Versions of the GNU Lesser General Public License.
+
+  The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+  Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+  If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.

+ 19 - 0
assets/cursors/adwaita/README

@@ -0,0 +1,19 @@
+Adwaita cursor theme (24 px images only)
+
+Source:  the Arch Linux package adwaita-cursors 51.0
+         (/usr/share/icons/Adwaita/cursors), upstream
+         https://gitlab.gnome.org/GNOME/adwaita-icon-theme
+Licence: GNU LGPL v3 or Creative Commons Attribution-Share Alike 3.0
+         (see COPYING, COPYING_LGPL, COPYING_CCBYSA3).  Attribution:
+         "GNOME Project", https://www.gnome.org
+
+Each file is a valid Xcursor file reduced to its 24 px image chunks by
+tools/xcursor_trim.py (the upstream files also carry 30..96 px images):
+
+    python3 tools/xcursor_trim.py /usr/share/icons/Adwaita/cursors \
+        assets/cursors/adwaita 24
+
+The legacy X11 aliases (left_ptr, xterm, hand2, ...) are symlinks upstream
+and were not copied; X_cursor was dropped.  tools/mkcursors.c converts these
+files into the NBCUR1 bundle (include/cursor_abi.h) that is packed as
+/ramfs/cursors/adwaita24.cur.

BIN
assets/cursors/adwaita/alias


BIN
assets/cursors/adwaita/all-resize


BIN
assets/cursors/adwaita/all-scroll


BIN
assets/cursors/adwaita/cell


BIN
assets/cursors/adwaita/col-resize


BIN
assets/cursors/adwaita/context-menu


BIN
assets/cursors/adwaita/copy


BIN
assets/cursors/adwaita/crosshair


BIN
assets/cursors/adwaita/default


BIN
assets/cursors/adwaita/e-resize


BIN
assets/cursors/adwaita/ew-resize


BIN
assets/cursors/adwaita/grab


BIN
assets/cursors/adwaita/grabbing


BIN
assets/cursors/adwaita/help


BIN
assets/cursors/adwaita/n-resize


BIN
assets/cursors/adwaita/ne-resize


BIN
assets/cursors/adwaita/nesw-resize


BIN
assets/cursors/adwaita/no-drop


BIN
assets/cursors/adwaita/not-allowed


BIN
assets/cursors/adwaita/ns-resize


BIN
assets/cursors/adwaita/nw-resize


BIN
assets/cursors/adwaita/nwse-resize


BIN
assets/cursors/adwaita/pointer


BIN
assets/cursors/adwaita/progress


BIN
assets/cursors/adwaita/row-resize


BIN
assets/cursors/adwaita/s-resize


BIN
assets/cursors/adwaita/se-resize


BIN
assets/cursors/adwaita/sw-resize


BIN
assets/cursors/adwaita/text


BIN
assets/cursors/adwaita/vertical-text


BIN
assets/cursors/adwaita/w-resize


BIN
assets/cursors/adwaita/wait


BIN
assets/cursors/adwaita/zoom-in


BIN
assets/cursors/adwaita/zoom-out


+ 10 - 0
assets/icons/adwaita/COPYING

@@ -0,0 +1,10 @@
+This work is licenced under the terms of either the GNU LGPL v3 or
+Creative Commons Attribution-Share Alike 3.0 United States License.
+
+To view a copy of the CC-BY-SA licence, visit
+http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
+Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA.
+
+When attributing the artwork, using "GNOME Project" is enough.
+Please link to http://www.gnome.org where available.
+

+ 7 - 0
assets/icons/adwaita/COPYING_CCBYSA3

@@ -0,0 +1,7 @@
+This work is licenced under the Creative Commons Attribution-Share Alike 3.0
+United States License. To view a copy of this licence, visit
+http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
+Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA.
+
+When attributing the artwork, using "GNOME Project" is enough. 
+Please link to http://www.gnome.org where available.

+ 165 - 0
assets/icons/adwaita/COPYING_LGPL

@@ -0,0 +1,165 @@
+                   GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+  This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+  0. Additional Definitions.
+
+  As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+  "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+  An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+  A "Combined Work" is a work produced by combining or linking an
+Application with the Library.  The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+  The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+  The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+  1. Exception to Section 3 of the GNU GPL.
+
+  You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+  2. Conveying Modified Versions.
+
+  If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+   a) under this License, provided that you make a good faith effort to
+   ensure that, in the event an Application does not supply the
+   function or data, the facility still operates, and performs
+   whatever part of its purpose remains meaningful, or
+
+   b) under the GNU GPL, with none of the additional permissions of
+   this License applicable to that copy.
+
+  3. Object Code Incorporating Material from Library Header Files.
+
+  The object code form of an Application may incorporate material from
+a header file that is part of the Library.  You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+   a) Give prominent notice with each copy of the object code that the
+   Library is used in it and that the Library and its use are
+   covered by this License.
+
+   b) Accompany the object code with a copy of the GNU GPL and this license
+   document.
+
+  4. Combined Works.
+
+  You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+   a) Give prominent notice with each copy of the Combined Work that
+   the Library is used in it and that the Library and its use are
+   covered by this License.
+
+   b) Accompany the Combined Work with a copy of the GNU GPL and this license
+   document.
+
+   c) For a Combined Work that displays copyright notices during
+   execution, include the copyright notice for the Library among
+   these notices, as well as a reference directing the user to the
+   copies of the GNU GPL and this license document.
+
+   d) Do one of the following:
+
+       0) Convey the Minimal Corresponding Source under the terms of this
+       License, and the Corresponding Application Code in a form
+       suitable for, and under terms that permit, the user to
+       recombine or relink the Application with a modified version of
+       the Linked Version to produce a modified Combined Work, in the
+       manner specified by section 6 of the GNU GPL for conveying
+       Corresponding Source.
+
+       1) Use a suitable shared library mechanism for linking with the
+       Library.  A suitable mechanism is one that (a) uses at run time
+       a copy of the Library already present on the user's computer
+       system, and (b) will operate properly with a modified version
+       of the Library that is interface-compatible with the Linked
+       Version.
+
+   e) Provide Installation Information, but only if you would otherwise
+   be required to provide such information under section 6 of the
+   GNU GPL, and only to the extent that such information is
+   necessary to install and execute a modified version of the
+   Combined Work produced by recombining or relinking the
+   Application with a modified version of the Linked Version. (If
+   you use option 4d0, the Installation Information must accompany
+   the Minimal Corresponding Source and Corresponding Application
+   Code. If you use option 4d1, you must provide the Installation
+   Information in the manner specified by section 6 of the GNU GPL
+   for conveying Corresponding Source.)
+
+  5. Combined Libraries.
+
+  You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+   a) Accompany the combined library with a copy of the same work based
+   on the Library, uncombined with any other library facilities,
+   conveyed under the terms of this License.
+
+   b) Give prominent notice with the combined library that part of it
+   is a work based on the Library, and explaining where to find the
+   accompanying uncombined form of the same work.
+
+  6. Revised Versions of the GNU Lesser General Public License.
+
+  The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+  Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+  If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.

+ 21 - 0
assets/icons/adwaita/README

@@ -0,0 +1,21 @@
+Adwaita symbolic icons (16 px)
+
+Source:  the Arch Linux package adwaita-icon-theme 51.0
+         (/usr/share/icons/Adwaita/symbolic), upstream
+         https://gitlab.gnome.org/GNOME/adwaita-icon-theme
+Licence: GNU LGPL v3 or Creative Commons Attribution-Share Alike 3.0
+         (see COPYING, COPYING_LGPL, COPYING_CCBYSA3).  Attribution:
+         "GNOME Project", https://www.gnome.org
+
+The SVG files are copied unchanged from the symbolic/<context>/ folders
+(the context folder is dropped).  tools/mkicons.c rasterizes them with the
+browser's svg_raster.c into the NBICO1 bundle (include/icon_abi.h), one
+8-bit coverage mask per icon, packed as /ramfs/icons/adwaita16.icn.  ngui
+tints the masks with the theme colour.  ICON_LIST in include/icon_abi.h
+names the file for every icon; to add one, copy its -symbolic.svg here and
+append an ICON_LIST entry.
+
+mkicons understands what these files use: <path d>, <rect>, <circle>,
+<ellipse>, fill / fill-rule / opacity / fill-opacity on the element or an
+enclosing <g>.  It refuses transforms, strokes and anything else instead of
+drawing the icon wrong.

+ 1 - 0
assets/icons/adwaita/drive-harddisk-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M4 0C2.355469 0 1 1.355469 1 3v10c0 1.644531 1.355469 3 3 3h8c1.644531 0 3-1.355469 3-3V3c0-1.644531-1.355469-3-3-3zm0 2h8c.570312 0 1 .429688 1 1v9c0 .570312-.429688 1-1 1H4c-.554688 0-1-.445312-1-1V3c0-.554688.445312-1 1-1m4 1C5.789062 3 4 4.789062 4 7v4h4c2.5 0 4-1.789062 4-4s-1.789062-4-4-4m0 2c1.105469 0 2 .894531 2 2s-.894531 2-2 2-2-.894531-2-2 .894531-2 2-2m0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/folder-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M2.96875 1.003906c-1.644531 0-3 1.355469-3 3v8c0 1.644532 1.355469 3 3 3h10c1.644531 0 3-1.355468 3-3v-6c0-1.644531-1.355469-3-3-3H9.382812L7.675781 1.296875c-.1875-.1875-.441406-.292969-.707031-.292969zm0 2h3.585938l1 1H1.96875c0-.5625.4375-1 1-1m-1 2h11c.5625 0 1 .4375 1 1v6c0 .5625-.4375 1-1 1h-10c-.5625 0-1-.4375-1-1zm0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/go-home-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M8 .363281c-.5 0-1 .167969-1.40625.507813L2.128906 4.59375C1.414062 5.1875 1 6.070312 1 7v6c0 1.65625 1.34375 3 3 3h8c1.65625 0 3-1.34375 3-3V7c0-.929688-.414062-1.8125-1.128906-2.40625L9.40625.871094C9 .53125 8.5.363281 8 .363281m-.015625 1.996094c.050781-.003906.101563.011719.144531.046875l4.464844 3.722656C12.851562 6.34375 13 6.664062 13 7v6c0 .5625-.4375 1-1 1h-2V9c0-.554688-.445312-1-1-1H7c-.554688 0-1 .445312-1 1v5H4c-.5625 0-1-.4375-1-1V7c0-.335938.148438-.65625.40625-.871094L7.871094 2.40625c.035156-.027344.074218-.042969.113281-.046875m0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/go-next-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M4 2c0-.265625.105469-.519531.292969-.707031.390625-.390625 1.023437-.390625 1.414062 0l6 6C11.894531 7.480469 12 7.734375 12 8s-.105469.519531-.292969.707031l-6 6c-.390625.390625-1.023437.390625-1.414062 0C4.105469 14.519531 4 14.265625 4 14s.105469-.519531.292969-.707031L9.585938 8 4.292969 2.707031C4.105469 2.519531 4 2.265625 4 2m0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/go-previous-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M12 2c0-.265625-.105469-.519531-.292969-.707031-.390625-.390625-1.023437-.390625-1.414062 0l-6 6C4.105469 7.480469 4 7.734375 4 8s.105469.519531.292969.707031l6 6c.390625.390625 1.023437.390625 1.414062 0C11.894531 14.519531 12 14.265625 12 14s-.105469-.519531-.292969-.707031L6.414062 8l5.292969-5.292969C11.894531 2.519531 12 2.265625 12 2m0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/go-up-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M1 11c0-.265625.105469-.519531.292969-.707031l6-6c.390625-.390625 1.023437-.390625 1.414062 0l6 6c.1875.1875.292969.441406.292969.707031s-.105469.519531-.292969.707031c-.390625.390625-1.023437.390625-1.414062 0L8 6.414062l-5.292969 5.292969c-.390625.390625-1.023437.390625-1.414062 0C1.105469 11.519531 1 11.265625 1 11m0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/list-add-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M7 1v6H1v2h6v6h2V9h6V7H9V1zm0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/open-menu-symbolic.svg

@@ -0,0 +1 @@
+<svg width="16px" height="16px" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><g fill="#2e3436"><path d="m1 2h14v2h-14z"/><path d="m1 7h14v2h-14z"/><path d="m1 12h14v2h-14z"/></g></svg>

+ 1 - 0
assets/icons/adwaita/process-stop-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M3 2c-.265625 0-.519531.105469-.707031.292969-.390625.390625-.390625 1.023437 0 1.414062L6.585938 8l-4.292969 4.292969c-.390625.390625-.390625 1.023437 0 1.414062s1.023437.390625 1.414062 0L8 9.414062l4.292969 4.292969c.390625.390625 1.023437.390625 1.414062 0s.390625-1.023437 0-1.414062L9.414062 8l4.292969-4.292969c.390625-.390625.390625-1.023437 0-1.414062C13.519531 2.105469 13.265625 2 13 2s-.519531.105469-.707031.292969L8 6.585938 3.707031 2.292969C3.519531 2.105469 3.265625 2 3 2m0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/system-search-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M6.5 0C2.921875 0 0 2.921875 0 6.5s2.921875 6.496094 6.5 6.496094c1.429688 0 2.753906-.464844 3.828125-1.253906l2.945313 2.945312c.957031.9375 2.363281-.5 1.40625-1.4375L11.75 10.320312C12.535156 9.246094 13 7.925781 13 6.5 13 2.921875 10.078125 0 6.5 0m0 2C8.996094 2 11 4.003906 11 6.5s-2.003906 4.496094-4.5 4.496094S2 8.996094 2 6.5 4.003906 2 6.5 2m0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/text-x-generic-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M4.96875 1.003906c-1.644531 0-3 1.355469-3 3v9c0 1.644532 1.355469 3 3 3h6c1.644531 0 3-1.355468 3-3v-7.5c0-.265625-.105469-.519531-.292969-.707031l-3.5-3.5c-.1875-.1875-.441406-.292969-.707031-.292969zm0 2h4v1.5q0 1.5 1.5 1.5h1.5v7c0 .570313-.429688 1-1 1h-6c-.570312 0-1-.429687-1-1v-9c0-.570312.429688-1 1-1m0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/view-refresh-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M7.40625 1c-.613281.007812-1.234375.089844-1.847656.253906C2.285156 2.132812 0 5.109375 0 8.5s2.285156 6.367188 5.558594 7.242188c3.273437.878906 6.742187-.558594 8.4375-3.492188.277344-.480469.109375-1.089844-.367188-1.367188-.476562-.273437-1.089844-.109374-1.367187.367188-1.246094 2.160156-3.777344 3.207031-6.1875 2.5625C3.667969 13.167969 2 10.992188 2 8.5c0-2.496094 1.667969-4.667969 4.074219-5.3125 2.410156-.644531 4.941406.402344 6.1875 2.5625.058593.085938.125.164062.203125.226562l-.019532.015626L12.4375 6H11c-.550781 0-1 .449219-1 1 0 0 0 1 1 1h5V3s.003906-1-1-1c-.550781 0-1 .449219-1 1v1.6875l-.015625.011719-.011719.011719c-1.277344-2.179688-3.53125-3.519532-5.953125-3.691407C7.816406 1.003906 7.613281 1 7.40625 1m0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/window-close-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M4 4h1.03125c.253906.011719.511719.128906.6875.3125L8 6.59375l2.3125-2.28125c.265625-.230469.445312-.304688.6875-.3125h1v1c0 .285156-.035156.550781-.25.75L9.46875 8.03125l2.25 2.25c.1875.1875.28125.453125.28125.71875v1h-1c-.265625 0-.53125-.09375-.71875-.28125L8 9.4375l-2.28125 2.28125C5.53125 11.90625 5.265625 12 5 12H4v-1c0-.265625.09375-.53125.28125-.71875l2.28125-2.25L4.28125 5.75C4.070312 5.554688 3.976562 5.28125 4 5zm0 0"/></svg>

+ 3 - 1
docs/boot.html

@@ -294,7 +294,9 @@
 			The build produces several images from the same boot sector, kernel
 			and rootfs. The floppy images append the <em>lite</em> pack
 			(<code>rootfs.bin</code> from <code>cmds-lite.pack</code>, everything
-			but <code>firmware/*</code>) so they still fit 1.44 MB. The USB
+			but <code>firmware/*</code>, the cursor bundle, the install kernel and
+			<code>bin/browser.app</code>) so they still fit 1.44 MB; a floppy boot
+			runs the browser from <code>BROWSER</code> on <code>root.img</code>. The USB
 			rootfs partition carries the full pack (about 1.3 MB gzip with the
 			WiFi firmware), which now ends past the first 1.44 MB: a BIOS that
 			boots the stick as a CHS-only floppy can no longer read all of it.

+ 2 - 1
docs/development.html

@@ -234,11 +234,12 @@
 					<tr><td><code>make test-js</code></td><td>Host tests (ASan/UBSan) for the vendored QuickJS engine through the <code>js_mu</code> stack API: modern syntax (classes, arrows, templates, destructuring, spread, async/await, BigInt, named regex groups), Promise jobs, C functions and <code>new</code>, thrown TypeErrors, userdata hooks and expandos, registry refs and the wall-clock interrupt.</td></tr>
 					<tr><td><code>make test-font</code> / <code>test-font-asan</code></td><td>Host specimen test for the fixed-point TrueType parser/rasterizer and glyph cache, with an AddressSanitizer/UBSan variant.</td></tr>
 					<tr><td><code>make test-svg</code></td><td>Host tests (ASan/UBSan) for the inline-SVG rasterizer: exact rect coverage, antialiased edges, relative commands, nonzero vs even-odd, circle area, curves and arcs, transforms, number grammar and strokes; <code>./svg_test out.ppm</code> writes a specimen.</td></tr>
+					<tr><td><code>make test-cursors</code></td><td>Host test (ASan/UBSan) for the NBCUR1 cursor bundle built by <code>mkcursors</code>: header and shape count, sizes and hotspots against the Adwaita files, premultiplied pixels, no empty frame, and the 15-frame <code>wait</code>/<code>progress</code> spinners.</td></tr>
 					<tr><td><code>make test-touchpad</code></td><td>Host tests for the device-independent contact gesture engine: taps, right-click zones, physical-button latch, two-finger scroll, direction and pointer re-anchoring.</td></tr>
 					<tr><td><code>make test-chat</code></td><td>Host tests (ASan/UBSan) for the chat client's JSON parser, cookie jar and the OIDC login page/reply/config parsers.</td></tr>
 					<tr><td><code>make test-chat-e2e</code></td><td>Boots QEMU with an NE2000 on slirp, starts <code>tools/mock_chat.py</code> and drives <code>chat</code> through QMP: native login, send, live poll, read marker, older paging, browse/join, new DM, saved-session resume and sign-out.  <code>CHAT_E2E=--totp|--consent|--passkey|--wrong</code> runs a login variant.</td></tr>
 					<tr><td><code>make compat-serve</code></td><td>Serve the browser compatibility ladder from <code>testdata/browser/compat/</code> on port 8000 for the board or QEMU guest.</td></tr>
-					<tr><td><code>make browser-host</code></td><td>Build the Linux SDL3 development harness (<code>browser-host</code> and its <code>host-curl</code> helper). It implements the ring-3 <code>SYS_*</code> ABI with host files, BSD sockets, <code>fork/exec</code> and an SDL3 window, so pages render and accept input without QEMU. Run <code>./browser-host [--size WxH] [--root DIR] URL|FILE</code>; <code>--headless --wait 3000 --shot out.ppm</code> writes the canvas without a display. Needs the 32-bit SDL3/Wayland libraries (<code>lib32-sdl3</code>, <code>lib32-wayland</code>, <code>lib32-libxkbcommon</code>).</td></tr>
+					<tr><td><code>make browser-host</code></td><td>Build the Linux SDL3 development harness (<code>browser-host</code> and its <code>host-curl</code> helper). It implements the ring-3 <code>SYS_*</code> ABI with host files, BSD sockets, <code>fork/exec</code> and an SDL3 window, so pages render and accept input without QEMU. Run <code>./browser-host [--size WxH] [--root DIR] URL|FILE</code>; <code>--headless --wait 3000 --shot out.ppm</code> writes the canvas without a display, and <code>--keys 'clo{down}{enter}'</code> types into it (one key per 100 ms; <code>{enter}</code>, <code>{esc}</code>, <code>{tab}</code>, <code>{bs}</code>, <code>{del}</code>, arrows, <code>{ctrl-l}</code>, <code>{wait}</code>). Needs the 32-bit SDL3/Wayland libraries (<code>lib32-sdl3</code>, <code>lib32-wayland</code>, <code>lib32-libxkbcommon</code>).</td></tr>
 					<tr><td><code>make fonts</code></td><td>Regenerate the checked-in Arimo/Liberation Mono subsets with <code>pyftsubset</code>.</td></tr>
 				</tbody>
 			</table>

+ 1 - 1
docs/drivers.html

@@ -286,7 +286,7 @@
 					<tr><td>UHCI</td><td>PCI I/O ports</td><td>1</td><td>Frame list at <code>0x3000</code>; control QH plus one QH per interrupt slot.</td></tr>
 					<tr><td>OHCI</td><td>PCI MMIO</td><td>up to 4</td><td>HCCA from the page allocator, static ED/TD sets in the uncacheable <code>ohci_dma_page</code>, TDs start at <code>CC = NotAccessed</code>. Before reset it requests SMM ownership (<code>HcCommandStatus.OCR</code>, clear <code>HcControl.IR</code>) and disables the AMD southbridge USB SMI on <code>1002:4385</code>.</td></tr>
 					<tr><td>EHCI</td><td>PCI MMIO</td><td>up to 4</td><td>Async QH/qTD schedule, page-allocated descriptors, polling only, no periodic list.</td></tr>
-					<tr><td>xHCI</td><td>PCI MMIO</td><td>—</td><td>USB2 and USB3 root ports; direct SuperSpeed devices use a 512-byte EP0 and the port speed in the slot context (USB3 hubs are not decoded). Halts and waits for <code>HCH</code> around <code>HCRST</code>; EP0 max packet comes from the port speed; EP0 stages are encoded as one TD per stage (EDK2 style) because chained control TDs stall on Braswell.</td></tr>
+					<tr><td>xHCI</td><td>PCI MMIO</td><td>—</td><td>USB2 and USB3 root ports; direct SuperSpeed devices use a 512-byte EP0 and the port speed in the slot context (USB3 hubs are not decoded). Halts and waits for <code>HCH</code> around <code>HCRST</code>; EP0 max packet is the speed's fixed value (8/64/512), and a full-speed EP0 is corrected with Evaluate Context after the first descriptor read (the VIA VL805 on the 970A-DS3P babbled on a high-speed stick otherwise); a SuperSpeed port is not PED-disabled before its reset; failed control transfers are always logged with their completion code; EP0 stages are encoded as one TD per stage (EDK2 style) because chained control TDs stall on Braswell.</td></tr>
 				</tbody>
 			</table>
 		</div>

+ 58 - 2
docs/graphics.html

@@ -60,6 +60,8 @@
 			<li><a href="#ngui">ngui toolkit</a></li>
 			<li><a href="#apps">Applications</a></li>
 			<li><a href="#images">Image library</a></li>
+			<li><a href="#icons">UI icons</a></li>
+			<li><a href="#cursors">Mouse cursors</a></li>
 			<li><a href="#gpu">GPU quirks</a></li>
 			<li><a href="#backlight">Panel backlight</a></li>
 			<li><a href="#sources">Source map</a></li>
@@ -350,8 +352,8 @@
 		<p>
 			<span class="file">ngui.c</span>/<span class="file">ngui.h</span> is an
 			immediate-mode GUI toolkit shared by the ring-3 apps. It provides
-			clipped RGB565 primitives, buttons, menu items, text fields, nine
-			procedural icons, a theme palette, layout cut helpers and scrolling
+			clipped RGB565 primitives, buttons, menu items, text fields, the
+			Adwaita symbolic icons (see <a href="#icons">UI icons</a>), a theme palette, layout cut helpers and scrolling
 			panes. It is linked into <code>files</code>, <code>mines</code>,
 			<code>solitaire</code>, <code>chat</code>, the control panel and
 			the real <code>gallery.elf</code>.
@@ -441,6 +443,57 @@
 		</ul>
 	</section>
 
+	<section id="icons">
+		<h2>UI icons</h2>
+		<p>
+			ngui's icons (<code>ngui_icon()</code>, <code>ngui_icon_button()</code>:
+			back/forward, reload and home in the browser toolbar, folder/file/drive
+			in <code>files</code>) are GNOME Adwaita symbolic icons
+			(adwaita-icon-theme 51, LGPL-3 or CC-BY-SA-3.0).  The unchanged
+			<code>*-symbolic.svg</code> files live in
+			<span class="file">assets/icons/adwaita/</span>; the host tool
+			<span class="file">tools/mkicons.c</span> rasterizes each one with the
+			browser's <span class="file">svg_raster.c</span> into a 16&times;16
+			8-bit coverage mask and writes one <code>NBICO1</code> bundle,
+			<code>/ramfs/icons/adwaita16.icn</code> (layout in
+			<span class="file">include/icon_abi.h</span>): a 16-byte header and
+			13 masks, ~3.3&nbsp;KB raw and ~0.8&nbsp;KB gzip, so both the USB
+			and the floppy pack carry it.
+		</p>
+		<ul>
+			<li><strong>Icon list.</strong> <code>ICON_LIST</code> is an X-macro of enum suffix, short name and theme file.  Its order is the icon id and the bundle order (append only); it generates <code>enum ngui_icon</code> and <code>ngui_icon_name()</code>, and the gallery shows every entry.</li>
+			<li><strong>Tinting.</strong> Symbolic icons are one colour, so only coverage is stored.  <code>ngui_icon()</code> blends the mask in the caller's colour (the theme text colour on buttons, <code>icon_folder</code>/<code>icon_disk</code>/<code>icon_file</code> in <code>files</code>), centred and clipped.</li>
+			<li><strong>Loading.</strong> Each process reads the bundle once into a BSS buffer, so the browser's <code>heap_reset()</code> cannot free it.  The read is capped at the ids the app was built with, so an older app still works with a newer bundle.  Without the bundle the icon is left blank; there is no line-drawn fallback, because it cost ~2&nbsp;KB of code in each app.</li>
+			<li><strong>Strict converter.</strong> mkicons reads only what symbolic icons use (<code>&lt;svg viewBox&gt;</code>, <code>&lt;g&gt;</code>, <code>&lt;path&gt;</code>, <code>&lt;rect&gt;</code>, <code>&lt;circle&gt;</code>, <code>&lt;ellipse&gt;</code>, fill, fill-rule, opacity) and fails the build on transforms, strokes, <code>style</code> or unknown elements instead of drawing a wrong icon.  <code>./mkicons assets/icons/adwaita 16 out.icn -v</code> prints an ASCII preview of every mask.</li>
+		</ul>
+	</section>
+
+	<section id="cursors">
+		<h2>Mouse cursors</h2>
+		<p>
+			The cursor set is the GNOME Adwaita theme (adwaita-cursors 51,
+			LGPL-3 or CC-BY-SA-3.0).  Its 24&nbsp;px Xcursor images are copied
+			into <span class="file">assets/cursors/adwaita/</span> (trimmed by
+			<span class="file">tools/xcursor_trim.py</span>), and the host tool
+			<span class="file">tools/mkcursors.c</span> turns them into one
+			<code>NBCUR1</code> bundle, <code>/ramfs/cursors/adwaita24.cur</code>
+			(layout in <span class="file">include/cursor_abi.h</span>):
+			35 shapes named after the CSS <code>cursor</code> keywords, each
+			with its size, hotspot, frame count and premultiplied ARGB8888
+			frames.  The animated <code>wait</code>/<code>progress</code>
+			spinners keep every fourth of Adwaita's 60 frames (15 frames at
+			64&nbsp;ms, the same speed).  The bundle is ~146&nbsp;KB raw,
+			~18&nbsp;KB gzip, and only in the full pack: the floppy lite pack
+			has no room, so a floppy boot keeps the built-in 16&times;16 arrow.
+		</p>
+		<ul>
+			<li><strong>Loading.</strong> <span class="file">cursor.c</span> copies the bundle out of the ramfs into its own pages after <code>ramfs_init()</code> and after every <code>ramfs_replace()</code> (the old pack is freed), then tells <span class="file">mouse.c</span> to re-fetch its image.</li>
+			<li><strong>Selection.</strong> On every <code>SYS_WM_POLL</code> the window server resolves the shape: the WM's override (<code>SYS_WM_SET_CURSOR</code>: resize arrows on the grip and while resizing, the move cross during a title-bar drag, a hand over launchers and the status area), else the cursor of the window holding the pointer capture, else the content cursor (<code>SYS_WIN_SET_CURSOR</code>) of the window under the pointer, else the arrow.</li>
+			<li><strong>Clients.</strong> ngui resets the cursor to the arrow for each redrawn frame, a hovered text field asks for the I-beam, <code>ngui_cursor_rect()</code>/<code>ngui_set_cursor()</code> serve apps, and <code>ngui_end_ex()</code> sends it when it changed.  The terminal uses the I-beam; the browser maps the inherited CSS <code>cursor</code> property and, for <code>auto</code>, a hand over links, an I-beam over text fields and the progress arrow while a page loads.  The gallery's Cursors section shows every shape.</li>
+			<li><strong>Drawing.</strong> <code>cur_x</code>/<code>cur_y</code> stay the hotspot; the image's top-left is the hotspot minus the image's hotspot and may be off-screen.  The software cursor saves up to 32&times;32 pixels under it and blends the premultiplied pixels over them.  Intel Ironlake and Radeon copy the ARGB image into their 64&times;64 planes (Intel uses CURPOS sign bits for negative positions, Radeon <code>HORZ_VERT_OFF</code> plus a shifted <code>CUR_OFFSET</code>); Cirrus reduces it to its two colours and clamps the position at 0.  Animated frames advance from <code>mouse_poll_update()</code>.</li>
+		</ul>
+	</section>
+
 	<section id="gpu">
 		<h2>GPU quirks</h2>
 		<ul>
@@ -492,6 +545,9 @@
 			<li><code>user/lib/img/img*.c</code> — image codecs</li>
 			<li><code>kernel/ati.c</code>, <code>kernel/nvidia.c</code>, <code>kernel/intel.c</code>, <code>kernel/nv50.c</code></li>
 			<li><code>kernel/backlight.c</code>, <code>kernel/backlight.h</code> — Cherryview/VLV panel PWM</li>
+			<li><code>kernel/cursor.c</code>, <code>kernel/cursor.h</code>, <code>kernel/mouse.c</code>, <code>kernel/cursor_shape.h</code> — cursor bundle loader, drawing and the built-in fallback arrow; <code>kernel/cirrus.c</code>, <code>kernel/radeon.c</code> — hardware cursors</li>
+			<li><code>include/icon_abi.h</code>, <code>tools/mkicons.c</code>, <code>assets/icons/adwaita/</code> — UI icon list, the NBICO1 bundle and the Adwaita symbolic SVGs</li>
+			<li><code>include/cursor_abi.h</code>, <code>tools/mkcursors.c</code>, <code>tools/xcursor_trim.py</code>, <code>tools/cursor_test.c</code>, <code>assets/cursors/adwaita/</code> — cursor shapes, the NBCUR1 bundle and the Adwaita source images</li>
 		</ul>
 	</section>
 </main>

+ 1 - 1
docs/index.html

@@ -212,7 +212,7 @@
 			</a>
 			<a class="card" href="graphics.html">
 				<h3>Graphics &amp; UI</h3>
-				<p>VBE framebuffer, shadow buffer, damage rectangles, compositor, canvas ABI, ngui, the fixed-point TrueType text engine and image codecs.</p>
+				<p>VBE framebuffer, shadow buffer, damage rectangles, compositor, canvas ABI, ngui, the Adwaita UI icons and mouse cursors, the fixed-point TrueType text engine and image codecs.</p>
 				<span class="card-tag">graphics.html</span>
 			</a>
 			<a class="card" href="network.html">

Разница между файлами не показана из-за своего большого размера
+ 1 - 1
docs/network.html


Разница между файлами не показана из-за своего большого размера
+ 5 - 2
docs/userland.html


+ 22 - 16
host/fs.c

@@ -67,11 +67,29 @@ int host_guest_to_host(const char *guest, char *out, size_t cap)
 	return 0;
 }
 
+/* Expose <repo>/<dir> (or <cwd>/<dir>) as <root>/ramfs/<dir>, the way the
+ * pack mounts the UI fonts and icons on the target. */
+static void link_repo_dir(const char *root, const char *dir)
+{
+	char src[HOST_PATH_MAX];
+	char link[HOST_PATH_MAX];
+	struct stat st;
+
+	snprintf(src, sizeof(src), "%s/%s", host_repo, dir);
+	if (access(src, R_OK) != 0) {
+		char cwd[HOST_PATH_MAX];
+
+		if (getcwd(cwd, sizeof(cwd)))
+			snprintf(src, sizeof(src), "%s/%s", cwd, dir);
+	}
+	snprintf(link, sizeof(link), "%s/ramfs/%s", root, dir);
+	if (access(src, R_OK) == 0 && lstat(link, &st) != 0)
+		symlink(src, link);
+}
+
 int host_fs_init(const char *root)
 {
 	char path[HOST_PATH_MAX];
-	char fonts[HOST_PATH_MAX];
-	char link[HOST_PATH_MAX];
 
 	if (mkdir_p(root) != 0)
 		return -1;
@@ -85,20 +103,8 @@ int host_fs_init(const char *root)
 	if (mkdir_p(path) != 0)
 		return -1;
 
-	snprintf(fonts, sizeof(fonts), "%s/fonts", host_repo);
-	if (access(fonts, R_OK) != 0) {
-		char cwd[HOST_PATH_MAX];
-
-		if (getcwd(cwd, sizeof(cwd)))
-			snprintf(fonts, sizeof(fonts), "%s/fonts", cwd);
-	}
-	snprintf(link, sizeof(link), "%s/ramfs/fonts", root);
-	if (access(fonts, R_OK) == 0) {
-		struct stat st;
-
-		if (lstat(link, &st) != 0)
-			symlink(fonts, link);
-	}
+	link_repo_dir(root, "fonts");
+	link_repo_dir(root, "icons");   /* built by `make icons/adwaita16.icn` */
 	return 0;
 }
 

+ 1 - 0
host/host.h

@@ -9,6 +9,7 @@ struct host_options {
 	const char *shot;
 	unsigned int wait_ms;
 	int headless;
+	const char *keys;       /* --keys: scripted headless keystrokes */
 	int width;
 	int height;
 };

+ 8 - 2
host/main.c

@@ -1,7 +1,11 @@
 /* browser-host: run the NebOS browser as a Linux/Wayland program.
  *
  * Usage: browser-host [--size WxH] [--root DIR] [--headless]
- *                     [--wait MS] [--shot FILE] [URL|FILE]
+ *                     [--wait MS] [--shot FILE] [--keys KEYS] [URL|FILE]
+ *
+ * --keys types into a headless window, one key every 100 ms from 300 ms
+ * after the first frame: plain characters, plus {enter} {esc} {tab} {bs}
+ * {del} {up} {down} {left} {right} {ctrl-l} and {wait} (a 1 s pause).
  */
 #include <signal.h>
 #include <stdio.h>
@@ -17,7 +21,7 @@ static void usage(void)
 	fprintf(stderr,
 		"usage: browser-host [--size WxH] [--root DIR] [--headless]\n"
 		"                    [--wait MS] [--shot|--screenshot FILE]\n"
-		"                    [URL|FILE]\n");
+		"                    [--keys KEYS] [URL|FILE]\n");
 }
 
 static int parse_size(const char *s, int *w, int *h)
@@ -65,6 +69,8 @@ int main(int argc, char **argv)
 			host_opts.shot = argv[++i];
 		} else if (!strcmp(a, "--screenshot") && i + 1 < argc) {
 			host_opts.shot = argv[++i];
+		} else if (!strcmp(a, "--keys") && i + 1 < argc) {
+			host_opts.keys = argv[++i];
 		} else if (!strcmp(a, "--help") || !strcmp(a, "-h")) {
 			usage();
 			return 0;

+ 4 - 0
host/syscall.c

@@ -212,6 +212,10 @@ int u_syscall3(int num, int a1, int a2, int a3)
 		return host_window_scroll((struct win_scroll *)argp(a1));
 	case SYS_WIN_RESIZE_SELF:
 		return -1;
+	case SYS_WIN_SET_CURSOR:
+		return host_window_set_cursor((int)a1);
+	case SYS_WM_SET_CURSOR:
+		return -1;
 	case SYS_SCREEN_INFO: {
 		struct sys_screen *out = (struct sys_screen *)argp(a1);
 

+ 9 - 0
host/window.c

@@ -119,6 +119,15 @@ int host_window_screen(unsigned int *w, unsigned int *h)
 	return headless ? host_headless_screen(w, h) : host_sdl_screen(w, h);
 }
 
+int host_window_set_cursor(int shape)
+{
+	if (!open)
+		return -1;
+	if (!headless)
+		host_sdl_set_cursor(shape);
+	return 0;
+}
+
 int host_window_key_wait(unsigned int timeout_ms)
 {
 	if (!open) {

+ 3 - 0
host/window.h

@@ -19,6 +19,8 @@ int host_window_key(void);
 int host_window_screen(unsigned int *w, unsigned int *h);
 int host_window_key_wait(unsigned int timeout_ms);
 const char *host_window_backend(void);
+/* SYS_WIN_SET_CURSOR: enum cursor_shape (cursor_abi.h). */
+int host_window_set_cursor(int shape);
 
 /* Active backend (window.c selects by host_opts.headless). */
 void host_sdl_close(void);
@@ -35,6 +37,7 @@ int host_sdl_key(void);
 int host_sdl_screen(unsigned int *w, unsigned int *h);
 int host_sdl_key_wait(unsigned int timeout_ms);
 const char *host_sdl_backend(void);
+void host_sdl_set_cursor(int shape);
 
 void host_headless_close(void);
 int host_headless_open(unsigned int w, unsigned int h, const char *title);

+ 42 - 1
host/window_headless.c

@@ -128,9 +128,50 @@ int host_headless_scroll(struct win_scroll *out)
 	return 0;
 }
 
+/* --keys: the next scripted key once it is due, else 0. */
+static const char *key_pos;
+static unsigned long long key_due;
+
 int host_headless_key(void)
 {
-	return 0;
+	static const struct {
+		const char *name;
+		int code;
+	} names[] = {
+		{"enter", '\n'}, {"esc", 0x1B}, {"tab", 0x09}, {"bs", 0x08},
+		{"del", 0x108}, {"left", 0x100}, {"right", 0x101},
+		{"up", 0x102}, {"down", 0x103}, {"ctrl-l", 0x0C}, {"wait", -1},
+	};
+	unsigned long long now = now_ms();
+	int code;
+
+	if (!host_opts.keys || !presented)
+		return 0;
+	if (!key_pos) {
+		key_pos = host_opts.keys;
+		key_due = first_present + 300;
+	}
+	if (!*key_pos || now < key_due)
+		return 0;
+	code = (unsigned char)*key_pos++;
+	if (code == '{') {
+		const char *end = strchr(key_pos, '}');
+		unsigned int i;
+
+		code = 0;
+		for (i = 0; end && i < sizeof(names) / sizeof(names[0]); i++)
+			if (strlen(names[i].name) == (size_t)(end - key_pos) &&
+			    !strncmp(key_pos, names[i].name,
+				     (size_t)(end - key_pos)))
+				code = names[i].code;
+		key_pos = end ? end + 1 : key_pos + strlen(key_pos);
+		if (code < 0) {
+			key_due = now + 1000;
+			return 0;
+		}
+	}
+	key_due = now + 100;
+	return code;
 }
 
 int host_headless_screen(unsigned int *w, unsigned int *h)

+ 47 - 0
host/window_sdl3.c

@@ -10,6 +10,7 @@
 #include <unistd.h>
 
 #include "window.h"
+#include "cursor_abi.h"
 
 #define KEYQ_MAX 256
 #define EVQ_MAX  64
@@ -431,6 +432,52 @@ int host_sdl_key(void)
 	return pop_key();
 }
 
+/* NebOS cursor shapes on the desktop's own cursor theme.  SDL has no
+ * help/zoom/copy/... system cursors: those fall back to the arrow. */
+void host_sdl_set_cursor(int shape)
+{
+	static SDL_Cursor *cache[CURSOR_COUNT];
+	static int current = -1;
+	SDL_SystemCursor sc = SDL_SYSTEM_CURSOR_DEFAULT;
+
+	if (shape < 0 || shape >= CURSOR_COUNT || shape == current)
+		return;
+	switch (shape) {
+	case CURSOR_POINTER:     sc = SDL_SYSTEM_CURSOR_POINTER; break;
+	case CURSOR_TEXT:
+	case CURSOR_VERTICAL_TEXT: sc = SDL_SYSTEM_CURSOR_TEXT; break;
+	case CURSOR_WAIT:        sc = SDL_SYSTEM_CURSOR_WAIT; break;
+	case CURSOR_PROGRESS:    sc = SDL_SYSTEM_CURSOR_PROGRESS; break;
+	case CURSOR_CROSSHAIR:
+	case CURSOR_CELL:        sc = SDL_SYSTEM_CURSOR_CROSSHAIR; break;
+	case CURSOR_MOVE:
+	case CURSOR_ALL_SCROLL:
+	case CURSOR_ALL_RESIZE:  sc = SDL_SYSTEM_CURSOR_MOVE; break;
+	case CURSOR_NOT_ALLOWED:
+	case CURSOR_NO_DROP:     sc = SDL_SYSTEM_CURSOR_NOT_ALLOWED; break;
+	case CURSOR_N_RESIZE:    sc = SDL_SYSTEM_CURSOR_N_RESIZE; break;
+	case CURSOR_E_RESIZE:    sc = SDL_SYSTEM_CURSOR_E_RESIZE; break;
+	case CURSOR_S_RESIZE:    sc = SDL_SYSTEM_CURSOR_S_RESIZE; break;
+	case CURSOR_W_RESIZE:    sc = SDL_SYSTEM_CURSOR_W_RESIZE; break;
+	case CURSOR_NE_RESIZE:   sc = SDL_SYSTEM_CURSOR_NE_RESIZE; break;
+	case CURSOR_NW_RESIZE:   sc = SDL_SYSTEM_CURSOR_NW_RESIZE; break;
+	case CURSOR_SE_RESIZE:   sc = SDL_SYSTEM_CURSOR_SE_RESIZE; break;
+	case CURSOR_SW_RESIZE:   sc = SDL_SYSTEM_CURSOR_SW_RESIZE; break;
+	case CURSOR_EW_RESIZE:
+	case CURSOR_COL_RESIZE:  sc = SDL_SYSTEM_CURSOR_EW_RESIZE; break;
+	case CURSOR_NS_RESIZE:
+	case CURSOR_ROW_RESIZE:  sc = SDL_SYSTEM_CURSOR_NS_RESIZE; break;
+	case CURSOR_NESW_RESIZE: sc = SDL_SYSTEM_CURSOR_NESW_RESIZE; break;
+	case CURSOR_NWSE_RESIZE: sc = SDL_SYSTEM_CURSOR_NWSE_RESIZE; break;
+	default: break;
+	}
+	if (!cache[shape])
+		cache[shape] = SDL_CreateSystemCursor(sc);
+	if (cache[shape])
+		SDL_SetCursor(cache[shape]);
+	current = shape;
+}
+
 int host_sdl_screen(unsigned int *w, unsigned int *h)
 {
 	SDL_Rect r;

+ 87 - 0
include/cursor_abi.h

@@ -0,0 +1,87 @@
+/* Mouse-cursor shapes and the NBCUR1 cursor bundle.
+ *
+ * Shared by the kernel (kernel/cursor.c loads the bundle and mouse.c draws
+ * it), ring 3 (SYS_WIN_SET_CURSOR / SYS_WM_SET_CURSOR take a shape id, the
+ * browser maps CSS `cursor` keywords) and the host tool tools/mkcursors.c,
+ * which builds /ramfs/cursors/adwaita24.cur from assets/cursors/adwaita/.
+ *
+ * The shape names are the CSS / freedesktop cursor names.  CURSOR_LIST is an
+ * X-macro: X(ENUM_SUFFIX, "css-name", "theme-file"); the order is the shape
+ * id and the order of the shapes in the bundle, so append only. */
+#ifndef CURSOR_ABI_H
+#define CURSOR_ABI_H
+
+#define CURSOR_LIST(X) \
+	X(DEFAULT,       "default",       "default")       \
+	X(POINTER,       "pointer",       "pointer")       \
+	X(TEXT,          "text",          "text")          \
+	X(VERTICAL_TEXT, "vertical-text", "vertical-text") \
+	X(WAIT,          "wait",          "wait")          \
+	X(PROGRESS,      "progress",      "progress")      \
+	X(HELP,          "help",          "help")          \
+	X(CONTEXT_MENU,  "context-menu",  "context-menu")  \
+	X(CELL,          "cell",          "cell")          \
+	X(CROSSHAIR,     "crosshair",     "crosshair")     \
+	X(MOVE,          "move",          "all-resize")    \
+	X(ALL_SCROLL,    "all-scroll",    "all-scroll")    \
+	X(GRAB,          "grab",          "grab")          \
+	X(GRABBING,      "grabbing",      "grabbing")      \
+	X(NOT_ALLOWED,   "not-allowed",   "not-allowed")   \
+	X(NO_DROP,       "no-drop",       "no-drop")       \
+	X(COPY,          "copy",          "copy")          \
+	X(ALIAS,         "alias",         "alias")         \
+	X(ZOOM_IN,       "zoom-in",       "zoom-in")       \
+	X(ZOOM_OUT,      "zoom-out",      "zoom-out")      \
+	X(COL_RESIZE,    "col-resize",    "col-resize")    \
+	X(ROW_RESIZE,    "row-resize",    "row-resize")    \
+	X(N_RESIZE,      "n-resize",      "n-resize")      \
+	X(E_RESIZE,      "e-resize",      "e-resize")      \
+	X(S_RESIZE,      "s-resize",      "s-resize")      \
+	X(W_RESIZE,      "w-resize",      "w-resize")      \
+	X(NE_RESIZE,     "ne-resize",     "ne-resize")     \
+	X(NW_RESIZE,     "nw-resize",     "nw-resize")     \
+	X(SE_RESIZE,     "se-resize",     "se-resize")     \
+	X(SW_RESIZE,     "sw-resize",     "sw-resize")     \
+	X(EW_RESIZE,     "ew-resize",     "ew-resize")     \
+	X(NS_RESIZE,     "ns-resize",     "ns-resize")     \
+	X(NESW_RESIZE,   "nesw-resize",   "nesw-resize")   \
+	X(NWSE_RESIZE,   "nwse-resize",   "nwse-resize")   \
+	X(ALL_RESIZE,    "all-resize",    "all-resize")
+
+#define CURSOR_ENUM_(e, css, file) CURSOR_##e,
+enum cursor_shape {
+	CURSOR_LIST(CURSOR_ENUM_)
+	CURSOR_COUNT
+};
+#undef CURSOR_ENUM_
+
+/* SYS_WM_SET_CURSOR: no WM override, use the window's own cursor. */
+#define CURSOR_NO_OVERRIDE (-1)
+
+/* Largest cursor image the kernel accepts (the software cursor's save
+ * buffer and the hardware planes are sized for it). */
+#define CURSOR_MAX_DIM 32
+
+/* ---- NBCUR1 bundle ------------------------------------------------------
+ * [struct cursor_file_hdr][count x struct cursor_file_shape][pixels]
+ * Pixels are premultiplied ARGB8888 (0xAARRGGBB little-endian dwords, as in
+ * Xcursor), w*h per frame, frames stored back to back starting at
+ * `offset` (bytes from the start of the file).  Every field is
+ * little-endian. */
+#define CURSOR_FILE_MAGIC "NBCUR1\0\0"
+
+struct cursor_file_hdr {
+	char magic[8];
+	unsigned int count;      /* number of shapes (CURSOR_COUNT when built) */
+	unsigned int nominal;    /* theme size in px, e.g. 24 */
+};
+
+struct cursor_file_shape {
+	unsigned short w, h;
+	unsigned short hot_x, hot_y;
+	unsigned short frames;   /* >= 1; > 1 animates */
+	unsigned short delay_ms; /* per frame when animated */
+	unsigned int offset;     /* first frame's pixels */
+};
+
+#endif

+ 42 - 0
include/icon_abi.h

@@ -0,0 +1,42 @@
+/* UI icons and the NBICO1 icon bundle.
+ *
+ * Shared by ngui (user/lib/ngui: enum ngui_icon, ngui_icon()) and the host
+ * tool tools/mkicons.c, which rasterizes the Adwaita symbolic SVGs in
+ * assets/icons/adwaita/ into /ramfs/icons/adwaita16.icn.
+ *
+ * ICON_LIST is an X-macro: X(ENUM_SUFFIX, "short name", "theme file").  The
+ * order is the icon id and the order of the masks in the bundle, so append
+ * only. */
+#ifndef ICON_ABI_H
+#define ICON_ABI_H
+
+#define ICON_LIST(X) \
+	X(FOLDER,        "folder",  "folder-symbolic")         \
+	X(FILE,          "file",    "text-x-generic-symbolic") \
+	X(DISK,          "disk",    "drive-harddisk-symbolic") \
+	X(UP,            "up",      "go-up-symbolic")          \
+	X(HOME,          "home",    "go-home-symbolic")        \
+	X(REFRESH,       "refresh", "view-refresh-symbolic")   \
+	X(PLUS,          "plus",    "list-add-symbolic")       \
+	X(CHEVRON_LEFT,  "back",    "go-previous-symbolic")    \
+	X(CHEVRON_RIGHT, "forward", "go-next-symbolic")        \
+	X(STOP,          "stop",    "process-stop-symbolic")   \
+	X(CLOSE,         "close",   "window-close-symbolic")   \
+	X(SEARCH,        "search",  "system-search-symbolic")  \
+	X(MENU,          "menu",    "open-menu-symbolic")
+
+/* ---- NBICO1 bundle ------------------------------------------------------
+ * [struct icon_file_hdr][count x size*size coverage bytes]
+ * One 8-bit coverage mask per icon (0 = transparent, 255 = opaque), rows
+ * top to bottom, in ICON_LIST order.  Symbolic icons are single-colour, so
+ * the drawing side tints the mask with the theme colour.  Little-endian. */
+#define ICON_FILE_MAGIC "NBICO1\0\0"
+
+struct icon_file_hdr {
+	char magic[8];
+	unsigned short count;    /* number of masks */
+	unsigned short size;     /* mask edge in px, e.g. 16 */
+	unsigned int reserved;
+};
+
+#endif

+ 4 - 0
include/syscall.h

@@ -117,6 +117,10 @@
 #define SYS_WIN_SCROLL     109 /* (struct win_scroll *out) -> 1 delta, 0 none, -1 */
 #define SYS_WIN_RESIZE_SELF 115 /* (int w, int h) -> 0/-1; resize the caller's canvas */
 #define SYS_SCREEN_INFO   116 /* (struct sys_screen *out) -> 0/-1 */
+#define SYS_WIN_SET_CURSOR 117 /* (int shape) -> 0/-1; the caller's content
+				  cursor (enum cursor_shape, cursor_abi.h) */
+#define SYS_WM_SET_CURSOR 118 /* (int shape | CURSOR_NO_OVERRIDE) -> 0/-1;
+				  WM only: cursor for its chrome/drags */
 #define SYS_BACKLIGHT     113 /* (int op, int value) -> percent / -1.
 				  op 0 = get, 1 = set (5..100), 2 = step */
 #define SYS_BACKLIGHT_GET  0

+ 44 - 28
kernel/cirrus.c

@@ -2,7 +2,7 @@
    Reference: QEMU hw/display/cirrus_vga.c (register offsets, ROP codes). */
 
 #include "cirrus.h"
-#include "cursor_shape.h"
+#include "cursor.h"
 #include "pci.h"
 #include "vga.h"
 
@@ -195,37 +195,47 @@ void cirrus_fill(unsigned int x, unsigned int y,
 		;
 }
 
-void cirrus_cursor_setup(void)
+/* 32x32 two-plane cursor: AND plane (offset 0..127), XOR plane (128..255),
+ * 4 bytes per row, the image in the top-left of the box:
+ *   AND=0 XOR=0 -> transparent
+ *   AND=0 XOR=1 -> color0 (white)
+ *   AND=1 XOR=1 -> color1 (black)
+ * The hidden DAC entries 0 and 15 are programmed white and black.  The ARGB
+ * image is reduced to that: alpha >= 50% is opaque, and the (premultiplied)
+ * luminance picks white or black. */
+void cirrus_cursor_load(const struct cursor_image *img)
 {
-	unsigned char bitmap[256];
-	unsigned int r, i;
 	unsigned int vram = vga_fb_vram_kb() * 1024;
 	unsigned char *dst;
+	unsigned int r, c, i;
 
-	/* 32x32 two-plane cursor: AND plane (offset 0..127), XOR plane (128..255),
-	   4 bytes per row.  The shared arrow is placed in the top-left of the
-	   box (the cursor position is the top-left of the 32x32 box):
-	     AND=0 XOR=0 -> transparent
-	     AND=0 XOR=1 -> color0 (white fill)
-	     AND=1 XOR=1 -> color1 (black outline)
-	   The hidden DAC entries 0 and 15 are programmed white and black. */
+	dst = (unsigned char *)(vga_fb_lfb_addr() + vram - 16384);
 	for (i = 0; i < 256; i++)
-		bitmap[i] = 0;
-	for (r = 0; r < CURSOR_SHAPE_HEIGHT; r++) {
-		unsigned short fill = cursor_shape_fill[r];
-		unsigned short outl = cursor_shape_outline[r];
-		unsigned short xor = fill | outl;
-		bitmap[r * 4 + 0] = (unsigned char)((outl >> 8) & 0xFF);        /* AND x=0..7  */
-		bitmap[r * 4 + 1] = (unsigned char)(outl & 0xFF);               /* AND x=8..15 */
-		bitmap[128 + r * 4 + 0] = (unsigned char)((xor >> 8) & 0xFF);   /* XOR x=0..7  */
-		bitmap[128 + r * 4 + 1] = (unsigned char)(xor & 0xFF);          /* XOR x=8..15 */
-	}
+		dst[i] = 0;
+	if (!img || !img->px)
+		return;
+	for (r = 0; r < img->h && r < 32; r++)
+		for (c = 0; c < img->w && c < 32; c++) {
+			unsigned int p = img->px[r * img->w + c];
+			unsigned int a = p >> 24;
+			unsigned int lum = (((p >> 16) & 0xFF) * 3 +
+					    ((p >> 8) & 0xFF) * 6 +
+					    (p & 0xFF)) / 10;
+			unsigned char bit = (unsigned char)(0x80u >> (c & 7));
+
+			if (a < 128)
+				continue;
+			dst[128 + r * 4 + c / 8] |= bit;    /* XOR: opaque */
+			if (lum * 2 < a)
+				dst[r * 4 + c / 8] |= bit;  /* AND: black */
+		}
+}
 
-	/* Upload to the top of VRAM (SR[0x13] = 0 selects the first 256-byte block). */
+void cirrus_cursor_setup(const struct cursor_image *img)
+{
+	/* SR[0x13] = 0 selects the first 256-byte block at the top of VRAM. */
 	sr_write(SR_CURSOR_PAT, 0);
-	dst = (unsigned char *)(vga_fb_lfb_addr() + vram - 16384);
-	for (i = 0; i < 256; i++)
-		dst[i] = bitmap[i];
+	cirrus_cursor_load(img);
 
 	/* Cursor colors via the hidden DAC palette: entry 0 = white, 15 = black. */
 	sr_write(SR_CURSOR_ATTR, CURSOR_HIDDENPEL);
@@ -236,11 +246,17 @@ void cirrus_cursor_setup(void)
 	sr_write(SR_CURSOR_ATTR, CURSOR_SHOW);
 }
 
-void cirrus_cursor_move(unsigned int x, unsigned int y)
+/* (x,y) is the image's top-left.  The Cirrus position cannot go negative,
+ * so near the top/left edge the image is clamped (the hotspot is then off
+ * by up to its offset). */
+void cirrus_cursor_move(int x, int y)
 {
+	unsigned int ux = x < 0 ? 0u : (unsigned int)x;
+	unsigned int uy = y < 0 ? 0u : (unsigned int)y;
+
 	/* Position is 11 bits; low 3 bits select the index alias, high 8 are data. */
-	sr_write(SR_CURSOR_X | ((x & 0x7) << 5), (unsigned char)(x >> 3));
-	sr_write(SR_CURSOR_Y | ((y & 0x7) << 5), (unsigned char)(y >> 3));
+	sr_write(SR_CURSOR_X | ((ux & 0x7) << 5), (unsigned char)(ux >> 3));
+	sr_write(SR_CURSOR_Y | ((uy & 0x7) << 5), (unsigned char)(uy >> 3));
 }
 
 void cirrus_cursor_show(int show)

+ 5 - 2
kernel/cirrus.h

@@ -16,8 +16,11 @@ void cirrus_fill(unsigned int x, unsigned int y,
 		 unsigned int r, unsigned int g, unsigned int b);
 
 /* Hardware cursor (32x32). */
-void cirrus_cursor_setup(void);
-void cirrus_cursor_move(unsigned int x, unsigned int y);
+struct cursor_image;
+void cirrus_cursor_setup(const struct cursor_image *img);
+void cirrus_cursor_load(const struct cursor_image *img);
+/* (x,y) is the image's top-left; negative values are clamped to 0. */
+void cirrus_cursor_move(int x, int y);
 void cirrus_cursor_show(int show);
 
 #endif

+ 145 - 0
kernel/cursor.c

@@ -0,0 +1,145 @@
+/* Mouse-cursor images.
+ *
+ * The cursor set is the Adwaita theme (assets/cursors/adwaita/), converted
+ * by tools/mkcursors.c into one NBCUR1 bundle that the rootfs pack carries
+ * as cursors/adwaita24.cur.  The kernel cannot keep a pointer into the pack
+ * (ramfs_replace() frees the old one), so cursor_load() copies the bundle
+ * into its own pages.  Until then -- and on a pack without the bundle --
+ * the built-in 16x16 arrow from cursor_shape.h is used. */
+
+#include "cursor.h"
+#include "cursor_shape.h"
+#include "mm.h"
+#include "mouse.h"
+#include "ramfs.h"
+#include "serial.h"
+
+#define CURSOR_PACK_PATH "cursors/adwaita24.cur"
+
+static const unsigned char *bundle;
+static unsigned int bundle_pages;
+static unsigned int fallback_px[CURSOR_SHAPE_WIDTH * CURSOR_SHAPE_HEIGHT];
+static int fallback_ready;
+
+static void fallback_build(void)
+{
+	unsigned int r, c;
+
+	for (r = 0; r < CURSOR_SHAPE_HEIGHT; r++)
+		for (c = 0; c < CURSOR_SHAPE_WIDTH; c++) {
+			unsigned short bit = (unsigned short)(0x8000u >> c);
+			unsigned int v = 0;
+
+			if (cursor_shape_fill[r] & bit)
+				v = 0xFFFFFFFFu;
+			else if (cursor_shape_outline[r] & bit)
+				v = 0xFF000000u;
+			fallback_px[r * CURSOR_SHAPE_WIDTH + c] = v;
+		}
+	fallback_ready = 1;
+}
+
+/* Bounds-check the whole bundle once, so cursor_get() can trust it. */
+static int bundle_valid(const unsigned char *p, unsigned int size)
+{
+	const struct cursor_file_hdr *h = (const struct cursor_file_hdr *)p;
+	const struct cursor_file_shape *s;
+	const char *magic = CURSOR_FILE_MAGIC;
+	unsigned int i;
+
+	if (size < sizeof(*h))
+		return 0;
+	for (i = 0; i < 8; i++)
+		if (h->magic[i] != magic[i])
+			return 0;
+	if (h->count == 0 || h->count > 256 ||
+	    sizeof(*h) + h->count * sizeof(*s) > size)
+		return 0;
+	s = (const struct cursor_file_shape *)(p + sizeof(*h));
+	for (i = 0; i < h->count; i++) {
+		unsigned int bytes;
+
+		if (!s[i].w || !s[i].h || s[i].w > CURSOR_MAX_DIM ||
+		    s[i].h > CURSOR_MAX_DIM || s[i].hot_x >= s[i].w ||
+		    s[i].hot_y >= s[i].h || !s[i].frames ||
+		    s[i].frames > 256 || (s[i].offset & 3))
+			return 0;
+		bytes = (unsigned int)s[i].w * s[i].h * 4u * s[i].frames;
+		if (s[i].offset > size || bytes > size - s[i].offset)
+			return 0;
+	}
+	return 1;
+}
+
+void cursor_load(void)
+{
+	unsigned int size = 0, pages, i;
+	const unsigned char *src =
+		(const unsigned char *)ramfs_lookup(CURSOR_PACK_PATH, &size);
+	unsigned char *copy;
+	const unsigned char *old = bundle;
+	unsigned int old_pages = bundle_pages;
+
+	if (!src || !bundle_valid(src, size)) {
+		serial_puts(SERIAL_COM1, "cursor: no valid " CURSOR_PACK_PATH
+			    ", keeping the current cursors\n");
+		return;
+	}
+	pages = (size + 0xFFFu) >> 12;
+	copy = (unsigned char *)mm_alloc_pages(pages);
+	if (!copy) {
+		serial_puts(SERIAL_COM1, "cursor: out of memory\n");
+		return;
+	}
+	for (i = 0; i < size; i++)
+		copy[i] = src[i];
+	bundle = copy;
+	bundle_pages = pages;
+	/* The mouse may still point into the old copy: let it switch before
+	 * the pages go back to the allocator. */
+	mouse_cursor_reload();
+	for (i = 0; i < old_pages; i++)
+		mm_free_page((unsigned int)old + i * 0x1000u);
+	serial_puts(SERIAL_COM1, "cursor: loaded ");
+	serial_putdec(SERIAL_COM1,
+		((const struct cursor_file_hdr *)bundle)->count);
+	serial_puts(SERIAL_COM1, " shapes\n");
+}
+
+int cursor_bundle_loaded(void)
+{
+	return bundle != 0;
+}
+
+void cursor_get(int shape, unsigned int frame, struct cursor_image *out)
+{
+	if (bundle) {
+		const struct cursor_file_hdr *h =
+			(const struct cursor_file_hdr *)bundle;
+		const struct cursor_file_shape *s =
+			(const struct cursor_file_shape *)(bundle + sizeof(*h));
+
+		if (shape < 0 || (unsigned int)shape >= h->count)
+			shape = CURSOR_DEFAULT;
+		s += shape;
+		frame %= s->frames;
+		out->w = s->w;
+		out->h = s->h;
+		out->hot_x = s->hot_x;
+		out->hot_y = s->hot_y;
+		out->frames = s->frames;
+		out->delay_ms = s->delay_ms ? s->delay_ms : 100;
+		out->px = (const unsigned int *)(bundle + s->offset) +
+			  frame * s->w * s->h;
+		return;
+	}
+	if (!fallback_ready)
+		fallback_build();
+	out->px = fallback_px;
+	out->w = CURSOR_SHAPE_WIDTH;
+	out->h = CURSOR_SHAPE_HEIGHT;
+	out->hot_x = 0;
+	out->hot_y = 0;
+	out->frames = 1;
+	out->delay_ms = 0;
+}

+ 29 - 0
kernel/cursor.h

@@ -0,0 +1,29 @@
+/* Mouse-cursor images: the NBCUR1 bundle from /ramfs/cursors (see
+ * include/cursor_abi.h), with a built-in 16x16 arrow as the fallback. */
+#ifndef CURSOR_H
+#define CURSOR_H
+
+#include "cursor_abi.h"
+
+struct cursor_image {
+	const unsigned int *px;     /* premultiplied ARGB8888, w*h */
+	unsigned int w, h;
+	unsigned int hot_x, hot_y;
+	unsigned int frames;        /* >= 1 */
+	unsigned int delay_ms;      /* per frame when frames > 1 */
+};
+
+/* (Re)load the bundle from the ramfs into page-allocated memory.  Called
+ * after ramfs_init() and from ramfs_replace(); the mouse is told to pick up
+ * the new images.  A missing or invalid bundle keeps the previous one (or
+ * the built-in arrow). */
+void cursor_load(void);
+
+/* Fill *out with frame `frame` (mod the frame count) of `shape`.  An
+ * unknown shape, or one the bundle lacks, gives the default arrow. */
+void cursor_get(int shape, unsigned int frame, struct cursor_image *out);
+
+/* 1 when the bundle is loaded (0 = built-in arrow only). */
+int cursor_bundle_loaded(void);
+
+#endif

+ 48 - 27
kernel/intel.c

@@ -9,7 +9,9 @@
  *
  * Register semantics follow the Linux i915 Ironlake path:
  *  - CURACNTR/CURABASE/CURAPOS are per-pipe (A at 0x70080, B at 0x700c0).
- *  - 64x64 ARGB8888 cursor, MSB A:R:G:B, hotspot at (0,0).
+ *  - 64x64 ARGB8888 cursor, MSB A:R:G:B, hotspot at (0,0); the mouse code
+ *    positions the image's top-left, so CURPOS takes negative values in
+ *    sign-magnitude form (bit 15 = X sign, bit 31 = Y sign).
  *  - CURCNTR bit 31 enables, mode 0x27 is 64x64 ARGB, bits 29:28 hold the
  *    pipe select.  CURBASE is written after CURPOS to arm the update.
  *  - The GTT PTE is the physical page, its bits 35:32 in PTE bits 7:4, the
@@ -17,7 +19,7 @@
  */
 
 #include "intel.h"
-#include "cursor_shape.h"
+#include "cursor.h"
 #include "mm.h"
 #include "paging.h"
 #include "pci.h"
@@ -176,28 +178,19 @@ static int intel_alloc_cursor(void)
 	return 0;
 }
 
-static void intel_fill_cursor(unsigned int phys)
+/* Copy a cursor image (premultiplied ARGB, as the plane expects) into the
+ * top-left of the 64x64 plane; NULL clears it. */
+static void intel_fill_cursor(unsigned int phys, const struct cursor_image *ci)
 {
 	unsigned int *img = (unsigned int *)phys;
 	unsigned int i, r, c;
 
 	for (i = 0; i < CUR_SIZE * CUR_SIZE; i++)
 		img[i] = 0;
-
-	for (r = 0; r < CURSOR_SHAPE_HEIGHT; r++) {
-		unsigned short fill = cursor_shape_fill[r];
-		unsigned short outline = cursor_shape_outline[r];
-
-		for (c = 0; c < CURSOR_SHAPE_WIDTH; c++) {
-			unsigned short bit = (unsigned short)(0x8000u >> c);
-			unsigned int *px = &img[r * CUR_SIZE + c];
-
-			if (fill & bit)
-				*px = 0xFFFFFFFFu;      /* opaque white */
-			else if (outline & bit)
-				*px = 0xFF000000u;      /* opaque black */
-		}
-	}
+	if (ci && ci->px)
+		for (r = 0; r < ci->h && r < CUR_SIZE; r++)
+			for (c = 0; c < ci->w && c < CUR_SIZE; c++)
+				img[r * CUR_SIZE + c] = ci->px[r * ci->w + c];
 
 	/* The GTT mapping is uncached, so push the WB image out to DRAM. */
 	__asm__ volatile ("wbinvd" ::: "memory");
@@ -325,7 +318,7 @@ void intel_init(unsigned int bus, unsigned int dev, unsigned int device_id)
 		return;
 	}
 	intel_cursor_gtt = slot * 4096;
-	intel_fill_cursor(intel_cursor_phys);
+	intel_fill_cursor(intel_cursor_phys, 0);
 	if (intel_map_cursor(slot) != 0) {
 		serial_puts(SERIAL_COM1, "intel: GTT write did not stick\n");
 		return;
@@ -349,19 +342,33 @@ int intel_available(void)
 	return intel_probe_ok;
 }
 
-static void intel_cursor_program(unsigned int pipe, unsigned int x,
-				 unsigned int y)
+static unsigned int intel_cursor_pos(int x, int y)
+{
+	unsigned int pos = 0;
+
+	if (x < 0) {
+		pos |= 0x8000u;
+		x = -x;
+	}
+	if (y < 0) {
+		pos |= 0x80000000u;
+		y = -y;
+	}
+	return pos | ((unsigned int)x & 0x7FFFu) |
+	       (((unsigned int)y & 0x7FFFu) << 16);
+}
+
+static void intel_cursor_program(unsigned int pipe, int x, int y)
 {
 	unsigned int base = CURACNTR + (pipe ? CUR_PIPE_B : 0);
-	unsigned int pos = (x & 0x7FFFu) | ((y & 0x7FFFu) << 16);
 
 	mmio_write(base, cursor_ctrl(pipe));
-	mmio_write(base + 8, pos);                  /* CURAPOS */
-	mmio_write(base + 4, intel_cursor_gtt);     /* CURABASE */
+	mmio_write(base + 8, intel_cursor_pos(x, y)); /* CURAPOS */
+	mmio_write(base + 4, intel_cursor_gtt);       /* CURABASE */
 	(void)mmio_read(base + 4);
 }
 
-int intel_cursor_setup(unsigned int x, unsigned int y)
+int intel_cursor_setup(int x, int y)
 {
 	if (!intel_probe_ok || !intel_cursor_gtt)
 		return -1;
@@ -378,13 +385,27 @@ int intel_cursor_setup(unsigned int x, unsigned int y)
 	return 0;
 }
 
-void intel_cursor_move(unsigned int x, unsigned int y)
+void intel_cursor_load(const struct cursor_image *img)
+{
+	if (!intel_probe_ok || !intel_cursor_phys)
+		return;
+	intel_fill_cursor(intel_cursor_phys, img);
+	/* Re-arm CURBASE so the plane fetches the new image. */
+	if (intel_cursor_ok) {
+		if (intel_pipe_mask & 1)
+			mmio_write(CURABASE, intel_cursor_gtt);
+		if (intel_pipe_mask & 2)
+			mmio_write(CURABASE + CUR_PIPE_B, intel_cursor_gtt);
+	}
+}
+
+void intel_cursor_move(int x, int y)
 {
 	unsigned int pos;
 
 	if (!intel_cursor_ok)
 		return;
-	pos = (x & 0x7FFFu) | ((y & 0x7FFFu) << 16);
+	pos = intel_cursor_pos(x, y);
 	if (intel_pipe_mask & 1) {
 		mmio_write(CURAPOS, pos);
 		mmio_write(CURABASE, intel_cursor_gtt);

+ 11 - 5
kernel/intel.h

@@ -9,11 +9,17 @@ void intel_init(unsigned int bus, unsigned int dev, unsigned int device_id);
 /* 1 when the hardware cursor is fully set up and usable. */
 int intel_available(void);
 
-/* Enable the cursor at (x,y); returns 0 on success and -1 when the cursor
- * image/GTT was not prepared (the caller then keeps the software cursor). */
-int intel_cursor_setup(unsigned int x, unsigned int y);
+struct cursor_image;
 
-/* Move the hardware cursor. */
-void intel_cursor_move(unsigned int x, unsigned int y);
+/* Enable the cursor with its image's top-left at (x,y) (may be negative);
+ * returns 0 on success and -1 when the cursor image/GTT was not prepared
+ * (the caller then keeps the software cursor). */
+int intel_cursor_setup(int x, int y);
+
+/* Copy a cursor image into the 64x64 plane (top-left aligned). */
+void intel_cursor_load(const struct cursor_image *img);
+
+/* Move the hardware cursor: (x,y) is the image's top-left. */
+void intel_cursor_move(int x, int y);
 
 #endif

+ 2 - 0
kernel/kernel.c

@@ -22,6 +22,7 @@
 #include "power.h"
 #include "process.h"
 #include "ramfs.h"
+#include "cursor.h"
 #include "rndis.h"
 #include "rtl8821au.h"
 #include "sched.h"
@@ -547,6 +548,7 @@ void kernel_main(void)
 				serial_puts(SERIAL_COM1, " files, ");
 				serial_putdec(SERIAL_COM1, ramfs_pack_size());
 				serial_puts(SERIAL_COM1, " bytes\n");
+				cursor_load();
 				if (!gz) {
 					/* ramfs has its own copy now; keep that
 					 * as the self-update image. */

+ 219 - 50
kernel/mouse.c

@@ -1,7 +1,7 @@
 #include "mouse.h"
 #include "bootinfo.h"
 #include "cirrus.h"
-#include "cursor_shape.h"
+#include "cursor.h"
 #include "intel.h"
 #include "radeon.h"
 #include "timer.h"
@@ -20,9 +20,6 @@
 #define MOUSE_ACK     0xFA
 #define MOUSE_RESEND  0xFE
 
-#define MOUSE_CUR_W CURSOR_SHAPE_WIDTH
-#define MOUSE_CUR_H CURSOR_SHAPE_HEIGHT
-
 /* One PS/2 wheel notch in scroll pixels; touchpads emit pixels directly. */
 #define MOUSE_WHEEL_PX 48
 #define MOUSE_SCROLL_MAX 100000
@@ -42,7 +39,11 @@ static int mouse_aux_irq_ok;        /* controller config accepted AUX IRQ */
 static unsigned int fbw, fbh;
 static unsigned int cur_x, cur_y;
 static unsigned int saved_x, saved_y, saved_w, saved_h;
-static unsigned char cur_saved[MOUSE_CUR_W * MOUSE_CUR_H * 4];
+static int saved_ox, saved_oy;       /* unclipped image origin of the save */
+static unsigned char cur_saved[CURSOR_MAX_DIM * CURSOR_MAX_DIM * 4];
+static struct cursor_image cur_img;  /* the frame on screen */
+static int cur_shape = CURSOR_DEFAULT;
+static unsigned int cur_frame, cur_frame_ms;
 static unsigned char pkt[4];
 static unsigned int pkt_idx;
 
@@ -167,21 +168,34 @@ static int mouse_send_cmd_ack(unsigned char cmd)
 	return r;
 }
 
-enum {
-	MOUSE_PIX_TRANSPARENT = 0,
-	MOUSE_PIX_OUTLINE,
-	MOUSE_PIX_FILL
-};
-
-static int mouse_pixel_at(int r, int c)
-{
-	if (r < 0 || c < 0 || r >= (int)MOUSE_CUR_H || c >= (int)MOUSE_CUR_W)
-		return MOUSE_PIX_TRANSPARENT;
-	if (cursor_shape_fill[(unsigned int)r] & (0x8000u >> c))
-		return MOUSE_PIX_FILL;
-	if (cursor_shape_outline[(unsigned int)r] & (0x8000u >> c))
-		return MOUSE_PIX_OUTLINE;
-	return MOUSE_PIX_TRANSPARENT;
+/* ---- Cursor image ---------------------------------------------------------
+ *
+ * cur_x/cur_y are the hotspot.  The image (kernel/cursor.c: an Adwaita
+ * shape or the built-in arrow) is drawn with its top-left at
+ * (cur_x - hot_x, cur_y - hot_y), so near the top/left edge part of it is
+ * off-screen.  The software cursor blends the premultiplied ARGB over the
+ * saved background; the hardware backends take the same image. */
+
+static void cursor_calc_rect(unsigned int *rx, unsigned int *ry,
+			     unsigned int *rw, unsigned int *rh)
+{
+	int ox = (int)cur_x - (int)cur_img.hot_x;
+	int oy = (int)cur_y - (int)cur_img.hot_y;
+	int x0 = ox, y0 = oy;
+	int x1 = ox + (int)cur_img.w, y1 = oy + (int)cur_img.h;
+
+	if (x0 < 0) x0 = 0;
+	if (y0 < 0) y0 = 0;
+	if (x1 > (int)fbw) x1 = (int)fbw;
+	if (y1 > (int)fbh) y1 = (int)fbh;
+	if (x1 <= x0 || y1 <= y0) {
+		*rx = *ry = *rw = *rh = 0;
+		return;
+	}
+	*rx = (unsigned int)x0;
+	*ry = (unsigned int)y0;
+	*rw = (unsigned int)(x1 - x0);
+	*rh = (unsigned int)(y1 - y0);
 }
 
 static void cursor_save_under(void)
@@ -192,10 +206,9 @@ static void cursor_save_under(void)
 		saved_w = saved_h = 0;
 		return;
 	}
-	saved_x = cur_x;
-	saved_y = cur_y;
-	saved_w = (cur_x + MOUSE_CUR_W <= fbw) ? MOUSE_CUR_W : fbw - cur_x;
-	saved_h = (cur_y + MOUSE_CUR_H <= fbh) ? MOUSE_CUR_H : fbh - cur_y;
+	cursor_calc_rect(&saved_x, &saved_y, &saved_w, &saved_h);
+	saved_ox = (int)cur_x - (int)cur_img.hot_x;
+	saved_oy = (int)cur_y - (int)cur_img.hot_y;
 	if (saved_w && saved_h)
 		vga_fb_read_rect(saved_x, saved_y, saved_w, saved_h, cur_saved);
 }
@@ -215,22 +228,172 @@ static void cursor_present(void)
 		vga_fb_present_rect(saved_x, saved_y, saved_w, saved_h);
 }
 
-static void mouse_draw_cursor(unsigned int x0, unsigned int y0)
+/* Blend the current image over the background saved by cursor_save_under()
+ * (which must have run for the same position and image). */
+static void mouse_draw_cursor(void)
 {
+	unsigned int pb = vga_fb_bpp() == 16 ? 2u : vga_fb_bpp() == 24 ? 3u : 4u;
 	unsigned int r, c;
 
-	/* White arrow body with a black outline around it. */
-	for (r = 0; r < MOUSE_CUR_H; r++) {
-		for (c = 0; c < MOUSE_CUR_W; c++) {
-			int px = mouse_pixel_at((int)r, (int)c);
-			if (px == MOUSE_PIX_FILL)
-				vga_fb_put_pixel(x0 + c, y0 + r, 255, 255, 255);
-			else if (px == MOUSE_PIX_OUTLINE)
-				vga_fb_put_pixel(x0 + c, y0 + r, 0, 0, 0);
+	if (!cur_img.px)
+		return;
+	for (r = 0; r < saved_h; r++) {
+		unsigned int iy = saved_y + r - (unsigned int)saved_oy;
+		const unsigned int *src = cur_img.px + iy * cur_img.w +
+			(saved_x - (unsigned int)saved_ox);
+
+		for (c = 0; c < saved_w; c++) {
+			unsigned int s = src[c];
+			unsigned int a = s >> 24;
+			unsigned int sr = (s >> 16) & 0xFF, sg = (s >> 8) & 0xFF;
+			unsigned int sb = s & 0xFF;
+
+			if (a == 0)
+				continue;
+			if (a != 255) {
+				const unsigned char *d =
+					cur_saved + (r * saved_w + c) * pb;
+				unsigned int dr, dg, db, inv = 255 - a;
+
+				if (pb == 2) {
+					unsigned int v = d[0] | (d[1] << 8);
+
+					dr = ((v >> 11) & 0x1F) * 255 / 31;
+					dg = ((v >> 5) & 0x3F) * 255 / 63;
+					db = (v & 0x1F) * 255 / 31;
+				} else {
+					db = d[0];
+					dg = d[1];
+					dr = d[2];
+				}
+				/* Premultiplied source over the background. */
+				sr += (dr * inv + 127) / 255;
+				sg += (dg * inv + 127) / 255;
+				sb += (db * inv + 127) / 255;
+				if (sr > 255) sr = 255;
+				if (sg > 255) sg = 255;
+				if (sb > 255) sb = 255;
+			}
+			vga_fb_put_pixel(saved_x + c, saved_y + r, sr, sg, sb);
 		}
 	}
 }
 
+/* Hardware cursor position: the image's top-left, may be negative. */
+static void cursor_hw_move(void)
+{
+	int ox = (int)cur_x - (int)cur_img.hot_x;
+	int oy = (int)cur_y - (int)cur_img.hot_y;
+
+	if (mouse_hw_cursor == 3)
+		intel_cursor_move(ox, oy);
+	else if (mouse_hw_cursor == 2)
+		radeon_cursor_move(ox, oy);
+	else if (mouse_hw_cursor == 1)
+		cirrus_cursor_move(ox, oy);
+}
+
+static void cursor_hw_load(void)
+{
+	if (mouse_hw_cursor == 3)
+		intel_cursor_load(&cur_img);
+	else if (mouse_hw_cursor == 2)
+		radeon_cursor_load(&cur_img);
+	else if (mouse_hw_cursor == 1)
+		cirrus_cursor_load(&cur_img);
+}
+
+/* Switch to `img`: re-upload the hardware image, or erase and redraw the
+ * software cursor (presenting the union of the old and new rectangles in
+ * one go, so a shape change does not blink). */
+static void cursor_set_image(const struct cursor_image *img)
+{
+	unsigned int ox, oy, ow, oh;
+
+	if (!mouse_cursor_flag) {
+		cur_img = *img;
+		return;
+	}
+	if (mouse_hw_cursor) {
+		unsigned int flags = mouse_irq_save();
+
+		cur_img = *img;
+		cursor_hw_load();
+		cursor_hw_move();
+		mouse_irq_restore(flags);
+		return;
+	}
+	if (!mouse_auto_draw) {
+		/* A WM frame owns the shadow; PRESENT redraws the cursor. */
+		cur_img = *img;
+		return;
+	}
+	cursor_restore_under();
+	ox = saved_x; oy = saved_y; ow = saved_w; oh = saved_h;
+	cur_img = *img;
+	cursor_save_under();
+	mouse_draw_cursor();
+	if (ow && oh && saved_w && saved_h) {
+		unsigned int x0 = ox < saved_x ? ox : saved_x;
+		unsigned int y0 = oy < saved_y ? oy : saved_y;
+		unsigned int x1 = ox + ow > saved_x + saved_w ?
+				  ox + ow : saved_x + saved_w;
+		unsigned int y1 = oy + oh > saved_y + saved_h ?
+				  oy + oh : saved_y + saved_h;
+
+		vga_fb_present_rect(x0, y0, x1 - x0, y1 - y0);
+	} else {
+		if (ow && oh)
+			vga_fb_present_rect(ox, oy, ow, oh);
+		cursor_present();
+	}
+}
+
+static void cursor_select(int shape, unsigned int frame)
+{
+	struct cursor_image img;
+
+	cursor_get(shape, frame, &img);
+	cursor_set_image(&img);
+}
+
+void mouse_set_shape(int shape)
+{
+	if (shape < 0 || shape >= CURSOR_COUNT)
+		shape = CURSOR_DEFAULT;
+	if (shape == cur_shape)
+		return;
+	cur_shape = shape;
+	cur_frame = 0;
+	cur_frame_ms = get_ticks_ms();
+	cursor_select(cur_shape, 0);
+}
+
+int mouse_get_shape(void)
+{
+	return cur_shape;
+}
+
+void mouse_cursor_reload(void)
+{
+	cursor_select(cur_shape, cur_frame);
+}
+
+/* Advance an animated cursor (wait/progress) from the poll loop. */
+static void mouse_cursor_tick(void)
+{
+	unsigned int now;
+
+	if (!mouse_cursor_flag || cur_img.frames <= 1)
+		return;
+	now = get_ticks_ms();
+	if (now - cur_frame_ms < cur_img.delay_ms)
+		return;
+	cur_frame_ms = now;
+	cur_frame = (cur_frame + 1) % cur_img.frames;
+	cursor_select(cur_shape, cur_frame);
+}
+
 static void mouse_clamp_ptr(long *nx, long *ny)
 {
 	long maxx = (long)fbw - 1;
@@ -257,8 +420,10 @@ static void mouse_cursor_setup(void)
 		return;
 	fbw = vga_fb_width();
 	fbh = vga_fb_height();
-	if (fbw < MOUSE_CUR_W || fbh < MOUSE_CUR_H)
+	if (fbw < CURSOR_MAX_DIM || fbh < CURSOR_MAX_DIM)
 		return;
+	cursor_get(cur_shape, cur_frame, &cur_img);
+	cur_frame_ms = get_ticks_ms();
 
 	/* Cirrus hardware cursor: the card overlays it; no save/restore.
 	 * UEFI GOP modes are not programmed through the legacy VGA sequencer,
@@ -267,8 +432,8 @@ static void mouse_cursor_setup(void)
 		mouse_hw_cursor = 1;
 		cur_x = 100;
 		cur_y = 100;
-		cirrus_cursor_setup();
-		cirrus_cursor_move(cur_x, cur_y);
+		cirrus_cursor_setup(&cur_img);
+		cursor_hw_move();
 		mouse_cursor_flag = 1;
 		return;
 	}
@@ -278,8 +443,8 @@ static void mouse_cursor_setup(void)
 		mouse_hw_cursor = 2;
 		cur_x = 100;
 		cur_y = 100;
-		radeon_cursor_setup();
-		radeon_cursor_move(cur_x, cur_y);
+		radeon_cursor_setup(&cur_img);
+		cursor_hw_move();
 		mouse_cursor_flag = 1;
 		return;
 	}
@@ -294,7 +459,9 @@ static void mouse_cursor_setup(void)
 		mouse_clamp_ptr(&nx, &ny);
 		cur_x = (unsigned int)nx;
 		cur_y = (unsigned int)ny;
-		if (intel_cursor_setup(cur_x, cur_y) == 0) {
+		intel_cursor_load(&cur_img);
+		if (intel_cursor_setup((int)cur_x - (int)cur_img.hot_x,
+				       (int)cur_y - (int)cur_img.hot_y) == 0) {
 			mouse_hw_cursor = 3;
 			mouse_cursor_flag = 1;
 			return;
@@ -316,7 +483,7 @@ static void mouse_cursor_setup(void)
 		cur_y = (unsigned int)ny;
 	}
 	cursor_save_under();
-	mouse_draw_cursor(cur_x, cur_y);
+	mouse_draw_cursor();
 	cursor_present();
 	mouse_cursor_flag = 1;
 }
@@ -410,12 +577,7 @@ static void mouse_move(int dx, int dy)
 
 		cur_x = (unsigned int)nx;
 		cur_y = (unsigned int)ny;
-		if (mouse_hw_cursor == 3)
-			intel_cursor_move(cur_x, cur_y);
-		else if (mouse_hw_cursor == 2)
-			radeon_cursor_move(cur_x, cur_y);
-		else
-			cirrus_cursor_move(cur_x, cur_y);
+		cursor_hw_move();
 		mouse_irq_restore(flags);
 	} else if (!mouse_auto_draw) {
 		/* A WM frame is between BEGIN and PRESENT: it erased the
@@ -428,7 +590,7 @@ static void mouse_move(int dx, int dy)
 		cur_x = (unsigned int)nx;
 		cur_y = (unsigned int)ny;
 		cursor_save_under();
-		mouse_draw_cursor(cur_x, cur_y);
+		mouse_draw_cursor();
 		cursor_present();          /* draw the new position in VRAM */
 	}
 }
@@ -508,6 +670,7 @@ void mouse_poll_update(void)
 	if ((mouse_present_flag || usbhid_mouse_attached() ||
 	     touchpad_present()) && !mouse_cursor_flag)
 		mouse_cursor_setup();
+	mouse_cursor_tick();
 
 	/* USB HID mouse: reports arrive through the armed interrupt
 	   endpoint; the backend also handles hotplug/detach. */
@@ -632,10 +795,16 @@ void mouse_redraw_cursor(void)
 	 * rectangle is still the old position and has been restored to the
 	 * background there.  Erase it in VRAM before drawing the new one, so
 	 * a moving cursor does not leave a trail behind a slow frame. */
-	if ((saved_x != cur_x || saved_y != cur_y) && saved_w && saved_h)
-		vga_fb_present_rect(saved_x, saved_y, saved_w, saved_h);
+	if (saved_w && saved_h) {
+		unsigned int nx, ny, nw, nh;
+
+		cursor_calc_rect(&nx, &ny, &nw, &nh);
+		if (nx != saved_x || ny != saved_y || nw != saved_w ||
+		    nh != saved_h)
+			vga_fb_present_rect(saved_x, saved_y, saved_w, saved_h);
+	}
 	cursor_save_under();
-	mouse_draw_cursor(cur_x, cur_y);
+	mouse_draw_cursor();
 	cursor_present();
 }
 

+ 8 - 0
kernel/mouse.h

@@ -39,4 +39,12 @@ void mouse_redraw_cursor(void);
  * WM erases/redraws the cursor itself at BEGIN/PRESENT. */
 void mouse_set_auto_draw(int on);
 
+/* Cursor shape (enum cursor_shape, include/cursor_abi.h).  The WM server
+ * resolves the shape under the pointer on every poll; an unknown value
+ * selects CURSOR_DEFAULT.  Animated shapes advance from mouse_poll_update. */
+void mouse_set_shape(int shape);
+int mouse_get_shape(void);
+/* Re-fetch the current image after kernel/cursor.c (re)loaded the bundle. */
+void mouse_cursor_reload(void);
+
 #endif

+ 49 - 35
kernel/radeon.c

@@ -22,7 +22,7 @@
  */
 
 #include "radeon.h"
-#include "cursor_shape.h"
+#include "cursor.h"
 #include "pci.h"
 #include "paging.h"
 #include "serial.h"
@@ -120,11 +120,30 @@ int radeon_available(void)
 	return radeon_present;
 }
 
-void radeon_cursor_setup(void)
+#define RADEON_CUR_LOCK              (1u << 31)
+
+/* Copy a cursor image into the top-left of the 64x64 ARGB plane (the image
+ * is premultiplied ARGB8888, which the R200 cursor blends as-is). */
+void radeon_cursor_load(const struct cursor_image *img)
+{
+	unsigned int *dst;
+	unsigned int i, r, c;
+
+	if (!radeon_present)
+		return;
+	dst = (unsigned int *)(vga_fb_lfb_addr() + RADEON_CUR_VRAM_OFS);
+	for (i = 0; i < RADEON_CUR_SIZE * RADEON_CUR_SIZE; i++)
+		dst[i] = 0;
+	if (!img || !img->px)
+		return;
+	for (r = 0; r < img->h && r < RADEON_CUR_SIZE; r++)
+		for (c = 0; c < img->w && c < RADEON_CUR_SIZE; c++)
+			dst[r * RADEON_CUR_SIZE + c] = img->px[r * img->w + c];
+}
+
+void radeon_cursor_setup(const struct cursor_image *img)
 {
-	unsigned char *dst;
-	unsigned int vram;
-	unsigned int i, r, c, g;
+	unsigned int vram, g;
 
 	if (!radeon_present)
 		return;
@@ -135,35 +154,9 @@ void radeon_cursor_setup(void)
 		return;
 	}
 
-	dst = (unsigned char *)(vga_fb_lfb_addr() + RADEON_CUR_VRAM_OFS);
-
-	/* Transparent background (alpha 0), then the opaque white fill and
-	   black outline of the shared arrow. */
-	for (i = 0; i < RADEON_CUR_BYTES; i++)
-		dst[i] = 0;
-	for (r = 0; r < CURSOR_SHAPE_HEIGHT; r++) {
-		unsigned short fill = cursor_shape_fill[r];
-		unsigned short outl = cursor_shape_outline[r];
-		for (c = 0; c < CURSOR_SHAPE_WIDTH; c++) {
-			unsigned short bit = (unsigned short)(0x8000u >> c);
-			unsigned int off = (r * RADEON_CUR_SIZE + c) * 4;
-			if (fill & bit) {
-				dst[off + 0] = 0xFF;  /* B */
-				dst[off + 1] = 0xFF;  /* G */
-				dst[off + 2] = 0xFF;  /* R */
-			} else if (outl & bit) {
-				dst[off + 0] = 0x00;  /* B */
-				dst[off + 1] = 0x00;  /* G */
-				dst[off + 2] = 0x00;  /* R */
-			} else {
-				continue;
-			}
-			dst[off + 3] = 0xFF;          /* A */
-		}
-	}
-
+	radeon_cursor_load(img);
 	mmio_write(RADEON_CUR_OFFSET, RADEON_CUR_VRAM_OFS);
-	mmio_write(RADEON_CUR_HORZ_VERT_OFF, 0);    /* hotspot at (0,0) */
+	mmio_write(RADEON_CUR_HORZ_VERT_OFF, 0);
 	mmio_write(RADEON_CUR_HORZ_VERT_POSN, 0);   /* position set on move */
 
 	/* Enable the 24 bpp (ARGB8888) hardware cursor. */
@@ -173,11 +166,32 @@ void radeon_cursor_setup(void)
 	mmio_mm_write(RADEON_CRTC_GEN_CNTL, g);
 }
 
-void radeon_cursor_move(unsigned int x, unsigned int y)
+/* (x,y) is the image's top-left.  The position register cannot go
+ * negative: like Linux's legacy radeon_cursor_move_locked(), clamp it at 0
+ * and skip the hidden part through HORZ_VERT_OFF (x) and a CUR_OFFSET that
+ * starts yorigin rows (256 bytes each) into the image. */
+void radeon_cursor_move(int x, int y)
 {
+	unsigned int xo = 0, yo = 0;
+
 	if (!radeon_present)
 		return;
-	mmio_write(RADEON_CUR_HORZ_VERT_POSN, (x << 16) | y);
+	if (x < 0) {
+		xo = (unsigned int)-x;
+		if (xo > RADEON_CUR_SIZE - 1)
+			xo = RADEON_CUR_SIZE - 1;
+		x = 0;
+	}
+	if (y < 0) {
+		yo = (unsigned int)-y;
+		if (yo > RADEON_CUR_SIZE - 1)
+			yo = RADEON_CUR_SIZE - 1;
+		y = 0;
+	}
+	mmio_write(RADEON_CUR_HORZ_VERT_OFF, RADEON_CUR_LOCK | (xo << 16) | yo);
+	mmio_write(RADEON_CUR_HORZ_VERT_POSN, RADEON_CUR_LOCK |
+		   ((unsigned int)x << 16) | (unsigned int)y);
+	mmio_write(RADEON_CUR_OFFSET, RADEON_CUR_VRAM_OFS + yo * 256);
 }
 
 void radeon_cursor_show(int show)

+ 6 - 3
kernel/radeon.h

@@ -6,9 +6,12 @@
 void radeon_init(unsigned int bus, unsigned int dev, unsigned int device_id);
 int  radeon_available(void);
 
-/* Hardware cursor (64x64, 2 bpp). */
-void radeon_cursor_setup(void);
-void radeon_cursor_move(unsigned int x, unsigned int y);
+/* Hardware cursor (64x64 ARGB8888). */
+struct cursor_image;
+void radeon_cursor_setup(const struct cursor_image *img);
+void radeon_cursor_load(const struct cursor_image *img);
+/* (x,y) is the image's top-left and may be negative. */
+void radeon_cursor_move(int x, int y);
 void radeon_cursor_show(int show);
 
 #endif

+ 3 - 0
kernel/ramfs.c

@@ -9,6 +9,7 @@
 #include "inflate.h"
 #include "mm.h"
 #include "serial.h"
+#include "cursor.h"
 
 #define RAMFS_MAX_DECOMPRESSED (8u * 1024u * 1024u)
 
@@ -279,6 +280,8 @@ int ramfs_replace(const void *pack, unsigned int size)
 	for (i = 0; i < old_pages; i++)
 		mm_free_page((unsigned int)old_base + i * 0x1000);
 	(void)old_size;
+	/* The new pack may carry different cursors. */
+	cursor_load();
 	return 0;
 }
 

+ 10 - 0
kernel/sys_wm.c

@@ -285,3 +285,13 @@ int sys_win_resize_self(unsigned int w, unsigned int h)
 {
 	return wm_server_win_resize_self(w, h);
 }
+
+int sys_win_set_cursor(int shape)
+{
+	return wm_server_win_set_cursor(shape);
+}
+
+int sys_wm_set_cursor(int shape)
+{
+	return wm_server_set_cursor(shape);
+}

+ 2 - 0
kernel/sys_wm.h

@@ -29,6 +29,8 @@ int sys_win_scroll(struct win_scroll *out);
 int sys_wm_resize(unsigned int index, const struct wm_size *in);
 int sys_win_key_wait(unsigned int timeout_ms);
 int sys_win_resize_self(unsigned int w, unsigned int h);
+int sys_win_set_cursor(int shape);
+int sys_wm_set_cursor(int shape);
 
 /* Set once the first application window (the boot terminal) has presented
  * a frame; kernel_main waits for it before the USB bring-up. */

+ 4 - 0
kernel/syscall.c

@@ -350,6 +350,10 @@ static int syscall_dispatch_locked(int num, int a1, int a2, int a3)
 		return sys_win_key_wait((unsigned int)a1);
 	case SYS_WIN_RESIZE_SELF:
 		return sys_win_resize_self((unsigned int)a1, (unsigned int)a2);
+	case SYS_WIN_SET_CURSOR:
+		return sys_win_set_cursor((int)a1);
+	case SYS_WM_SET_CURSOR:
+		return sys_wm_set_cursor((int)a1);
 	case SYS_SCREEN_INFO: {
 		struct sys_screen *out = (struct sys_screen *)a1;
 

+ 61 - 0
kernel/wm.c

@@ -2,6 +2,7 @@
  * mapping/presentation and input routing.  There is no in-kernel WM. */
 
 #include "wm.h"
+#include "cursor_abi.h"
 #include "backlight.h"
 #include "bootcon.h"
 #include "io.h"
@@ -33,6 +34,9 @@ static unsigned int wm_next_content_gen(void)
  * called by the ring-3 WM every loop, so it is the cheapest place to turn the
  * sampled mouse state into press/release edges. */
 static unsigned int wm_ptr_buttons;
+/* SYS_WM_SET_CURSOR: the WM's shape for its own chrome (resize grip,
+ * title-bar drag, launchers), or CURSOR_NO_OVERRIDE. */
+static int wm_cursor_override = CURSOR_NO_OVERRIDE;
 static int wm_ptr_capture = -1;
 
 /* Ring-3 WM lifecycle.  The kernel only admits the process it spawned; a
@@ -272,6 +276,7 @@ int wm_server_win_create(const struct win_create *in, struct win_info *out)
 	w->pending_pages = 0;
 	w->resize_pending = 0;
 	w->scroll_x = w->scroll_y = 0;
+	w->cursor = CURSOR_DEFAULT;
 	w->canvas_dmg_x = w->canvas_dmg_y = 0;
 	w->canvas_dmg_w = w->canvas_dmg_h = 0;
 	w->pw = cw + pad * 2;
@@ -592,6 +597,59 @@ int wm_server_win_resize_self(unsigned int cw, unsigned int ch)
 	return wm_resize_window((unsigned int)idx, cw, ch);
 }
 
+int wm_server_win_set_cursor(int shape)
+{
+	int idx = wm_window_for_pid(current_proc()->pid);
+
+	if (idx < 0 || shape < 0 || shape >= CURSOR_COUNT)
+		return -1;
+	windows[idx].cursor = shape;
+	return 0;
+}
+
+int wm_server_set_cursor(int shape)
+{
+	if (!wm_server_is_wm())
+		return -1;
+	if (shape != CURSOR_NO_OVERRIDE && (shape < 0 || shape >= CURSOR_COUNT))
+		return -1;
+	wm_cursor_override = shape;
+	return 0;
+}
+
+/* The shape for the pointer at (mx,my): the WM's override, else the
+ * content cursor of the window that holds the pointer capture (a drag that
+ * started in the content keeps its cursor), else of the window whose
+ * content is under the pointer (not on a normal window's resize grip),
+ * else the default arrow (title bars, the desktop, the top bar). */
+static int wm_cursor_at(unsigned int mx, unsigned int my)
+{
+	int idx;
+	struct window *w;
+	int cx, cy;
+
+	if (wm_cursor_override != CURSOR_NO_OVERRIDE)
+		return wm_cursor_override;
+	if (wm_ptr_capture >= 0 && windows[wm_ptr_capture].used &&
+	    windows[wm_ptr_capture].canvas_window)
+		return windows[wm_ptr_capture].cursor;
+	idx = wm_window_at((int)mx, (int)my);
+	if (idx < 0)
+		return CURSOR_DEFAULT;
+	w = &windows[idx];
+	if (!w->canvas_window)
+		return CURSOR_DEFAULT;
+	cx = (int)mx - win_content_x(w);
+	cy = (int)my - win_content_y(w);
+	if (cx < 0 || cy < 0 || cx >= (int)w->canvas.w ||
+	    cy >= (int)w->canvas.h)
+		return CURSOR_DEFAULT;
+	if (!w->popover && (int)mx >= w->x + (int)w->pw - 16 &&
+	    (int)my >= w->y + (int)w->ph - 16)
+		return CURSOR_DEFAULT;
+	return w->cursor;
+}
+
 int wm_server_key_poll(void)
 {
 	int idx = wm_window_for_pid(current_proc()->pid);
@@ -982,6 +1040,7 @@ int wm_server_poll(struct wm_status *out)
 	out->mouse.buttons = mouse_buttons_state();
 	wm_route_pointer(out->mouse.x, out->mouse.y, out->mouse.buttons);
 	wm_route_scroll(out->mouse.x, out->mouse.y);
+	mouse_set_shape(wm_cursor_at(out->mouse.x, out->mouse.y));
 	out->full_redraw = wm_full_redraw ? 1 : 0;
 	out->boot_ready = wm_boot_ready ? 1 : 0;
 	out->kexec_busy = kexec_busy ? 1 : 0;
@@ -1074,6 +1133,8 @@ static void wm_server_wm_died(void)
 	wm_cr3 = 0;
 	wm_ptr_buttons = 0;
 	wm_ptr_capture = -1;
+	wm_cursor_override = CURSOR_NO_OVERRIDE;
+	mouse_set_shape(CURSOR_DEFAULT);
 	for (i = 0; i < MAX_WINDOWS; i++) {
 		windows[i].mapped_kind = WM_KIND_NONE;
 		windows[i].mapped_gen = 0;

+ 5 - 0
kernel/wm.h

@@ -39,6 +39,9 @@ struct window {
 	unsigned int ptr_head, ptr_tail;
 	/* Scroll accumulated while the pointer is over the content. */
 	int scroll_x, scroll_y;
+	/* Cursor shape over the content (enum cursor_shape), set by the app
+	 * with SYS_WIN_SET_CURSOR. */
+	int cursor;
 	/* Content-relative damage union since the WM last ACKed a present. */
 	unsigned int canvas_dmg_x, canvas_dmg_y;
 	unsigned int canvas_dmg_w, canvas_dmg_h;
@@ -87,6 +90,8 @@ int  wm_server_win_pointer(struct win_pointer *out);
 int  wm_server_win_event(struct win_event *out);
 int  wm_server_win_scroll(struct win_scroll *out);
 int  wm_server_win_resize_self(unsigned int cw, unsigned int ch);
+int  wm_server_win_set_cursor(int shape);
+int  wm_server_set_cursor(int shape);
 void wm_server_boot_ready(void);
 struct window *wm_focused_window(void);
 int  wm_is_focused(const struct window *w);

+ 125 - 16
kernel/xhci.c

@@ -104,6 +104,7 @@ static unsigned int portsc_neutral(unsigned int ps)
 #define TRB_DISABLE_SLOT	10
 #define TRB_ADDR_DEV		11
 #define TRB_CONFIG_EP		12
+#define TRB_EVAL_CTX		13
 #define TRB_TRANSFER		32
 #define TRB_COMPLETION		33
 
@@ -148,6 +149,7 @@ struct xhci_slot {
 	unsigned int ep0;	/* EP0 transfer ring page */
 	unsigned int ep0_enq;
 	unsigned int ep0_cycle;
+	unsigned int ep0_mps;	/* max packet size programmed into EP0 */
 	unsigned int ep_mask;	/* configured endpoint flags */
 };
 
@@ -194,6 +196,8 @@ static unsigned int ctx_size;
 static unsigned int port_mask;
 static unsigned int hcc_params;
 static unsigned int pci_bus, pci_dev, pci_func;
+static unsigned int pci_id;
+static unsigned int hci_version;
 static int found;
 static int last_port = -1;
 
@@ -265,6 +269,14 @@ static void dbg_hex(const char *s, unsigned int v) { (void)s; (void)v; }
 static void dbg_dec(const char *s, unsigned int v) { (void)s; (void)v; }
 #endif
 
+/* Always-on one-line diagnostics (COM1, mirrored to netmon).  Only used on
+ * the init line and on failures, so a working machine stays quiet. */
+static void xlog_hex(const char *s, unsigned int v)
+{
+	serial_puts(SERIAL_COM1, s);
+	serial_puthex(SERIAL_COM1, v);
+}
+
 static void delay_ms(unsigned int ms)
 {
 	usb_delay_ms(ms);    /* sleeps inside a sleepable scan */
@@ -601,6 +613,47 @@ static unsigned int ep0_mps_for_speed(unsigned int speed)
 	return 64;		/* full speed (guess) and high speed */
 }
 
+/* EP0 max packet size for Address Device.  Low, high and SuperSpeed have
+ * one legal value, so the USB core's 8-byte first-read guess is replaced
+ * by it; only full speed (8/16/32/64) takes the caller's value and is
+ * corrected later by ep0_set_mps(). */
+static unsigned int ep0_mps_initial(unsigned int speed, unsigned int mps)
+{
+	if (!mps || speed != 1)
+		return ep0_mps_for_speed(speed);
+	return mps;
+}
+
+/* Evaluate Context: tell the xHC the device's real bMaxPacketSize0 once
+ * the first descriptor read has returned it.  Without this the VL805 on
+ * the 970A-DS3P kept the 8-byte EP0 that SET_ADDRESS created, and the
+ * 18-byte device descriptor read of a high-speed stick failed with
+ * Babble Detected (the device answers in one 18-byte packet). */
+static int ep0_set_mps(struct xhci_slot *s, unsigned int mps)
+{
+	unsigned int flags;
+	int rc;
+
+	spin_lock_irqsave(&xhci_lock, &flags);
+	zero_page(input_ctx, 4096);
+	*(unsigned int *)input_ctx = 0;
+	*(unsigned int *)(input_ctx + 4) = EP0_FLAG;
+	fill_ep0_ctx(mps, s->ep0, s->ep0_enq, s->ep0_cycle);
+	spin_unlock_irqrestore(&xhci_lock, flags);
+
+	rc = xhci_cmd(input_ctx, 0,
+		      TRB_TYPE(TRB_EVAL_CTX) | (s->slot_id << 24), 0);
+	if (rc == 0) {
+		s->ep0_mps = mps;
+	} else {
+		xlog_hex("xhci: evaluate context failed slot ", s->slot_id);
+		xlog_hex(" mps ", mps);
+		xlog_hex(" cc ", cmd_status);
+		serial_putc(SERIAL_COM1, '\n');
+	}
+	return rc;
+}
+
 static int xhci_config_ep(struct xhci_slot *s, unsigned int ep_index,
 			  unsigned int type, unsigned int mps,
 			  unsigned int interval, unsigned int ring)
@@ -680,8 +733,8 @@ static struct xhci_slot *new_slot_common(unsigned int target_addr,
 	s->ep_mask = 0;
 	s->dev_addr = 0;
 	ring_init(ep0, XHCI_EP0_TRBS, &s->ep0_enq, &s->ep0_cycle);
-	if (!mps || s->speed >= 4)
-		mps = ep0_mps_for_speed(s->speed);
+	mps = ep0_mps_initial(s->speed, mps);
+	s->ep0_mps = mps;
 
 	ram_wr64(dcbaa + slot_id * 8, dc);
 
@@ -697,8 +750,13 @@ static struct xhci_slot *new_slot_common(unsigned int target_addr,
 		      TRB_TYPE(TRB_ADDR_DEV) | (slot_id << 24) |
 		      (bsr ? TRB_BSR : 0), 0);
 	if (rc != 0) {
-		dbg(bsr ? "xhci: address default failed\n" :
-		    "xhci: address device failed\n");
+		xlog_hex(bsr ? "xhci: address default failed port " :
+			 "xhci: address device failed port ", s->port);
+		xlog_hex(" spd ", s->speed);
+		xlog_hex(" cc ", cmd_status);
+		xlog_hex(" portsc ",
+			 mmio_rd(op(XHCI_OP_PORTSC) + s->port * 0x10));
+		serial_putc(SERIAL_COM1, '\n');
 		ram_wr64(dcbaa + slot_id * 8, 0);
 		xhci_cmd(0, 0,
 			 TRB_TYPE(TRB_DISABLE_SLOT) | (slot_id << 24), 0);
@@ -777,10 +835,7 @@ static int set_address(unsigned int new_addr, unsigned int mps)
 	if (!s || new_addr == 0 || new_addr > 127)
 		return -1;
 
-	/* The USB core's first SET_ADDRESS uses its high/full-speed 64-byte
-	 * guess; a SuperSpeed slot's EP0 is always 512 bytes. */
-	if (s->speed >= 4)
-		mps = ep0_mps_for_speed(s->speed);
+	mps = ep0_mps_initial(s->speed, mps);
 
 	spin_lock_irqsave(&xhci_lock, &flags);
 	zero_page(input_ctx, 4096);
@@ -799,6 +854,7 @@ static int set_address(unsigned int new_addr, unsigned int mps)
 
 	spin_lock_irqsave(&xhci_lock, &flags);
 	s->dev_addr = ((unsigned int *)s->dc)[3] & 0xFF;
+	s->ep0_mps = mps;
 	addr_slot[0] = 0;
 	s->addr = new_addr;
 	addr_slot[new_addr] = s->slot_id;
@@ -807,6 +863,32 @@ static int set_address(unsigned int new_addr, unsigned int mps)
 }
 
 /* ---- control transfers ------------------------------------------------- */
+/* One line per failed control transfer: the request, the completion code
+ * (0 = no event within the timeout), the root port's PORTSC, and the slot /
+ * EP0 states from the output device context (slot state 2 = Addressed,
+ * EP state 2 = Halted, 4 = Error). */
+static void ctl_fail_log(const struct xhci_slot *s, const unsigned char *setup,
+			 unsigned int cc, unsigned int data_seen)
+{
+	const unsigned int *dc = (const unsigned int *)s->dc;
+	const unsigned int *ep0 = (const unsigned int *)(s->dc + ctx_size);
+
+	serial_puts(SERIAL_COM1, cc ? "xhci: ctl err" : "xhci: ctl timeout");
+	xlog_hex(" req ", (unsigned int)setup[0] | ((unsigned int)setup[1] << 8) |
+		 ((unsigned int)setup[2] << 16) | ((unsigned int)setup[3] << 24));
+	xlog_hex(" cc ", cc);
+	xlog_hex(" data ", data_seen);
+	xlog_hex(" slot ", s->slot_id);
+	xlog_hex(" spd ", s->speed);
+	xlog_hex(" portsc ", mmio_rd(op(XHCI_OP_PORTSC) + s->port * 0x10));
+	xlog_hex(" sstate ", dc[3] >> 27);
+	xlog_hex(" dev ", dc[3] & 0xFF);
+	xlog_hex(" ep0 ", ep0[0] & 7);
+	xlog_hex(" mps ", ep0[1] >> 16);
+	xlog_hex(" sts ", mmio_rd(op(XHCI_OP_USBSTS)));
+	serial_putc(SERIAL_COM1, '\n');
+}
+
 static int control_transfer(unsigned int ctrl, unsigned int addr,
 			    unsigned int mps, int low_speed,
 			    const unsigned char *setup, unsigned char *data,
@@ -854,6 +936,14 @@ static int control_transfer(unsigned int ctrl, unsigned int addr,
 			return -1;
 	}
 
+	/* The core learned the real bMaxPacketSize0 from the first 8 bytes
+	 * of the device descriptor; reprogram EP0 before using it.  Only a
+	 * full-speed EP0 can legally differ from the speed's fixed value. */
+	if (s->speed == 1 && (mps == 8 || mps == 16 || mps == 32 ||
+			      mps == 64) && mps != s->ep0_mps &&
+	    ep0_set_mps(s, mps) != 0)
+		return -1;
+
 	spin_lock_irqsave(&xhci_lock, &flags);
 	if (ctl_busy) {
 		spin_unlock_irqrestore(&xhci_lock, flags);
@@ -875,7 +965,10 @@ static int control_transfer(unsigned int ctrl, unsigned int addr,
 	 * transfer event is ever posted, while the per-stage encoding
 	 * completes. */
 	setup_c = TRB_TYPE(TRB_SETUP) | TRB_IDT | TRB_IOC;
-	if (len)
+	/* Transfer Type (TRT) only exists from xHCI 1.0 on; in a 0.96
+	 * controller (Etron EJ168, early VIA/Renesas parts) bits 17:16 are
+	 * reserved.  Linux sets it only for hci_version >= 0x100 too. */
+	if (len && hci_version >= 0x100)
 		setup_c |= (dir_in ? 3u : 2u) << 16;
 	ctl_setup_trb = s->ep0 + s->ep0_enq * 16;
 	ring_queue(s->ep0, XHCI_EP0_TRBS, &s->ep0_enq, &s->ep0_cycle,
@@ -931,7 +1024,7 @@ static int control_transfer(unsigned int ctrl, unsigned int addr,
 	if (!ctl_done) {
 		ctl_busy = 0;
 		spin_unlock_irqrestore(&xhci_lock, flags);
-		dbg("xhci: control timeout\n");
+		ctl_fail_log(s, setup, 0, ctl_data_seen);
 		return -1;
 	}
 	rc = ctl_actual;
@@ -940,7 +1033,7 @@ static int control_transfer(unsigned int ctrl, unsigned int addr,
 	spin_unlock_irqrestore(&xhci_lock, flags);
 
 	if (st != CC_SUCCESS && st != CC_SHORT_PACKET) {
-		dbg_hex("xhci: control status ", st);
+		ctl_fail_log(s, setup, st, ctl_data_seen);
 		return -1;
 	}
 	return (int)rc;
@@ -1258,8 +1351,12 @@ static int port_reset(unsigned int ctrl, unsigned int port)
 
 	/* Force the port into the Disabled state first: some xHCs ignore
 	 * PR while the port is already enabled, leaving the device at its
-	 * firmware-assigned address instead of address 0. */
-	if (ps & PORTSC_PED) {
+	 * firmware-assigned address instead of address 0.  USB2 ports only:
+	 * on a SuperSpeed port PED=1 puts the link into SS.Disabled, which a
+	 * hot reset (PR) does not leave -- software would have to write
+	 * PLS=RxDetect -- so the BIOS-booted stick stayed unreachable. */
+	if ((ps & PORTSC_PED) &&
+	    ((ps >> PORTSC_SPEED_SHIFT) & PORTSC_SPEED_MASK) < 4) {
 		mmio_wr(op(XHCI_OP_PORTSC) + port * 0x10,
 			portsc_neutral(ps) | PORTSC_PED);
 		t0 = get_ticks_ms();
@@ -1290,7 +1387,9 @@ static int port_reset(unsigned int ctrl, unsigned int port)
 		usb_poll_relax(t0);
 	}
 	if (!(ps & PORTSC_PRC)) {
-		dbg_hex("xhci: port reset timeout ", port);
+		xlog_hex("xhci: port reset timeout port ", port);
+		xlog_hex(" portsc ", ps);
+		serial_putc(SERIAL_COM1, '\n');
 		return -1;
 	}
 	mmio_wr(op(XHCI_OP_PORTSC) + port * 0x10,
@@ -1304,7 +1403,9 @@ static int port_reset(unsigned int ctrl, unsigned int port)
 		usb_poll_relax(t0);
 	}
 	if (!(ps & PORTSC_PED)) {
-		dbg_hex("xhci: port not enabled ", port);
+		xlog_hex("xhci: port not enabled port ", port);
+		xlog_hex(" portsc ", ps);
+		serial_putc(SERIAL_COM1, '\n');
 		return -1;
 	}
 
@@ -1485,7 +1586,9 @@ found_xhci:
 	mmio_base = bar;
 	paging_map_mmio(mmio_base, 0x10000);
 
+	pci_id = pci_cfg_read32(pci_bus, pci_dev, pci_func, 0x00);
 	cap_len = mmio_rd(0) & 0xFF;
+	hci_version = mmio_rd(0) >> 16;
 	hcs1 = mmio_rd(XHCI_CAP_HCSPARAMS1);
 	hcs2 = mmio_rd(XHCI_CAP_HCSPARAMS2);
 	hcc_params = mmio_rd(XHCI_CAP_HCCPARAMS1);
@@ -1656,7 +1759,13 @@ found_xhci:
 	 * while commands complete normally. */
 
 	scan_protocols();
-	dbg_hex("xhci: ports ", port_mask);
+	xlog_hex("xhci: ", pci_id);
+	xlog_hex(" hci ", hci_version);
+	xlog_hex(" mmio ", mmio_base);
+	xlog_hex(" ports ", port_mask);
+	xlog_hex(" csz ", ctx_size);
+	xlog_hex(" scratch ", n);
+	serial_putc(SERIAL_COM1, '\n');
 
 	/* Power every root port.  VBus is supposed to come up after HCRST,
 	 * but some firmware/PPC combinations leave PP clear; the USB3

+ 40 - 0
testdata/browser/compat/072-styled-controls.html

@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>072 author-styled form controls</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 14px; }
+  .pane { float: left; width: 330px; margin-right: 20px; }
+  /* A: real controls styled like google.com's search page */
+  .A input[type="submit"] { background-color: #e8eaed; border: 1px solid #e8eaed;
+         border-radius: 8px; color: #3c4043; padding: 0 16px; height: 36px;
+         margin: 11px 4px; font-size: 14px; }
+  .A .box, .B .box { border: 1px solid #9aa0a6; border-radius: 22px;
+         height: 44px; background: #ffffff; }
+  .A textarea { width: 100%; background-color: transparent; border: none;
+         padding: 0; margin: 0; resize: none; font-size: 16px; }
+  /* B: the same look built from plain boxes */
+  .B .btn { display: inline-block; background: #e8eaed; border: 1px solid #e8eaed;
+         border-radius: 8px; color: #3c4043; padding: 9px 16px;
+         margin: 11px 4px; }
+  /* Only for forced-colors (high contrast): must not apply here. */
+  @media (forced-colors: active) { .A input[type="submit"] { border: 3px solid #ff0000; } }
+</style>
+</head>
+<body>
+<h1>072 &mdash; author-styled controls</h1>
+<p>A control with author background/border/radius is painted with that
+   style (not the dark UI theme); a transparent borderless textarea is
+   invisible inside its rounded box.  A and B must look alike.</p>
+<div class="pane A">
+  <div class="box"><textarea rows="1"></textarea></div>
+  <center><input type="submit" value="Search"><input type="submit" value="Lucky"></center>
+</div>
+<div class="pane B">
+  <div class="box"></div>
+  <center><span class="btn">Search</span><span class="btn">Lucky</span></center>
+</div>
+</body>
+</html>

+ 21 - 0
testdata/browser/compat/073-noscript.html

@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>073 noscript with scripting enabled</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  #result { background: #c8f0c8; color: #000000; padding: 8px; margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>073 &mdash; noscript</h1>
+<p>Scripting is on, so <code>&lt;noscript&gt;</code> content is raw text:
+   its style and meta refresh must not apply (google.com hides every div
+   this way).  The green NOSCRIPT-OK line must be visible and no
+   "NOSCRIPT-FAIL" text may appear.</p>
+<noscript><meta http-equiv="refresh" content="0;url=about:blank"><style>div,p{display:none}</style><span>NOSCRIPT-FAIL</span></noscript>
+<div id="result">NOSCRIPT-OK</div>
+</body>
+</html>

+ 1 - 1
testdata/browser/compat/README

@@ -17,7 +17,7 @@ Serve this directory from the host and open it on the board:
   browser http://<host>:8000/            # board
   browser http://10.0.2.2:8000/         # QEMU with -netdev user
 
-Status: 010-071 and 030a pass.  036a needs the POST echo server:
+Status: 010-073 and 030a pass.  036a needs the POST echo server:
 
   python3 testdata/browser/compat/post_server.py
   browser /floppy1/036a.htm      # action is http://10.0.2.2:8765/echo

+ 2 - 0
testdata/browser/compat/index.html

@@ -94,6 +94,8 @@ a { color: #0645ad; }
 <tr><td>069</td><td><a href="069-inline-flex-tail.html">inline-flex tail</a></td><td>inline-flex around text stays in the line</td><td class="pass">PASS</td></tr>
 <tr><td>070</td><td><a href="070-many-absolute.html">many absolute boxes</a></td><td>more than 16 absolute boxes keep their containing block</td><td class="pass">PASS</td></tr>
 <tr><td>071</td><td><a href="071-modern-js.html">modern JavaScript</a></td><td>classes, private fields, arrows, templates, destructuring, Map/Set, optional chaining, async/await</td><td class="pass">PASS</td></tr>
+<tr><td>072</td><td><a href="072-styled-controls.html">author-styled controls</a></td><td>inputs/textarea with author background, border, radius, padding and height; forced-colors media is false</td><td class="pass">PASS</td></tr>
+<tr><td>073</td><td><a href="073-noscript.html">noscript</a></td><td>with scripting on, noscript content (style, meta refresh) is inert</td><td class="pass">PASS</td></tr>
 </table>
 </body>
 </html>

+ 104 - 0
tools/cursor_test.c

@@ -0,0 +1,104 @@
+/* Host test for the NBCUR1 cursor bundle built by mkcursors
+ * (make test-cursors): structure, a few Adwaita hotspots, the subsampled
+ * spinner, and that every frame has visible pixels. */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "cursor_abi.h"
+
+static int fails;
+
+#define CHECK(c, ...) do { if (!(c)) { fails++; \
+	fprintf(stderr, "FAIL %s:%d: ", __FILE__, __LINE__); \
+	fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } } while (0)
+
+int main(int argc, char **argv)
+{
+	const char *path = argc > 1 ? argv[1] : "cursors/adwaita24.cur";
+	FILE *f = fopen(path, "rb");
+	unsigned char *buf;
+	long size;
+	const struct cursor_file_hdr *h;
+	const struct cursor_file_shape *s;
+	unsigned int i, fr;
+
+	if (!f) {
+		perror(path);
+		return 1;
+	}
+	fseek(f, 0, SEEK_END);
+	size = ftell(f);
+	fseek(f, 0, SEEK_SET);
+	buf = malloc((size_t)size);
+	if (!buf || fread(buf, 1, (size_t)size, f) != (size_t)size)
+		return 1;
+	fclose(f);
+
+	h = (const struct cursor_file_hdr *)buf;
+	s = (const struct cursor_file_shape *)(buf + sizeof(*h));
+	CHECK(memcmp(h->magic, CURSOR_FILE_MAGIC, 8) == 0, "magic");
+	CHECK(h->count == CURSOR_COUNT, "count %u", h->count);
+	CHECK(h->nominal == 24, "nominal %u", h->nominal);
+	if (fails)
+		return 1;
+
+	for (i = 0; i < h->count; i++) {
+		unsigned int px = (unsigned int)s[i].w * s[i].h;
+
+		CHECK(s[i].w == 24 && s[i].h == 24, "shape %u size %ux%u",
+		      i, s[i].w, s[i].h);
+		CHECK(s[i].hot_x < s[i].w && s[i].hot_y < s[i].h,
+		      "shape %u hotspot", i);
+		CHECK(s[i].frames >= 1, "shape %u frames", i);
+		CHECK((s[i].offset & 3) == 0 &&
+		      s[i].offset + px * 4u * s[i].frames <= (unsigned long)size,
+		      "shape %u range", i);
+		for (fr = 0; fr < s[i].frames; fr++) {
+			const unsigned int *p = (const unsigned int *)
+				(buf + s[i].offset) + fr * px;
+			unsigned int k, opaque = 0, bad = 0;
+
+			for (k = 0; k < px; k++) {
+				unsigned int a = p[k] >> 24;
+
+				if (a)
+					opaque++;
+				/* Premultiplied: no channel above alpha. */
+				if (((p[k] >> 16) & 0xFF) > a ||
+				    ((p[k] >> 8) & 0xFF) > a || (p[k] & 0xFF) > a)
+					bad++;
+			}
+			CHECK(opaque > 10, "shape %u frame %u is empty", i, fr);
+			CHECK(bad == 0, "shape %u frame %u not premultiplied", i,
+			      fr);
+		}
+	}
+	/* Hotspots from the Adwaita 51 Xcursor files. */
+	CHECK(s[CURSOR_DEFAULT].hot_x == 3 && s[CURSOR_DEFAULT].hot_y == 1,
+	      "default hotspot");
+	CHECK(s[CURSOR_TEXT].hot_x == 11 && s[CURSOR_TEXT].hot_y == 12,
+	      "text hotspot");
+	CHECK(s[CURSOR_POINTER].hot_x == 7 && s[CURSOR_POINTER].hot_y == 5,
+	      "pointer hotspot");
+	/* move is Adwaita's all-resize (its own `move` is a symlink to the
+	 * arrow). */
+	CHECK(s[CURSOR_MOVE].hot_x == 12 && s[CURSOR_MOVE].hot_y == 11,
+	      "move hotspot");
+	/* 60 frames x 16 ms, every 4th kept: 15 frames x 64 ms. */
+	CHECK(s[CURSOR_WAIT].frames == 15 && s[CURSOR_WAIT].delay_ms == 64,
+	      "wait %u frames x %u ms", s[CURSOR_WAIT].frames,
+	      s[CURSOR_WAIT].delay_ms);
+	CHECK(s[CURSOR_PROGRESS].frames == 15, "progress frames");
+	CHECK(s[CURSOR_DEFAULT].frames == 1 && s[CURSOR_DEFAULT].delay_ms == 0,
+	      "default is static");
+
+	i = h->count;
+	free(buf);
+	if (fails) {
+		fprintf(stderr, "cursor_test: %d failure(s)\n", fails);
+		return 1;
+	}
+	printf("cursor_test: %u shapes OK (%ld bytes)\n", i, size);
+	return 0;
+}

+ 184 - 0
tools/mkcursors.c

@@ -0,0 +1,184 @@
+/* mkcursors: build the NBCUR1 cursor bundle (include/cursor_abi.h) from an
+ * Xcursor theme directory.
+ *
+ *   ./mkcursors <theme-dir> <size> <out.cur>
+ *
+ * For every shape in CURSOR_LIST it reads <theme-dir>/<file>, takes the
+ * image chunks of nominal size <size>, and writes them in shape order.
+ * Animated cursors (Adwaita's wait/progress: 60 frames x 16 ms) keep every
+ * Nth frame so that no frame is shorter than MIN_DELAY_MS, with the delay
+ * scaled to keep the animation speed; the kernel only advances frames from
+ * the poll loop, so 16 ms frames would just be skipped anyway. */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+#include "cursor_abi.h"
+
+#define XCUR_IMAGE 0xFFFD0002u
+#define MIN_DELAY_MS 60
+#define MAX_FRAMES 64
+
+struct xframe {
+	uint32_t w, h, xhot, yhot, delay;
+	const uint32_t *px;
+};
+
+static uint32_t rd32(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 unsigned char *read_file(const char *path, size_t *len)
+{
+	FILE *f = fopen(path, "rb");
+	unsigned char *buf;
+	long n;
+
+	if (!f)
+		return NULL;
+	fseek(f, 0, SEEK_END);
+	n = ftell(f);
+	fseek(f, 0, SEEK_SET);
+	buf = malloc(n > 0 ? (size_t)n : 1);
+	if (!buf || fread(buf, 1, (size_t)n, f) != (size_t)n) {
+		fclose(f);
+		free(buf);
+		return NULL;
+	}
+	fclose(f);
+	*len = (size_t)n;
+	return buf;
+}
+
+/* Collect the image chunks of `size`; returns the frame count or -1. */
+static int parse_xcursor(const unsigned char *d, size_t len, unsigned int size,
+			 struct xframe *out, int max)
+{
+	uint32_t hdr, ntoc, i;
+	int n = 0;
+
+	if (len < 16 || memcmp(d, "Xcur", 4) != 0)
+		return -1;
+	hdr = rd32(d + 4);
+	ntoc = rd32(d + 12);
+	if ((size_t)hdr + (size_t)ntoc * 12 > len)
+		return -1;
+	for (i = 0; i < ntoc; i++) {
+		const unsigned char *t = d + hdr + i * 12;
+		uint32_t pos = rd32(t + 8);
+		const unsigned char *c;
+		struct xframe fr;
+
+		if (rd32(t) != XCUR_IMAGE || rd32(t + 4) != size)
+			continue;
+		if ((size_t)pos + 36 > len)
+			return -1;
+		c = d + pos;
+		fr.w = rd32(c + 16);
+		fr.h = rd32(c + 20);
+		fr.xhot = rd32(c + 24);
+		fr.yhot = rd32(c + 28);
+		fr.delay = rd32(c + 32);
+		if (!fr.w || !fr.h || fr.w > CURSOR_MAX_DIM ||
+		    fr.h > CURSOR_MAX_DIM || fr.xhot >= fr.w || fr.yhot >= fr.h)
+			return -1;
+		if ((size_t)pos + rd32(c) + (size_t)fr.w * fr.h * 4 > len)
+			return -1;
+		fr.px = (const uint32_t *)(c + rd32(c));
+		if (n >= max)
+			return -1;
+		out[n++] = fr;
+	}
+	return n ? n : -1;
+}
+
+#define CURSOR_FILE_(e, css, file) file,
+static const char *const theme_files[CURSOR_COUNT] = {
+	CURSOR_LIST(CURSOR_FILE_)
+};
+#undef CURSOR_FILE_
+
+int main(int argc, char **argv)
+{
+	struct cursor_file_hdr hdr;
+	struct cursor_file_shape shapes[CURSOR_COUNT];
+	unsigned char *files[CURSOR_COUNT];
+	struct xframe frames[CURSOR_COUNT][MAX_FRAMES];
+	int nframes[CURSOR_COUNT], step[CURSOR_COUNT];
+	unsigned int size, off;
+	FILE *out;
+	int i, j;
+
+	if (argc != 4) {
+		fprintf(stderr, "usage: %s <theme-dir> <size> <out.cur>\n",
+			argv[0]);
+		return 2;
+	}
+	size = (unsigned int)atoi(argv[2]);
+	off = sizeof(hdr) + sizeof(shapes);
+	for (i = 0; i < CURSOR_COUNT; i++) {
+		char path[1024];
+		size_t len;
+		int n, kept;
+
+		snprintf(path, sizeof(path), "%s/%s", argv[1], theme_files[i]);
+		files[i] = read_file(path, &len);
+		if (!files[i]) {
+			fprintf(stderr, "mkcursors: cannot read %s\n", path);
+			return 1;
+		}
+		n = parse_xcursor(files[i], len, size, frames[i], MAX_FRAMES);
+		if (n < 0) {
+			fprintf(stderr, "mkcursors: %s: no valid %u px image\n",
+				path, size);
+			return 1;
+		}
+		step[i] = 1;
+		if (n > 1 && frames[i][0].delay && frames[i][0].delay < MIN_DELAY_MS)
+			step[i] = (MIN_DELAY_MS + frames[i][0].delay - 1) /
+				  frames[i][0].delay;
+		kept = (n + step[i] - 1) / step[i];
+		nframes[i] = n;
+		shapes[i].w = (unsigned short)frames[i][0].w;
+		shapes[i].h = (unsigned short)frames[i][0].h;
+		shapes[i].hot_x = (unsigned short)frames[i][0].xhot;
+		shapes[i].hot_y = (unsigned short)frames[i][0].yhot;
+		shapes[i].frames = (unsigned short)kept;
+		shapes[i].delay_ms = (unsigned short)(n > 1 ?
+			frames[i][0].delay * (unsigned int)step[i] : 0);
+		shapes[i].offset = off;
+		for (j = 0; j < n; j += step[i])
+			if (frames[i][j].w != frames[i][0].w ||
+			    frames[i][j].h != frames[i][0].h) {
+				fprintf(stderr, "mkcursors: %s: frame sizes differ\n",
+					path);
+				return 1;
+			}
+		off += (unsigned int)kept * shapes[i].w * shapes[i].h * 4;
+	}
+
+	memcpy(hdr.magic, CURSOR_FILE_MAGIC, 8);
+	hdr.count = CURSOR_COUNT;
+	hdr.nominal = size;
+	out = fopen(argv[3], "wb");
+	if (!out) {
+		perror(argv[3]);
+		return 1;
+	}
+	fwrite(&hdr, sizeof(hdr), 1, out);
+	fwrite(shapes, sizeof(shapes), 1, out);
+	for (i = 0; i < CURSOR_COUNT; i++)
+		for (j = 0; j < nframes[i]; j += step[i])
+			fwrite(frames[i][j].px, 4,
+			       (size_t)shapes[i].w * shapes[i].h, out);
+	if (fclose(out) != 0) {
+		perror(argv[3]);
+		return 1;
+	}
+	for (i = 0; i < CURSOR_COUNT; i++)
+		free(files[i]);
+	return 0;
+}

Некоторые файлы не были показаны из-за большого количества измененных файлов