FreeBSD kernel kern code
subr_terminal.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/cons.h>
#include <sys/consio.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/systm.h>
#include <sys/terminal.h>
#include <sys/tty.h>
#include <machine/stdarg.h>
Include dependency graph for subr_terminal.c:

Go to the source code of this file.

Macros

#define TERMINAL_LOCK(tm)
 
#define TERMINAL_UNLOCK(tm)
 
#define TERMINAL_LOCK_TTY(tm)
 
#define TERMINAL_UNLOCK_TTY(tm)
 
#define TERMINAL_LOCK_CONS(tm)   mtx_lock_spin(&(tm)->tm_mtx)
 
#define TERMINAL_UNLOCK_CONS(tm)   mtx_unlock_spin(&(tm)->tm_mtx)
 
#define TCOLOR_FG_FUDGED(color)
 
#define TCOLOR_BG_FUDGED(color)
 
#define TCOLOR_256TO16(color)
 
#define TCHAR_CREATE(c, a)
 

Functions

 __FBSDID ("$FreeBSD$")
 
static MALLOC_DEFINE (M_TERMINAL, "terminal", "terminal device")
 
static void terminal_init (struct terminal *tm)
 
struct terminal * terminal_alloc (const struct terminal_class *tc, void *softc)
 
static void terminal_sync_ttysize (struct terminal *tm)
 
void terminal_maketty (struct terminal *tm, const char *fmt,...)
 
void terminal_set_cursor (struct terminal *tm, const term_pos_t *pos)
 
void terminal_set_winsize_blank (struct terminal *tm, const struct winsize *size, int blank, const term_attr_t *attr)
 
void terminal_set_winsize (struct terminal *tm, const struct winsize *size)
 
void terminal_mute (struct terminal *tm, int yes)
 
void terminal_input_char (struct terminal *tm, term_char_t c)
 
void terminal_input_raw (struct terminal *tm, char c)
 
void terminal_input_special (struct terminal *tm, unsigned int k)
 
static int termtty_open (struct tty *tp)
 
static void termtty_close (struct tty *tp)
 
static void termtty_outwakeup (struct tty *tp)
 
static int termtty_ioctl (struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
 
static int termtty_mmap (struct tty *tp, vm_ooffset_t offset, vm_paddr_t *paddr, int nprot, vm_memattr_t *memattr)
 
void termcn_cnregister (struct terminal *tm)
 
static void termcn_cngrab (struct consdev *cp)
 
static void termcn_cnungrab (struct consdev *cp)
 
static void termcn_cnprobe (struct consdev *cp)
 
static void termcn_cninit (struct consdev *cp)
 
static void termcn_cnterm (struct consdev *cp)
 
static int termcn_cngetc (struct consdev *cp)
 
static void termcn_cnputc (struct consdev *cp, int c)
 
static void termteken_bell (void *softc)
 
static void termteken_cursor (void *softc, const teken_pos_t *p)
 
static void termteken_putchar (void *softc, const teken_pos_t *p, teken_char_t c, const teken_attr_t *a)
 
static void termteken_fill (void *softc, const teken_rect_t *r, teken_char_t c, const teken_attr_t *a)
 
static void termteken_copy (void *softc, const teken_rect_t *r, const teken_pos_t *p)
 
static void termteken_pre_input (void *softc)
 
static void termteken_post_input (void *softc)
 
static void termteken_param (void *softc, int cmd, unsigned int arg)
 
static void termteken_respond (void *softc, const void *buf, size_t len)
 

Variables

static tsw_open_t termtty_open
 
static tsw_close_t termtty_close
 
static tsw_outwakeup_t termtty_outwakeup
 
static tsw_ioctl_t termtty_ioctl
 
static tsw_mmap_t termtty_mmap
 
static struct ttydevsw terminal_tty_class
 
static tf_bell_t termteken_bell
 
static tf_cursor_t termteken_cursor
 
static tf_putchar_t termteken_putchar
 
static tf_fill_t termteken_fill
 
static tf_copy_t termteken_copy
 
static tf_pre_input_t termteken_pre_input
 
static tf_post_input_t termteken_post_input
 
static tf_param_t termteken_param
 
static tf_respond_t termteken_respond
 
static teken_funcs_t terminal_drawmethods
 
static teken_attr_t kernel_message
 
static teken_attr_t default_message
 
static cn_probe_t termcn_cnprobe
 
static cn_init_t termcn_cninit
 
static cn_term_t termcn_cnterm
 
static cn_getc_t termcn_cngetc
 
static cn_putc_t termcn_cnputc
 
static cn_grab_t termcn_cngrab
 
static cn_ungrab_t termcn_cnungrab
 
const struct consdev_ops termcn_cnops
 

Macro Definition Documentation

◆ TCHAR_CREATE

#define TCHAR_CREATE (   c,
 
)
Value:
((c) | TFORMAT((a)->ta_format) | \
TCOLOR_FG_FUDGED(TCOLOR_256TO16((a)->ta_fgcolor)) | \
TCOLOR_BG_FUDGED(TCOLOR_256TO16((a)->ta_bgcolor)))
#define TCOLOR_256TO16(color)
#define TCOLOR_BG_FUDGED(color)
#define TCOLOR_FG_FUDGED(color)

