Print this page
NEX-16819 loader UEFI support
Includes work by Toomas Soome <tsoome@me.com>
Upstream commits:
    loader: pxe receive cleanup
    9475 libefi: Do not return only if ReceiveFilter
    installboot: should support efi system partition
    8931 boot1.efi: scan all display modes rather than
    loader: spinconsole updates
    loader: gfx experiment to try GOP Blt() function.
    sha1 build test
    loader: add sha1 hash calculation
    common/sha1: update for loader build
    loader: biosdisk rework
    uts: 32-bit kernel FB needs mapping in low memory
    uts: add diag-device
    uts: boot console mirror with diag-device
    uts: enable very early console on ttya
    kmdb: add diag-device as input/output device
    uts: test VGA memory exclusion from mapping
    uts: clear boot mapping and protect boot pages test
    uts: add dboot map debug printf
    uts: need to release FB pages in release_bootstrap()
    uts: add screenmap ioctl
    uts: update sys/queue.h
    loader: add illumos uts/common to include path
    loader: tem/gfx font cleanup
    loader: vbe checks
    uts: gfx_private set KD_TEXT when KD_RESETTEXT is
    uts: gfx 8-bit update
    loader: gfx 8-bit fix
    loader: always set media size from partition.
    uts: MB2 support for 32-bit kernel
    loader: x86 should have tem 80x25
    uts: x86 should have tem 80x25
    uts: font update
    loader: font update
    uts: tem attributes
    loader: tem.c comment added
    uts: use font module
    loader: add font module
    loader: build rules for new font setup
    uts: gfx_private update for new font structure
    uts: early boot update for new font structure
    uts: font update
    uts: font build rules update for new fonts
    uts: tem update to new font structure
    loader: module.c needs to include tem_impl.h
    uts: gfx_private 8x16 font rework
    uts: make font_lookup public
    loader: font rework
    uts: font rework
    9259 libefi: efi_alloc_and_read should check for PMBR
    uts: tem utf-8 support
    loader: implement tem utf-8 support
    loader: tem should be able to display UTF-8
    7784 uts: console input should support utf-8
    7796 uts: ldterm default to utf-8
    uts: do not reset serial console
    uts: set up colors even if tem is not console
    uts: add type for early boot properties
    uts: gfx_private experiment with drm and vga
    uts: gfx_private should use setmode drm callback.
    uts: identify FB types and set up gfx_private based
    loader: replace gop and vesa with framebuffer
    uts: boot needs simple tem to support mdb
    uts: boot_keyboard should emit esc sequences for
    uts: gfx_private FB showuld be written by line
    kmdb: set terminal window size
    uts: gfx_private needs to keep track of early boot FB
    pnglite: move pnglite to usr/src/common
    loader: gfx_fb
    ficl-sys: add gfx primitives
    loader: add illumos.png logo
    ficl: add fb-putimage
    loader: add png support
    loader: add alpha blending for gfx_fb
    loader: use term-drawrect for menu frame
    ficl: add simple gfx words
    uts: provide fb_info via fbgattr dev_specific array.
    uts: gfx_private add alpha blending
    uts: update sys/ascii.h
    uts: tem OSC support (incomplete)
    uts: implement env module support and use data from
    uts: tem get colors from early boot data
    loader: use crc32 from libstand (libz)
    loader: optimize for size
    loader: pass tem info to the environment
    loader: import tem for loader console
    loader: UEFI loader needs to set ISADIR based on
    loader: need UEFI32 support
    8918 loader.efi: add vesa edid support
    uts: tem_safe_pix_clear_prom_output() should only
    uts: tem_safe_pix_clear_entire_screen() should use
    uts: tem_safe_check_first_time() should query cursor
    uts: tem implement cls callback & visual_io v4
    uts: gfx_vgatext use block cursor for vgatext
    uts: gfx_private implement cls callback & visual_io
    uts: gfx_private bitmap framebuffer implementation
    uts: early start frame buffer console support
    uts: font functions should check the input char
    uts: font rendering should support 16/24/32bit depths
    uts: use smallest font as fallback default.
    uts: update terminal dimensions based on selected
    7834 uts: vgatext should use gfx_private
    uts: add spacing property to 8859-1.bdf
    terminfo: add underline for sun-color
    terminfo: sun-color has 16 colors
    uts: add font load callback type
    loader: do not repeat int13 calls with error 0x20 and
    8905 loader: add skein/edonr support
    8904 common/crypto: make skein and edonr loader
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Revert "NEX-16819 loader UEFI support"
This reverts commit ec06b9fc617b99234e538bf2e7e4d02a24993e0c.
Reverting due to failures in the zfs-tests and the sharefs-tests
NEX-16819 loader UEFI support
Includes work by Toomas Soome <tsoome@me.com>
Upstream commits:
    loader: pxe receive cleanup
    9475 libefi: Do not return only if ReceiveFilter
    installboot: should support efi system partition
    8931 boot1.efi: scan all display modes rather than
    loader: spinconsole updates
    loader: gfx experiment to try GOP Blt() function.
    sha1 build test
    loader: add sha1 hash calculation
    common/sha1: update for loader build
    loader: biosdisk rework
    uts: 32-bit kernel FB needs mapping in low memory
    uts: add diag-device
    uts: boot console mirror with diag-device
    uts: enable very early console on ttya
    kmdb: add diag-device as input/output device
    uts: test VGA memory exclusion from mapping
    uts: clear boot mapping and protect boot pages test
    uts: add dboot map debug printf
    uts: need to release FB pages in release_bootstrap()
    uts: add screenmap ioctl
    uts: update sys/queue.h
    loader: add illumos uts/common to include path
    loader: tem/gfx font cleanup
    loader: vbe checks
    uts: gfx_private set KD_TEXT when KD_RESETTEXT is
    uts: gfx 8-bit update
    loader: gfx 8-bit fix
    loader: always set media size from partition.
    uts: MB2 support for 32-bit kernel
    loader: x86 should have tem 80x25
    uts: x86 should have tem 80x25
    uts: font update
    loader: font update
    uts: tem attributes
    loader: tem.c comment added
    uts: use font module
    loader: add font module
    loader: build rules for new font setup
    uts: gfx_private update for new font structure
    uts: early boot update for new font structure
    uts: font update
    uts: font build rules update for new fonts
    uts: tem update to new font structure
    loader: module.c needs to include tem_impl.h
    uts: gfx_private 8x16 font rework
    uts: make font_lookup public
    loader: font rework
    uts: font rework
    libefi: efi_alloc_and_read should check for PMBR
    uts: tem utf-8 support
    loader: implement tem utf-8 support
    loader: tem should be able to display UTF-8
    7784 uts: console input should support utf-8
    7796 uts: ldterm default to utf-8
    uts: do not reset serial console
    uts: set up colors even if tem is not console
    uts: add type for early boot properties
    uts: gfx_private experiment with drm and vga
    uts: gfx_private should use setmode drm callback.
    uts: identify FB types and set up gfx_private based
    loader: replace gop and vesa with framebuffer
    uts: boot needs simple tem to support mdb
    uts: boot_keyboard should emit esc sequences for
    uts: gfx_private FB showuld be written by line
    kmdb: set terminal window size
    uts: gfx_private needs to keep track of early boot FB
    pnglite: move pnglite to usr/src/common
    loader: gfx_fb
    ficl-sys: add gfx primitives
    loader: add illumos.png logo
    ficl: add fb-putimage
    loader: add png support
    loader: add alpha blending for gfx_fb
    loader: use term-drawrect for menu frame
    ficl: add simple gfx words
    uts: provide fb_info via fbgattr dev_specific array.
    uts: gfx_private add alpha blending
    uts: update sys/ascii.h
    uts: tem OSC support (incomplete)
    uts: implement env module support and use data from
    uts: tem get colors from early boot data
    loader: use crc32 from libstand (libz)
    loader: optimize for size
    loader: pass tem info to the environment
    loader: import tem for loader console
    loader: UEFI loader needs to set ISADIR based on
    loader: need UEFI32 support
    8918 loader.efi: add vesa edid support
    uts: tem_safe_pix_clear_prom_output() should only
    uts: tem_safe_pix_clear_entire_screen() should use
    uts: tem_safe_check_first_time() should query cursor
    uts: tem implement cls callback & visual_io v4
    uts: gfx_vgatext use block cursor for vgatext
    uts: gfx_private implement cls callback & visual_io
    uts: gfx_private bitmap framebuffer implementation
    uts: early start frame buffer console support
    uts: font functions should check the input char
    uts: font rendering should support 16/24/32bit depths
    uts: use smallest font as fallback default.
    uts: update terminal dimensions based on selected
    7834 uts: vgatext should use gfx_private
    uts: add spacing property to 8859-1.bdf
    terminfo: add underline for sun-color
    terminfo: sun-color has 16 colors
    uts: add font load callback type
    loader: do not repeat int13 calls with error 0x20 and
    8905 loader: add skein/edonr support
    8904 common/crypto: make skein and edonr loader
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>


  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*      Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
  28 
  29 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T       */
  30 /*        All Rights Reserved   */
  31 
  32 #ifndef _SYS_TEM_IMPL_H
  33 #define _SYS_TEM_IMPL_H
  34 
  35 #ifdef __cplusplus
  36 extern "C" {
  37 #endif
  38 
  39 #include <sys/types.h>


  40 #include <sys/sunddi.h>
  41 #include <sys/sunldi.h>
  42 #include <sys/visual_io.h>
  43 #include <sys/font.h>
  44 #include <sys/list.h>
  45 #include <sys/tem.h>
  46 #include <sys/note.h>

  47 
  48 /*
  49  * definitions for ANSI x3.64 terminal control language parser


















  50  */
  51 






  52 #define TEM_MAXPARAMS   5       /* maximum number of ANSI paramters */
  53 #define TEM_MAXTAB      40      /* maximum number of tab stops */
  54 #define TEM_MAXFKEY     30      /* max length of function key with <ESC>Q */
  55 #define MAX_TEM         2       /* max number of loadable terminal emulators */
  56 
  57 #define TEM_SCROLL_UP           0
  58 #define TEM_SCROLL_DOWN         1
  59 #define TEM_SHIFT_LEFT          0
  60 #define TEM_SHIFT_RIGHT         1
  61 

  62 #define TEM_ATTR_NORMAL         0x0000
  63 #define TEM_ATTR_REVERSE        0x0001
  64 #define TEM_ATTR_BOLD           0x0002
  65 #define TEM_ATTR_BLINK          0x0004
  66 #define TEM_ATTR_TRANSPARENT    0x0008
  67 #define TEM_ATTR_SCREEN_REVERSE 0x0010
  68 #define TEM_ATTR_BRIGHT_FG      0x0020
  69 #define TEM_ATTR_BRIGHT_BG      0x0040

  70 
  71 #define ANSI_COLOR_BLACK        0






  72 #define ANSI_COLOR_WHITE        7
  73 
  74 #define TEM_TEXT_WHITE          0
  75 #define TEM_TEXT_BLACK          1
  76 #define TEM_TEXT_BLACK24_RED    0x00
  77 #define TEM_TEXT_BLACK24_GREEN  0x00
  78 #define TEM_TEXT_BLACK24_BLUE   0x00
  79 #define TEM_TEXT_WHITE24_RED    0xff
  80 #define TEM_TEXT_WHITE24_GREEN  0xff
  81 #define TEM_TEXT_WHITE24_BLUE   0xff
  82 
  83 #define A_STATE_START                   0
  84 #define A_STATE_ESC                     1
  85 #define A_STATE_CSI                     2
  86 #define A_STATE_CSI_QMARK               3
  87 #define A_STATE_CSI_EQUAL               4

  88 
  89 /*
  90  * Default number of rows and columns
  91  */

  92 #define TEM_DEFAULT_ROWS        34
  93 #define TEM_DEFAULT_COLS        80




  94 
  95 /*
  96  * Default foreground/background color
  97  */
  98 
  99 #ifdef _HAVE_TEM_FIRMWARE
 100 #define DEFAULT_ANSI_FOREGROUND ANSI_COLOR_BLACK
 101 #define DEFAULT_ANSI_BACKGROUND ANSI_COLOR_WHITE
 102 #else /* _HAVE_TEM_FIRMWARE */
 103 #define DEFAULT_ANSI_FOREGROUND ANSI_COLOR_WHITE
 104 #define DEFAULT_ANSI_BACKGROUND ANSI_COLOR_BLACK
 105 #endif
 106 


 107 
 108 #define BUF_LEN         160 /* Two lines of data can be processed at a time */




 109 
 110 typedef uint32_t tem_char_t;    /* 32bit char to support UTF-8 */
 111 typedef uint8_t text_color_t;



 112 

 113 typedef struct tem_color {
 114         text_color_t    fg_color;
 115         text_color_t    bg_color;
 116         unsigned short  a_flags;
 117 } tem_color_t;
 118 
 119 enum called_from { CALLED_FROM_NORMAL, CALLED_FROM_STANDALONE };
 120 
 121 struct tem_pix_pos {
 122         screen_pos_t    x;
 123         screen_pos_t    y;
 124 };
 125 
 126 struct tem_char_pos {
 127         screen_pos_t    col;
 128         screen_pos_t    row;
 129 };
 130 
 131 struct tem_size {
 132         screen_size_t   width;
 133         screen_size_t   height;
 134 };
 135 
 136 typedef struct {
 137         uint8_t red[16];
 138         uint8_t green[16];
 139         uint8_t blue[16];
 140 } text_cmap_t;

 141 
 142 extern text_cmap_t cmap4_to_24;
 143 
 144 /*
 145  * State structure for each virtual terminal emulator
 146  */
 147 struct tem_vt_state {
 148         kmutex_t        tvs_lock;
 149         uchar_t         tvs_fbmode;     /* framebuffer mode */
 150         unsigned short  tvs_flags;      /* flags for this x3.64 terminal */
 151         int             tvs_state;      /* state in output esc seq processing */
 152         boolean_t       tvs_gotparam;   /* does output esc seq have a param */
 153 
 154         int     tvs_curparam;   /* current param # of output esc seq */
 155         int     tvs_paramval;   /* value of current param */
 156         int     tvs_params[TEM_MAXPARAMS];  /* parameters of output esc seq */
 157         screen_pos_t    tvs_tabs[TEM_MAXTAB];   /* tab stops */
 158         int     tvs_ntabs;              /* number of tabs used */
 159         int     tvs_nscroll;            /* number of lines to scroll */
 160 
 161         struct tem_char_pos tvs_s_cursor;       /* start cursor position */
 162         struct tem_char_pos tvs_c_cursor;       /* current cursor position */
 163         struct tem_char_pos tvs_r_cursor;       /* remembered cursor position */
 164 
 165         unsigned char   *tvs_outbuf;    /* place to keep incomplete lines */
 166         int             tvs_outbuf_size;
 167         int             tvs_outindex;   /* index into a_outbuf */
 168         void            *tvs_pix_data;  /* pointer to tmp bitmap area */
 169         int             tvs_pix_data_size;
 170         text_color_t    tvs_fg_color;
 171         text_color_t    tvs_bg_color;
 172         int             tvs_first_line; /* kernel console output begins */
 173 
 174         unsigned char   *tvs_screen_buf;        /* whole screen buffer */
 175         int             tvs_screen_buf_size;
 176         text_color_t    *tvs_fg_buf;    /* fg_color attribute cache */
 177         text_color_t    *tvs_bg_buf;    /* bg_color attribute cache */
 178         int             tvs_color_buf_size;
 179 
 180         unsigned        tvs_utf8_left;          /* UTF-8 code points */
 181         tem_char_t      tvs_utf8_partial;       /* UTF-8 char being completed */
 182 
 183         boolean_t       tvs_isactive;
 184         int             tvs_initialized;        /* initialization flag */
 185 
 186         list_node_t     tvs_list_node;
 187 };
 188 _NOTE(MUTEX_PROTECTS_DATA(tem_vt_state::tvs_lock, tem_vt_state))
 189 
 190 typedef struct tem_safe_callbacks {
 191         void (*tsc_display)(struct tem_vt_state *, unsigned char *, int,
 192             screen_pos_t, screen_pos_t, unsigned char, unsigned char,
 193             cred_t *, enum called_from);
 194         void (*tsc_copy)(struct tem_vt_state *,
 195             screen_pos_t, screen_pos_t, screen_pos_t, screen_pos_t,
 196             screen_pos_t, screen_pos_t, cred_t *, enum called_from);
 197         void (*tsc_cursor)(struct tem_vt_state *, short, cred_t *,
 198             enum called_from);
 199         void (*tsc_bit2pix)(struct tem_vt_state *, unsigned char,
 200             unsigned char, unsigned char);
 201         void (*tsc_cls)(struct tem_vt_state *, int,
 202             screen_pos_t, screen_pos_t, cred_t *, enum called_from);
 203 } tem_safe_callbacks_t;
 204 
 205 /*
 206  * common term soft state structure shared by all virtual terminal emulators
 207  */
 208 typedef struct tem_state {
 209         ldi_handle_t    ts_hdl; /* Framework handle for layered on dev */
 210         screen_size_t   ts_linebytes;   /* Layered on bytes per scan line */
 211 
 212         int     ts_display_mode;        /* What mode we are in */
 213         struct  vis_polledio    *ts_fb_polledio;
 214 
 215         struct tem_size ts_c_dimension; /* window dimensions in characters */
 216         struct tem_size ts_p_dimension; /* screen dimensions in pixels */
 217         struct tem_pix_pos ts_p_offset; /* pix offset to center the display */
 218 
 219         int     ts_pix_data_size;       /* size of bitmap data areas */
 220         int     ts_pdepth;              /* pixel depth */
 221         struct font     ts_font;        /* font table */
 222 
 223         unsigned char   *ts_blank_line; /* a blank line for scrolling */
 224         tem_safe_callbacks_t    *ts_callbacks;  /* internal output functions */
 225 
 226         int     ts_initialized;         /* initialization flag */
 227 
 228         tem_modechg_cb_t        ts_modechg_cb;
 229         tem_modechg_cb_arg_t    ts_modechg_arg;
 230 


 231         tem_color_t     ts_init_color; /* initial color and attributes */
 232 
 233         struct tem_vt_state     *ts_active;
 234         kmutex_t        ts_lock;
 235         list_t          ts_list;        /* chain of all tems */
 236 } tem_state_t;
 237 
 238 extern tem_state_t tems;
 239 extern tem_safe_callbacks_t tem_safe_text_callbacks;
 240 extern tem_safe_callbacks_t tem_safe_pix_callbacks;
 241 
 242 
 243 /*
 244  * tems_* fuctions mean that they just operate on the common soft state
 245  * (tem_state_t), and tem_* functions mean that they operate on the
 246  * per-tem structure (tem_vt_state). All "safe" interfaces are in tem_safe.c.
 247  */

 248 void    tems_display_layered(struct vis_consdisplay *, cred_t *);
 249 void    tems_copy_layered(struct vis_conscopy *, cred_t *);
 250 void    tems_cursor_layered(struct vis_conscursor *, cred_t *);
 251 void    tems_safe_copy(struct vis_conscopy *, cred_t *, enum called_from);
 252 
 253 void    tem_pix_align(struct tem_vt_state *, cred_t *, enum called_from);
 254 void    tem_safe_check_first_time(struct tem_vt_state *tem, cred_t *,
 255             enum called_from);
 256 void    tem_safe_reset_display(struct tem_vt_state *, cred_t *,
 257             enum called_from, boolean_t, boolean_t);
 258 void    tem_safe_terminal_emulate(struct tem_vt_state *, uchar_t *, int,
 259             cred_t *, enum called_from);
 260 void    tem_safe_text_display(struct tem_vt_state *, uchar_t *,
 261             int, screen_pos_t, screen_pos_t,
 262             text_color_t, text_color_t,
 263             cred_t *, enum called_from);
 264 void    tem_safe_text_copy(struct tem_vt_state *,
 265             screen_pos_t, screen_pos_t,
 266             screen_pos_t, screen_pos_t,
 267             screen_pos_t, screen_pos_t,
 268             cred_t *, enum called_from);
 269 void    tem_safe_text_cursor(struct tem_vt_state *, short, cred_t *,
 270             enum called_from);
 271 void    tem_safe_text_cls(struct tem_vt_state *,
 272             int count, screen_pos_t row, screen_pos_t col,
 273             cred_t *credp, enum called_from called_from);
 274 void    tem_safe_pix_display(struct tem_vt_state *, uchar_t *,
 275             int, screen_pos_t, screen_pos_t,
 276             text_color_t, text_color_t,
 277             cred_t *, enum called_from);
 278 void    tem_safe_pix_copy(struct tem_vt_state *,
 279             screen_pos_t, screen_pos_t,
 280             screen_pos_t, screen_pos_t,
 281             screen_pos_t, screen_pos_t,
 282             cred_t *, enum called_from);
 283 void    tem_safe_pix_cursor(struct tem_vt_state *, short, cred_t *,
 284             enum called_from);
 285 void    tem_safe_pix_bit2pix(struct tem_vt_state *, unsigned char,
 286             unsigned char, unsigned char);
 287 void    tem_safe_pix_cls(struct tem_vt_state *, int, screen_pos_t, screen_pos_t,
 288             cred_t *, enum called_from);
 289 void    tem_safe_pix_cls_range(struct tem_vt_state *,
 290             screen_pos_t, int, int,
 291             screen_pos_t, int, int,
 292             boolean_t, cred_t *, enum called_from);
 293 
 294 void    tem_safe_pix_clear_entire_screen(struct tem_vt_state *,
 295             cred_t *, enum called_from);
 296 
 297 void    tem_safe_get_color(struct tem_vt_state *, text_color_t *,
 298             text_color_t *, uint8_t);
 299 
 300 void    tem_safe_blank_screen(struct tem_vt_state *, cred_t *,
 301             enum called_from);
 302 void    tem_safe_unblank_screen(struct tem_vt_state *, cred_t *,
 303             enum called_from);

 304 
 305 #ifdef __cplusplus
 306 }
 307 #endif
 308 
 309 #endif /* _SYS_TEM_IMPL_H */


  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*      Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
  28 
  29 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T       */
  30 /*        All Rights Reserved   */
  31 
  32 #ifndef _SYS_TEM_IMPL_H
  33 #define _SYS_TEM_IMPL_H
  34 
  35 #ifdef __cplusplus
  36 extern "C" {
  37 #endif
  38 
  39 #include <sys/types.h>
  40 #include <sys/font.h>
  41 #if !defined(_BOOT)
  42 #include <sys/sunddi.h>
  43 #include <sys/sunldi.h>
  44 #include <sys/visual_io.h>

  45 #include <sys/list.h>
  46 #include <sys/tem.h>
  47 #include <sys/note.h>
  48 #endif
  49 
  50 /*
  51  * Definitions for ANSI x3.64 terminal control language parser.
  52  * With UTF-8 support we use 32-bit value for Unicode codepoints.
  53  *
  54  * However, as we only need 21 bits for unicode char, we will use the
  55  * rest of the bits for attributes, so we can save memory and
  56  * have combined attribute+char in screen buffer. This will also allow us
  57  * to keep better track about attributes and apply other optimizations.
  58  *
  59  * This setup will give us 11 bits for attributes (mask 0x7FF).
  60  *  Bits  Meaning
  61  *  0-20  char
  62  * 21-31  attributes
  63  *
  64  * The current implementation is building the screen buffer in three parts,
  65  * tvs_screen_buf is implementing the character array and the foreground
  66  * and the background colors have tvs_fg_color and tvs_bg_color arrays.
  67  * The character and color arrays are currently only used to restore the
  68  * screen from tem switch (vt switch, or switch from Xorg session.
  69  * To implement the console history, this buffering needs to be reviewed.
  70  */
  71 
  72 typedef uint32_t tem_char_t;    /* 32bit char to support UTF-8 */
  73 #define TEM_ATTR_MASK           0x7FF
  74 #define TEM_CHAR(c)             ((c) & 0x1fffff)
  75 #define TEM_CHAR_ATTR(c)        (((c) >> 21) & TEM_ATTR_MASK)
  76 #define TEM_ATTR(c)             (((c) & TEM_ATTR_MASK) << 21)
  77 
  78 #define TEM_MAXPARAMS   5       /* maximum number of ANSI paramters */
  79 #define TEM_MAXTAB      40      /* maximum number of tab stops */
  80 #define TEM_MAXFKEY     30      /* max length of function key with <ESC>Q */

  81 
  82 #define TEM_SCROLL_UP           0
  83 #define TEM_SCROLL_DOWN         1
  84 #define TEM_SHIFT_LEFT          0
  85 #define TEM_SHIFT_RIGHT         1
  86 
  87 /* Attributes 0-0x7ff */
  88 #define TEM_ATTR_NORMAL         0x0000
  89 #define TEM_ATTR_REVERSE        0x0001
  90 #define TEM_ATTR_BOLD           0x0002
  91 #define TEM_ATTR_BLINK          0x0004
  92 #define TEM_ATTR_UNDERLINE      0x0008
  93 #define TEM_ATTR_SCREEN_REVERSE 0x0010
  94 #define TEM_ATTR_BRIGHT_FG      0x0020
  95 #define TEM_ATTR_BRIGHT_BG      0x0040
  96 #define TEM_ATTR_TRANSPARENT    0x0080
  97 
  98 #define ANSI_COLOR_BLACK        0
  99 #define ANSI_COLOR_RED          1
 100 #define ANSI_COLOR_GREEN        2
 101 #define ANSI_COLOR_BROWN        3
 102 #define ANSI_COLOR_BLUE         4
 103 #define ANSI_COLOR_MAGENTA      5
 104 #define ANSI_COLOR_CYAN         6
 105 #define ANSI_COLOR_WHITE        7
 106 
 107 #define TEM_TEXT_WHITE          0
 108 #define TEM_TEXT_BLACK          1
 109 #define TEM_TEXT_BLACK24_RED    0x00
 110 #define TEM_TEXT_BLACK24_GREEN  0x00
 111 #define TEM_TEXT_BLACK24_BLUE   0x00
 112 #define TEM_TEXT_WHITE24_RED    0xff
 113 #define TEM_TEXT_WHITE24_GREEN  0xff
 114 #define TEM_TEXT_WHITE24_BLUE   0xff
 115 
 116 #define A_STATE_START                   0
 117 #define A_STATE_ESC                     1
 118 #define A_STATE_CSI                     2
 119 #define A_STATE_CSI_QMARK               3
 120 #define A_STATE_CSI_EQUAL               4
 121 #define A_STATE_OSC                     5
 122 
 123 /*
 124  * Default number of rows and columns
 125  */
 126 #ifdef _HAVE_TEM_FIRMWARE
 127 #define TEM_DEFAULT_ROWS        34
 128 #define TEM_DEFAULT_COLS        80
 129 #else
 130 #define TEM_DEFAULT_ROWS        25
 131 #define TEM_DEFAULT_COLS        80
 132 #endif
 133 
 134 /*
 135  * Default foreground/background color
 136  */
 137 

 138 #define DEFAULT_ANSI_FOREGROUND ANSI_COLOR_BLACK
 139 #define DEFAULT_ANSI_BACKGROUND ANSI_COLOR_WHITE




 140 
 141 typedef uint8_t text_color_t;
 142 typedef uint16_t text_attr_t;
 143 
 144 typedef struct {
 145         uint8_t red[16];
 146         uint8_t green[16];
 147         uint8_t blue[16];
 148 } text_cmap_t;
 149 
 150 /* Color translation tables. */
 151 extern const uint8_t dim_xlate[8];
 152 extern const uint8_t brt_xlate[8];
 153 extern const uint8_t solaris_color_to_pc_color[16];
 154 extern const text_cmap_t cmap4_to_24;
 155 
 156 #if !defined(_BOOT)
 157 typedef struct tem_color {
 158         text_color_t    fg_color;
 159         text_color_t    bg_color;
 160         text_attr_t     a_flags;
 161 } tem_color_t;
 162 
 163 enum called_from { CALLED_FROM_NORMAL, CALLED_FROM_STANDALONE };
 164 
 165 struct tem_pix_pos {
 166         screen_pos_t    x;
 167         screen_pos_t    y;
 168 };
 169 
 170 struct tem_char_pos {
 171         screen_pos_t    col;
 172         screen_pos_t    row;
 173 };
 174 
 175 struct tem_size {
 176         screen_size_t   width;
 177         screen_size_t   height;
 178 };
 179 
 180 /* Combined color and 32bit tem char */
 181 typedef struct term_char {
 182         text_color_t    tc_fg_color;
 183         text_color_t    tc_bg_color;
 184         tem_char_t      tc_char;
 185 } term_char_t;
 186 


 187 /*
 188  * State structure for each virtual terminal emulator
 189  */
 190 struct tem_vt_state {
 191         kmutex_t        tvs_lock;
 192         uchar_t         tvs_fbmode;     /* framebuffer mode */
 193         text_attr_t     tvs_flags;      /* flags for this x3.64 terminal */
 194         int             tvs_state;      /* state in output esc seq processing */
 195         boolean_t       tvs_gotparam;   /* does output esc seq have a param */
 196 
 197         int     tvs_curparam;   /* current param # of output esc seq */
 198         int     tvs_paramval;   /* value of current param */
 199         int     tvs_params[TEM_MAXPARAMS];  /* parameters of output esc seq */
 200         screen_pos_t    tvs_tabs[TEM_MAXTAB];   /* tab stops */
 201         int     tvs_ntabs;              /* number of tabs used */
 202         int     tvs_nscroll;            /* number of lines to scroll */
 203 
 204         struct tem_char_pos tvs_s_cursor;       /* start cursor position */
 205         struct tem_char_pos tvs_c_cursor;       /* current cursor position */
 206         struct tem_char_pos tvs_r_cursor;       /* remembered cursor position */
 207 
 208         term_char_t     *tvs_outbuf;    /* place to keep incomplete lines */
 209         size_t          tvs_outbuf_size;
 210         size_t          tvs_outindex;   /* index into a_outbuf */
 211         void            *tvs_pix_data;  /* pointer to tmp bitmap area */
 212         size_t          tvs_pix_data_size;
 213         text_color_t    tvs_fg_color;
 214         text_color_t    tvs_bg_color;
 215         int             tvs_first_line; /* kernel console output begins */
 216 
 217         term_char_t     *tvs_screen_buf;        /* whole screen buffer */
 218         term_char_t     **tvs_screen_rows;      /* screen buffer rows */
 219         size_t          tvs_screen_buf_size;
 220         size_t          tvs_screen_history_size;

 221 
 222         unsigned        tvs_utf8_left;          /* UTF-8 code points */
 223         tem_char_t      tvs_utf8_partial;       /* UTF-8 char being completed */
 224 
 225         boolean_t       tvs_isactive;
 226         boolean_t       tvs_initialized;        /* initialization flag */
 227 
 228         list_node_t     tvs_list_node;
 229 };
 230 _NOTE(MUTEX_PROTECTS_DATA(tem_vt_state::tvs_lock, tem_vt_state))
 231 
 232 typedef struct tem_safe_callbacks {
 233         void (*tsc_display)(struct tem_vt_state *, term_char_t *, int,
 234             screen_pos_t, screen_pos_t, cred_t *, enum called_from);

 235         void (*tsc_copy)(struct tem_vt_state *,
 236             screen_pos_t, screen_pos_t, screen_pos_t, screen_pos_t,
 237             screen_pos_t, screen_pos_t, cred_t *, enum called_from);
 238         void (*tsc_cursor)(struct tem_vt_state *, short, cred_t *,
 239             enum called_from);
 240         void (*tsc_bit2pix)(struct tem_vt_state *, term_char_t);

 241         void (*tsc_cls)(struct tem_vt_state *, int,
 242             screen_pos_t, screen_pos_t, cred_t *, enum called_from);
 243 } tem_safe_callbacks_t;
 244 
 245 /*
 246  * common term soft state structure shared by all virtual terminal emulators
 247  */
 248 typedef struct tem_state {
 249         ldi_handle_t    ts_hdl; /* Framework handle for layered on dev */
 250         screen_size_t   ts_linebytes;   /* Layered on bytes per scan line */
 251 
 252         int     ts_display_mode;        /* What mode we are in */
 253         struct  vis_polledio    *ts_fb_polledio;
 254 
 255         struct tem_size ts_c_dimension; /* window dimensions in characters */
 256         struct tem_size ts_p_dimension; /* screen dimensions in pixels */
 257         struct tem_pix_pos ts_p_offset; /* pix offset to center the display */
 258 
 259         int     ts_pix_data_size;       /* size of bitmap data areas */
 260         int     ts_pdepth;              /* pixel depth */
 261         struct font     ts_font;        /* font table */
 262 
 263         term_char_t     *ts_blank_line; /* a blank line for scrolling */
 264         tem_safe_callbacks_t    *ts_callbacks;  /* internal output functions */
 265 
 266         int     ts_initialized;         /* initialization flag */
 267 
 268         tem_modechg_cb_t        ts_modechg_cb;
 269         tem_modechg_cb_arg_t    ts_modechg_arg;
 270 
 271         color_map_fn_t  ts_color_map;
 272 
 273         tem_color_t     ts_init_color; /* initial color and attributes */
 274 
 275         struct tem_vt_state     *ts_active;
 276         kmutex_t        ts_lock;
 277         list_t          ts_list;        /* chain of all tems */
 278 } tem_state_t;
 279 
 280 extern tem_state_t tems;
 281 extern tem_safe_callbacks_t tem_safe_text_callbacks;
 282 extern tem_safe_callbacks_t tem_safe_pix_callbacks;
 283 
 284 
 285 /*
 286  * tems_* fuctions mean that they just operate on the common soft state
 287  * (tem_state_t), and tem_* functions mean that they operate on the
 288  * per-tem structure (tem_vt_state). All "safe" interfaces are in tem_safe.c.
 289  */
 290 int     tems_cls_layered(struct vis_consclear *, cred_t *);
 291 void    tems_display_layered(struct vis_consdisplay *, cred_t *);
 292 void    tems_copy_layered(struct vis_conscopy *, cred_t *);
 293 void    tems_cursor_layered(struct vis_conscursor *, cred_t *);
 294 void    tems_safe_copy(struct vis_conscopy *, cred_t *, enum called_from);
 295 
 296 void    tem_pix_align(struct tem_vt_state *, cred_t *, enum called_from);
 297 void    tem_safe_check_first_time(struct tem_vt_state *tem, cred_t *,
 298             enum called_from);
 299 void    tem_safe_reset_display(struct tem_vt_state *, cred_t *,
 300             enum called_from, boolean_t, boolean_t);
 301 void    tem_safe_terminal_emulate(struct tem_vt_state *, uchar_t *, int,
 302             cred_t *, enum called_from);
 303 void    tem_safe_text_display(struct tem_vt_state *, term_char_t *,
 304             int, screen_pos_t, screen_pos_t, cred_t *, enum called_from);


 305 void    tem_safe_text_copy(struct tem_vt_state *,
 306             screen_pos_t, screen_pos_t,
 307             screen_pos_t, screen_pos_t,
 308             screen_pos_t, screen_pos_t,
 309             cred_t *, enum called_from);
 310 void    tem_safe_text_cursor(struct tem_vt_state *, short, cred_t *,
 311             enum called_from);
 312 void    tem_safe_text_cls(struct tem_vt_state *,
 313             int count, screen_pos_t row, screen_pos_t col,
 314             cred_t *credp, enum called_from called_from);
 315 void    tem_safe_pix_display(struct tem_vt_state *, term_char_t *,
 316             int, screen_pos_t, screen_pos_t, cred_t *, enum called_from);


 317 void    tem_safe_pix_copy(struct tem_vt_state *,
 318             screen_pos_t, screen_pos_t,
 319             screen_pos_t, screen_pos_t,
 320             screen_pos_t, screen_pos_t,
 321             cred_t *, enum called_from);
 322 void    tem_safe_pix_cursor(struct tem_vt_state *, short, cred_t *,
 323             enum called_from);
 324 void    tem_safe_pix_bit2pix(struct tem_vt_state *, term_char_t);

 325 void    tem_safe_pix_cls(struct tem_vt_state *, int, screen_pos_t, screen_pos_t,
 326             cred_t *, enum called_from);
 327 void    tem_safe_pix_cls_range(struct tem_vt_state *,
 328             screen_pos_t, int, int,
 329             screen_pos_t, int, int,
 330             boolean_t, cred_t *, enum called_from);
 331 
 332 void    tem_safe_pix_clear_entire_screen(struct tem_vt_state *,
 333             cred_t *, enum called_from);
 334 
 335 void    tem_safe_get_attr(struct tem_vt_state *, text_color_t *,
 336             text_color_t *, text_attr_t *, uint8_t);
 337 
 338 void    tem_safe_blank_screen(struct tem_vt_state *, cred_t *,
 339             enum called_from);
 340 void    tem_safe_unblank_screen(struct tem_vt_state *, cred_t *,
 341             enum called_from);
 342 #endif  /* _BOOT */
 343 
 344 #ifdef __cplusplus
 345 }
 346 #endif
 347 
 348 #endif /* _SYS_TEM_IMPL_H */