# DuskBSD wrappers

The /drv/bsd directory contains wrapper around DuskBSD's (see doc/netbsd)
memory structures, allowing complex interactions with the kernel.

## Kernel API (/drv/bsd/kernel.fs)

At the root of all this is the "KExecAPI" structure, as defined in DuskBSD's
`kern/kexec.c` file. A pointer to this structure is passed as an argument to
the Kexec payload and the `Kernel` structure mirrors the structure defined in
the C source of the kernel.

Those are mostly pointers to root structures and functions, which are then
reused by other wrappers, but some words are usable as-is, such as `(emit)` and
`(key)`, which are of course implementation to `emit` and `key`.

This unit defines a `kernel` structbind to that structure.

## Device (/drv/bsd/device.fs)

This unit wraps some structures defined in DuskBSD's `sys/device.h` source file.

### CFData

Mirrors `struct cf_data` and adds these convienience methods:

:. ( self -- )
  Print a representation of the structure.

### Device

Mirrors `struct device`. In this NS, there are also constants for each of the
"devclass" enum (for example, "Device DV_DISK"). On top of that, there's these
convenience words:

first ( -- dev )
  Yields the first device of the whole list ("mainbus0" probably).

.roottree ( -- )
  Print the whole device tree.

.disks ( -- )
  Print all devices of class DV_DISK.

:iter ( -- ) ( Runtime: -- ) *I* i=dev j=ahead
  Iterate over all devices. "ahead" is the device following the one being
  iterated upon.

:iterclass ( -- ) ( Runtime: class -- ) *I* k=class
  Iterate over all device where dv_class=class.

:. ( self -- )
  Print a representation of the structure.

:.tree ( self -- )
  Prints itself as well as all its children in a cute hierarchical layout.

## WSDisplay (/drv/bsd/wsdisp.fs)

This unit wraps some structures defined in DuskBSD's `wsdisplay` subsystem. It
also defines `WSDisplayGrid`, a Grid (see doc/sys/grid) implementation using
this subsystem.

WARNING: For this wrappers to work, the kernel has to be compiled *without* the
`WSDISPLAY_SCROLLSUPPORT` option.

### WSDisplayEmulOps

Mirrors `struct wsdisplay_emulops`.

### WSScreenInternal

Mirrors `struct wsscreen_internal`.

### WSScreen

Mirrors `struct wsscreen`.

### WSDisplaySoftC

Mirrors `struct wsdisplay_softc`.

### WSDisplay

Extends `Device` (so it's supposed to wrap a `struct device` describing a
`wsdisplay`) and adds these convenience words:

:dconf ( self -- dconf )
  Yields the `WSScreenInternal` struct associated to the device.

:emulops ( self -- emulops )
  Yields the `WSDisplayEmulOps` struct associated to the device.

:emulcookie ( self -- cookie )
  Yields the "cookie" value to pass to functions in :emulops.

:putchar ( row col c attr self -- )
  Calls :emulops's `putchar` function, which places character `c` with
  attributes `attr` at specified row/col.

:cursor ( row col self -- )
  Calls :emulops's `cursor` function, which places cursor at specified row/col.

## WDDisplayGrid

Implements a Grid using the specified WSDisplay device.

:new ( wsdisplay -- grid )
  Create a new WSDisplayGrid wrapping `wsdisplay`, likely coming from
  "Kernel wsdisplaydev".