Definition at line 163 of file subr_terminal.c.

◆ TCOLOR_256TO16

#define TCOLOR_256TO16 (   color)
Value:
__extension__ ({ \
teken_color_t _c; \
\
_c = (color); \
if (_c >= 16) \
_c = teken_256to16(_c); \
_c; \
})

Definition at line 154 of file subr_terminal.c.

◆ TCOLOR_BG_FUDGED

#define TCOLOR_BG_FUDGED (   color)
Value:
__extension__ ({ \
teken_color_t _c; \
\
_c = (color); \
TCOLOR_BG(_c & 7) | ((_c & 8) << 20); \
})

Definition at line 147 of file subr_terminal.c.

◆ TCOLOR_FG_FUDGED

#define TCOLOR_FG_FUDGED (   color)
Value:
__extension__ ({ \
teken_color_t _c; \
\
_c = (color); \
TCOLOR_FG(_c & 7) | ((_c & 8) << 18); \
})

Definition at line 139 of file subr_terminal.c.

◆ TERMINAL_LOCK

#define TERMINAL_LOCK (   tm)
Value:
do { \
if ((tm)->tm_flags & TF_CONS) \
mtx_lock_spin(&(tm)->tm_mtx); \
else if ((tm)->tm_tty != NULL) \
tty_lock((tm)->tm_tty); \
} while (0)

Definition at line 58 of file subr_terminal.c.

◆ TERMINAL_LOCK_CONS

#define TERMINAL_LOCK_CONS (   tm)    mtx_lock_spin(&(tm)->tm_mtx)

Definition at line 78 of file subr_terminal.c.

◆ TERMINAL_LOCK_TTY

#define TERMINAL_LOCK_TTY (   tm)
Value:
do { \
if ((tm)->tm_flags & TF_CONS) \
mtx_lock_spin(&(tm)->tm_mtx); \
} while (0)

Definition at line 70 of file subr_terminal.c.

◆ TERMINAL_UNLOCK

#define TERMINAL_UNLOCK (   tm)
Value:
do { \
if ((tm)->tm_flags & TF_CONS) \
mtx_unlock_spin(&(tm)->tm_mtx); \
else if ((tm)->tm_tty != NULL) \
tty_unlock((tm)->tm_tty); \
} while (0)

Definition at line 64 of file subr_terminal.c.

◆ TERMINAL_UNLOCK_CONS

#define TERMINAL_UNLOCK_CONS (   tm)    mtx_unlock_spin(&(tm)->tm_mtx)

Definition at line 79 of file subr_terminal.c.

◆ TERMINAL_UNLOCK_TTY

#define TERMINAL_UNLOCK_TTY (   tm)
Value:
do { \
if ((tm)->tm_flags & TF_CONS) \
mtx_unlock_spin(&(tm)->tm_mtx); \
} while (0)

Definition at line 74 of file subr_terminal.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ MALLOC_DEFINE()

static MALLOC_DEFINE ( M_TERMINAL  ,
"terminal"  ,
"terminal device  
)
static

◆ termcn_cngetc()

static int termcn_cngetc ( struct consdev *  cp)
static

Definition at line 595 of file subr_terminal.c.

◆ termcn_cngrab()

static void termcn_cngrab ( struct consdev *  cp)
static

Definition at line 551 of file subr_terminal.c.

◆ termcn_cninit()

