Skip to content

<dev/tty.h>

ttysvc protocol and client helpers.

ttysvc joins providers (UART and console drivers) to consumers (programs) through named endpoints. Each session, either kind, shares one page with ttysvc that holds two byte rings: up carries bytes from the session's owner to ttysvc, down carries bytes from ttysvc to the owner. For a driver, up is what was received and down is what to transmit; for a program, up is its output and down is its input.

A session's index is (generation << 8) | slot, so an index from a closed session never matches a reused slot. It is guessable, so any peer can close or re-mode another's session.

#include <dev/tty.h>

Types

Type Definition Description
TtyWatchRequest TtyCloseRequest TTY_WATCH request; same layout as TtyCloseRequest.
TtyFocusRequest TtyCloseRequest TTY_FOCUS request; same layout as TtyCloseRequest.

Constants

Name Value Description
TTY_NAME_MAX 16 Longest endpoint alias, including the NUL.
TTY_RING_DATA_SIZE 1024u Bytes in each ring.
TTY_PROVIDE 1 Provide an endpoint (drivers). TtyConnectRequest; grants the session page. Replies TtyConnectReply and grants ttysvc's doorbell.
TTY_ATTACH 2 Attach to an endpoint (programs). Same request and reply as TTY_PROVIDE.
TTY_NOTIFY 3 Give ttysvc the caller's event. TtyNotifyRequest; grants the event.
TTY_SETMODE 4 Set a consumer's mode. TtySetModeRequest.
TTY_CLOSE 5 End a session. TtyCloseRequest.
TTY_WATCH 6 Tie a session to the caller's life. TtyWatchRequest; grants a port the caller owns (PERM_WAIT | PERM_TXFR). ttysvc closes the session when that port dies.
TTY_FOCUS 7 Take the endpoint's input (consumers). TtyFocusRequest.
TTY_MODE_RAW 0u Mode: bytes pass through untouched. The default.
TTY_MODE_COOKED (1u << 0) Mode: line editing (^H, DEL, ^U, ^W), input delivered a line at a time, ^D signals EOF and ^C an interrupt; ' ' becomes "\r\n" on output.
TTY_MODE_ECHO (1u << 1) Mode: ttysvc echoes typed characters.
TTY_MODE_ALL (TTY_MODE_COOKED \| TTY_MODE_ECHO) Every mode flag.

Structures

TtyCtl

Out-of-band signals from ttysvc to a consumer.

Field Type Description
eof_seq volatile uint32_t Bumped by ttysvc for each ^D in cooked mode.
eof_ack volatile uint32_t Last eof_seq the consumer has handled.
eof_pos volatile uint32_t down ring position the EOF applies at.
intr_seq volatile uint32_t Bumped by ttysvc for each ^C in cooked mode.

TtyShm

The page a session shares with ttysvc.

Field Type Description
up_hdr ShmRingHdr Owner to ttysvc ring.
up_data uint8_t Its data.
down_hdr ShmRingHdr ttysvc to owner ring.
down_data uint8_t Its data.
ctl TtyCtl EOF and interrupt signals.

TtyConnectRequest

TTY_PROVIDE and TTY_ATTACH request.

Field Type Description
cmd uint32_t TTY_PROVIDE or TTY_ATTACH.
alias char Endpoint name; empty attaches to the default endpoint.

TtyNotifyRequest

TTY_NOTIFY request.

Field Type Description
cmd uint32_t TTY_NOTIFY.
index uint32_t Session index.
bit uint32_t Bit ttysvc rings on the caller's event.

TtySetModeRequest

TTY_SETMODE request.

Field Type Description
cmd uint32_t TTY_SETMODE.
index uint32_t Session index.
flags uint32_t TTY_MODE_* flags.

TtyCloseRequest

TTY_CLOSE request.

Field Type Description
cmd uint32_t The command.
index uint32_t Session index.

TtyConnectReply

TTY_PROVIDE and TTY_ATTACH reply.

Field Type Description
status Err ZUZU_OK, or an error code.
bit uint32_t Bit to ring on ttysvc's doorbell.
index uint32_t Session index for later requests.

TtyConn

A session with ttysvc, for providers and consumers alike.

Field Type Description
shm TtyShm * Mapped session page.
mem Handle The session page's memory object.
doorbell Handle ttysvc's event, send-only.
bit uint32_t Bit to ring on doorbell.
index uint32_t Session index.
live Handle Port this client owns; ttysvc watches it to notice the client's death.