static void termcn_cninit ( struct consdev *  cp)
static

Definition at line 583 of file subr_terminal.c.

◆ termcn_cnprobe()

static void termcn_cnprobe ( struct consdev *  cp)
static

Definition at line 567 of file subr_terminal.c.

References terminal_init().

Here is the call graph for this function:

◆ termcn_cnputc()

static void termcn_cnputc ( struct consdev *  cp,
int  c 
)
static

Definition at line 603 of file subr_terminal.c.

References kernel_message, TERMINAL_LOCK_CONS, and TERMINAL_UNLOCK_CONS.

◆ termcn_cnregister()

void termcn_cnregister ( struct terminal *  tm)

Definition at line 527 of file subr_terminal.c.

References cnadd(), malloc(), sprintf(), termcn_cnops, and terminal_init().

Here is the call graph for this function:

◆ termcn_cnterm()

static void termcn_cnterm ( struct consdev *  cp)
static

Definition at line 589 of file subr_terminal.c.

◆ termcn_cnungrab()

static void termcn_cnungrab ( struct consdev *  cp)
static

Definition at line 559 of file subr_terminal.c.

◆ terminal_alloc()

struct terminal * terminal_alloc ( const struct terminal_class *  tc,
void *  softc 
)

Definition at line 202 of file subr_terminal.c.

References malloc(), and terminal_init().

Here is the call graph for this function:

◆ terminal_init()

static void terminal_init ( struct terminal *  tm)
static

Definition at line 168 of file subr_terminal.c.

References default_message, kernel_message, and terminal_drawmethods.

Referenced by termcn_cnprobe(), termcn_cnregister(), and terminal_alloc().

Here is the caller graph for this function:

◆ terminal_input_char()

void terminal_input_char ( struct terminal *  tm,
term_char_t  c 
)

Definition at line 306 of file subr_terminal.c.

References ttydisc_rint(), ttydisc_rint_done(), and ttydisc_rint_simple().

Here is the call graph for this function:

◆ terminal_input_raw()

void terminal_input_raw ( struct terminal *  tm,
char  c 
)

Definition at line 359 of file subr_terminal.c.

References ttydisc_rint(), and ttydisc_rint_done().

Here is the call graph for this function:

◆ terminal_input_special()

void terminal_input_special ( struct terminal *  tm,
unsigned int  k 
)

Definition at line 374 of file subr_terminal.c.

References ttydisc_rint_done(), and ttydisc_rint_simple().

Here is the call graph for this function:

◆ terminal_maketty()

void terminal_maketty ( struct terminal *  tm,
const char *  fmt,
  ... 
)

Definition at line 230 of file subr_terminal.c.

References name, terminal_sync_ttysize(), terminal_tty_class, tty_alloc(), and vsnrprintf().

Here is the call graph for this function:

◆ terminal_mute()

void terminal_mute ( struct terminal *  tm,
int  yes 
)

Definition at line 294 of file subr_terminal.c.

References TERMINAL_LOCK, and TERMINAL_UNLOCK.

◆ terminal_set_cursor()

void terminal_set_cursor ( struct terminal *  tm,
const term_pos_t *  pos 
)

Definition at line 247 of file subr_terminal.c.

◆ terminal_set_winsize()

void terminal_set_winsize ( struct terminal *  tm,
const struct winsize *  size 
)

Definition at line 280 of file subr_terminal.c.

References default_message, and terminal_set_winsize_blank().

Here is the call graph for this function:

◆ terminal_set_winsize_blank()

void terminal_set_winsize_blank ( struct terminal *  tm,
const struct winsize *  size,
int  blank,
const term_attr_t *  attr 
)

Definition at line 254 of file subr_terminal.c.

References TCHAR_CREATE, TERMINAL_LOCK, terminal_sync_ttysize(), and TERMINAL_UNLOCK.

Referenced by terminal_set_winsize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ terminal_sync_ttysize()

static void terminal_sync_ttysize ( struct terminal *  tm)
static

Definition at line 216 of file subr_terminal.c.

References tty_set_winsize().

Referenced by terminal_maketty(), and terminal_set_winsize_blank().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ termteken_bell()

static void termteken_bell ( void *  softc)
static

Definition at line 625 of file subr_terminal.c.

◆ termteken_copy()

static void termteken_copy ( void *  softc,
const teken_rect_t *  r,
const teken_pos_t *  p 
)
static

Definition at line 659 of file subr_terminal.c.

◆ termteken_cursor()

static void termteken_cursor ( void *  softc,
const teken_pos_t *  p 
)
static

Definition at line 633 of file subr_terminal.c.

◆ termteken_fill()

static void termteken_fill ( void *  softc,
const teken_rect_t *  r,
teken_char_t  c,
const teken_attr_t *  a 
)
static

Definition at line 650 of file subr_terminal.c.

References TCHAR_CREATE.

◆ termteken_param()

static void termteken_param ( void *  softc,
int  cmd,
unsigned int  arg 
)
static

Definition at line 683 of file subr_terminal.c.

◆ termteken_post_input()

static void termteken_post_input ( void *  softc)
static

Definition at line 675 of file subr_terminal.c.

◆ termteken_pre_input()

static void termteken_pre_input ( void *  softc)
static

Definition at line 667 of file subr_terminal.c.

◆ termteken_putchar()

static void termteken_putchar ( void *  softc,
const teken_pos_t *  p,
teken_char_t  c,
const teken_attr_t *  a 
)
static

Definition at line 641 of file subr_terminal.c.

References TCHAR_CREATE.

◆ termteken_respond()

static void termteken_respond ( void *  softc,
const void *  buf,
size_t  len 
)
static

Definition at line 691 of file subr_terminal.c.

References buf, ttydisc_rint_done(), and ttydisc_rint_simple().

Here is the call graph for this function:

◆ termtty_close()

static void termtty_close ( struct tty *  tp)
static

Definition at line 407 of file subr_terminal.c.

◆ termtty_ioctl()

static int termtty_ioctl ( struct tty *  tp,
u_long  cmd,
caddr_t  data,
struct thread *  td 
)
static

Definition at line 441 of file subr_terminal.c.

References data.

◆ termtty_mmap()

static int termtty_mmap ( struct tty *  tp,
vm_ooffset_t  offset,
vm_paddr_t *  paddr,
int  nprot,
vm_memattr_t *  memattr 
)
static

Definition at line 496 of file subr_terminal.c.

◆ termtty_open()

static int termtty_open ( struct tty *  tp)
static

Definition at line 398 of file subr_terminal.c.

◆ termtty_outwakeup()

static void termtty_outwakeup ( struct tty *  tp)
static

Definition at line 415 of file subr_terminal.c.

References flags, TERMINAL_LOCK_TTY, TERMINAL_UNLOCK_TTY, and ttydisc_getc().

Here is the call graph for this function:

Variable Documentation

◆ default_message

teken_attr_t default_message
static
Initial value:
= {
.ta_fgcolor = TCHAR_FGCOLOR(TERMINAL_NORM_ATTR),
.ta_bgcolor = TCHAR_BGCOLOR(TERMINAL_NORM_ATTR),
.ta_format = TCHAR_FORMAT(TERMINAL_NORM_ATTR)
}

Definition at line 132 of file subr_terminal.c.

Referenced by terminal_init(), and terminal_set_winsize().

◆ kernel_message

teken_attr_t kernel_message
static
Initial value:
= {
.ta_fgcolor = TCHAR_FGCOLOR(TERMINAL_KERN_ATTR),
.ta_bgcolor = TCHAR_BGCOLOR(TERMINAL_KERN_ATTR),
.ta_format = TCHAR_FORMAT(TERMINAL_KERN_ATTR)
}

Definition at line 126 of file subr_terminal.c.

Referenced by termcn_cnputc(), and terminal_init().

◆ termcn_cngetc

cn_getc_t termcn_cngetc
static

Definition at line 511 of file subr_terminal.c.

◆ termcn_cngrab

cn_grab_t termcn_cngrab
static

Definition at line 513 of file subr_terminal.c.

◆ termcn_cninit

cn_init_t termcn_cninit
static

Definition at line 509 of file subr_terminal.c.

◆ termcn_cnops

const struct consdev_ops termcn_cnops
Initial value:
= {
.cn_probe = termcn_cnprobe,
.cn_init = termcn_cninit,
.cn_term = termcn_cnterm,
.cn_getc = termcn_cngetc,
.cn_putc = termcn_cnputc,
.cn_grab = termcn_cngrab,
.cn_ungrab = termcn_cnungrab,
}
static cn_term_t termcn_cnterm
static cn_grab_t termcn_cngrab
static cn_init_t termcn_cninit
static cn_putc_t termcn_cnputc
static cn_probe_t termcn_cnprobe
static cn_ungrab_t termcn_cnungrab
static cn_getc_t termcn_cngetc

Definition at line 516 of file subr_terminal.c.

Referenced by termcn_cnregister().

◆ termcn_cnprobe

cn_probe_t termcn_cnprobe
static

Definition at line 508 of file subr_terminal.c.

◆ termcn_cnputc

cn_putc_t termcn_cnputc
static

Definition at line 512 of file subr_terminal.c.

◆ termcn_cnterm

cn_term_t termcn_cnterm
static

Definition at line 510 of file subr_terminal.c.

◆ termcn_cnungrab

cn_ungrab_t termcn_cnungrab
static

Definition at line 514 of file subr_terminal.c.

◆ terminal_drawmethods

teken_funcs_t terminal_drawmethods
static
Initial value:
= {
.tf_bell = termteken_bell,
.tf_cursor = termteken_cursor,
.tf_putchar = termteken_putchar,
.tf_fill = termteken_fill,
.tf_copy = termteken_copy,
.tf_pre_input = termteken_pre_input,
.tf_post_input = termteken_post_input,
.tf_param = termteken_param,
.tf_respond = termteken_respond,
}
static tf_post_input_t termteken_post_input
static tf_fill_t termteken_fill
static tf_respond_t termteken_respond
static tf_putchar_t termteken_putchar
static tf_bell_t termteken_bell
static tf_pre_input_t termteken_pre_input
static tf_copy_t termteken_copy
static tf_cursor_t termteken_cursor
static tf_param_t termteken_param

Definition at line 113 of file subr_terminal.c.

Referenced by terminal_init().

◆ terminal_tty_class

struct ttydevsw terminal_tty_class
static
Initial value:
= {
.tsw_open = termtty_open,
.tsw_close = termtty_close,
.tsw_outwakeup = termtty_outwakeup,
.tsw_ioctl = termtty_ioctl,
.tsw_mmap = termtty_mmap,
}
static tsw_close_t termtty_close
Definition: subr_terminal.c:86
static tsw_mmap_t termtty_mmap
Definition: subr_terminal.c:89
static tsw_open_t termtty_open
Definition: subr_terminal.c:85
static tsw_outwakeup_t termtty_outwakeup
Definition: subr_terminal.c:87
static tsw_ioctl_t termtty_ioctl
Definition: subr_terminal.c:88

Definition at line 91 of file subr_terminal.c.

Referenced by terminal_maketty().

◆ termteken_bell

tf_bell_t termteken_bell
static

Definition at line 103 of file subr_terminal.c.

◆ termteken_copy

tf_copy_t termteken_copy
static

Definition at line 107 of file subr_terminal.c.

◆ termteken_cursor

tf_cursor_t termteken_cursor
static

Definition at line 104 of file subr_terminal.c.

◆ termteken_fill

tf_fill_t termteken_fill
static

Definition at line 106 of file subr_terminal.c.

◆ termteken_param

tf_param_t termteken_param
static

Definition at line 110 of file subr_terminal.c.

◆ termteken_post_input

tf_post_input_t termteken_post_input
static

Definition at line 109 of file subr_terminal.c.

◆ termteken_pre_input

tf_pre_input_t termteken_pre_input
static

Definition at line 108 of file subr_terminal.c.

◆ termteken_putchar

tf_putchar_t termteken_putchar
static

Definition at line 105 of file subr_terminal.c.

◆ termteken_respond

tf_respond_t termteken_respond
static

Definition at line 111 of file subr_terminal.c.

◆ termtty_close

tsw_close_t termtty_close
static

Definition at line 86 of file subr_terminal.c.

◆ termtty_ioctl

tsw_ioctl_t termtty_ioctl
static

Definition at line 88 of file subr_terminal.c.

◆ termtty_mmap

tsw_mmap_t termtty_mmap
static

Definition at line 89 of file subr_terminal.c.

◆ termtty_open

tsw_open_t termtty_open
static

Definition at line 85 of file subr_terminal.c.

◆ termtty_outwakeup

tsw_outwakeup_t termtty_outwakeup
static

Definition at line 87 of file subr_terminal.c.