syscons.h revision 51404
1/*- 2 * Copyright (c) 1995-1998 S�ren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer, 10 * without modification, immediately at the beginning of the file. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * $FreeBSD: head/sys/dev/syscons/syscons.h 51404 1999-09-19 08:58:53Z yokota $ 29 */ 30 31#ifndef _DEV_SYSCONS_SYSCONS_H_ 32#define _DEV_SYSCONS_SYSCONS_H_ 33 34/* machine-dependent part of the header */ 35 36#ifdef PC98 37#include <pc98/pc98/sc_machdep.h> 38#elif defined(__i386__) 39/* nothing for the moment */ 40#elif defined(__alpha__) 41/* nothing for the moment */ 42#endif 43 44/* default values for configuration options */ 45 46#ifndef MAXCONS 47#define MAXCONS 16 48#endif 49 50#ifdef SC_NO_SYSMOUSE 51#undef SC_NO_CUTPASTE 52#define SC_NO_CUTPASTE 1 53#endif 54 55#ifdef SC_NO_MODE_CHANGE 56#undef SC_PIXEL_MODE 57#endif 58 59#ifndef SC_DEBUG_LEVEL 60#define SC_DEBUG_LEVEL 0 61#endif 62 63#define DPRINTF(l, p) if (SC_DEBUG_LEVEL >= (l)) printf p 64 65#define SC_DRIVER_NAME "sc" 66#define SC_VTY(dev) minor(dev) 67#define SC_DEV(sc, vty) ((sc)->dev[(vty) - (sc)->first_vty]) 68#define SC_STAT(dev) ((scr_stat *)(dev)->si_drv1) 69 70/* printable chars */ 71#ifndef PRINTABLE 72#define PRINTABLE(ch) ((ch) > 0x1b || ((ch) > 0x0d && (ch) < 0x1b) \ 73 || (ch) < 0x07) 74#endif 75 76/* macros for "intelligent" screen update */ 77#define mark_for_update(scp, x) {\ 78 if ((x) < scp->start) scp->start = (x);\ 79 else if ((x) > scp->end) scp->end = (x);\ 80 } 81#define mark_all(scp) {\ 82 scp->start = 0;\ 83 scp->end = scp->xsize * scp->ysize - 1;\ 84 } 85 86/* vty status flags (scp->status) */ 87#define UNKNOWN_MODE 0x00010 88#define SWITCH_WAIT_REL 0x00080 89#define SWITCH_WAIT_ACQ 0x00100 90#define BUFFER_SAVED 0x00200 91#define CURSOR_ENABLED 0x00400 92#define MOUSE_MOVED 0x01000 93#define MOUSE_CUTTING 0x02000 94#define MOUSE_VISIBLE 0x04000 95#define GRAPHICS_MODE 0x08000 96#define PIXEL_MODE 0x10000 97#define SAVER_RUNNING 0x20000 98#define VR_CURSOR_BLINK 0x40000 99#define VR_CURSOR_ON 0x80000 100 101/* attribute flags */ 102#define NORMAL_ATTR 0x00 103#define BLINK_ATTR 0x01 104#define BOLD_ATTR 0x02 105#define UNDERLINE_ATTR 0x04 106#define REVERSE_ATTR 0x08 107#define FOREGROUND_CHANGED 0x10 108#define BACKGROUND_CHANGED 0x20 109 110/* misc defines */ 111#define FALSE 0 112#define TRUE 1 113#define MAX_ESC_PAR 5 114#define LOAD 1 115#define SAVE 0 116#define COL 80 117#define ROW 25 118#define CONSOLE_BUFSIZE 1024 119#define PCBURST 128 120#define FONT_NONE 1 121#define FONT_8 2 122#define FONT_14 4 123#define FONT_16 8 124 125#ifndef BELL_DURATION 126#define BELL_DURATION 5 127#define BELL_PITCH 800 128#endif 129 130/* special characters */ 131#define cntlc 0x03 132#define cntld 0x04 133#define bs 0x08 134#define lf 0x0a 135#define cr 0x0d 136#define del 0x7f 137 138#define DEAD_CHAR 0x07 /* char used for cursor */ 139 140/* virtual terminal buffer */ 141typedef struct sc_vtb { 142 int vtb_flags; 143#define VTB_VALID (1 << 0) 144 int vtb_type; 145#define VTB_INVALID 0 146#define VTB_MEMORY 1 147#define VTB_FRAMEBUFFER 2 148#define VTB_RINGBUFFER 3 149 int vtb_cols; 150 int vtb_rows; 151 int vtb_size; 152 vm_offset_t vtb_buffer; 153 int vtb_tail; /* valid for VTB_RINGBUFFER only */ 154} sc_vtb_t; 155 156/* terminal status */ 157typedef struct term_stat { 158 int esc; /* processing escape sequence */ 159 int num_param; /* # of parameters to ESC */ 160 int last_param; /* last parameter # */ 161 int param[MAX_ESC_PAR]; /* contains ESC parameters */ 162 int cur_attr; /* current hardware attr word */ 163 int attr_mask; /* current logical attr mask */ 164 int cur_color; /* current hardware color */ 165 int std_color; /* normal hardware color */ 166 int rev_color; /* reverse hardware color */ 167} term_stat; 168 169/* softc */ 170 171struct keyboard; 172struct video_adapter; 173struct scr_stat; 174struct tty; 175 176typedef struct sc_softc { 177 int unit; /* unit # */ 178 int config; /* configuration flags */ 179#define SC_VESA800X600 (1 << 7) 180#define SC_AUTODETECT_KBD (1 << 8) 181#define SC_KERNEL_CONSOLE (1 << 9) 182 183 int flags; /* status flags */ 184#define SC_VISUAL_BELL (1 << 0) 185#define SC_QUIET_BELL (1 << 1) 186#define SC_BLINK_CURSOR (1 << 2) 187#define SC_CHAR_CURSOR (1 << 3) 188#define SC_MOUSE_ENABLED (1 << 4) 189#define SC_SCRN_IDLE (1 << 5) 190#define SC_SCRN_BLANKED (1 << 6) 191#define SC_SAVER_FAILED (1 << 7) 192 193#define SC_INIT_DONE (1 << 16) 194#define SC_SPLASH_SCRN (1 << 17) 195 196 int keyboard; /* -1 if unavailable */ 197 struct keyboard *kbd; 198 199 int adapter; 200 struct video_adapter *adp; 201 int initial_mode; /* initial video mode */ 202 203 int first_vty; 204 int vtys; 205 dev_t *dev; 206 struct scr_stat *cur_scp; 207 struct scr_stat *new_scp; 208 struct scr_stat *old_scp; 209 int delayed_next_scr; 210 211 char font_loading_in_progress; 212 char switch_in_progress; 213 char videoio_in_progress; 214 char write_in_progress; 215 char blink_in_progress; 216 217 long scrn_time_stamp; 218 219 char cursor_base; 220 char cursor_height; 221 222 u_char scr_map[256]; 223 u_char scr_rmap[256]; 224 225#ifdef _SC_MD_SOFTC_DECLARED_ 226 sc_md_softc_t md; /* machine dependent vars */ 227#endif 228 229#ifndef SC_NO_PALETTE_LOADING 230 u_char palette[256*3]; 231#endif 232 233#ifndef SC_NO_FONT_LOADING 234 int fonts_loaded; 235 u_char *font_8; 236 u_char *font_14; 237 u_char *font_16; 238#endif 239 240} sc_softc_t; 241 242/* virtual screen */ 243typedef struct scr_stat { 244 int index; /* index of this vty */ 245 struct sc_softc *sc; /* pointer to softc */ 246 struct sc_rndr_sw *rndr; /* renderer */ 247 sc_vtb_t scr; 248 sc_vtb_t vtb; 249 int xpos; /* current X position */ 250 int ypos; /* current Y position */ 251 int saved_xpos; /* saved X position */ 252 int saved_ypos; /* saved Y position */ 253 int xsize; /* X text size */ 254 int ysize; /* Y text size */ 255 int xpixel; /* X graphics size */ 256 int ypixel; /* Y graphics size */ 257 int xoff; /* X offset in pixel mode */ 258 int yoff; /* Y offset in pixel mode */ 259 u_char *font; /* current font */ 260 int font_size; /* fontsize in Y direction */ 261 int start; /* modified area start */ 262 int end; /* modified area end */ 263 term_stat term; /* terminal emulation stuff */ 264 int status; /* status (bitfield) */ 265 int kbd_mode; /* keyboard I/O mode */ 266 int cursor_pos; /* cursor buffer position */ 267 int cursor_oldpos; /* cursor old buffer position */ 268 u_short cursor_saveunder_char; /* saved char under cursor */ 269 u_short cursor_saveunder_attr; /* saved attr under cursor */ 270 char cursor_base; /* cursor base line # */ 271 char cursor_height; /* cursor height */ 272 int mouse_pos; /* mouse buffer position */ 273 int mouse_oldpos; /* mouse old buffer position */ 274 short mouse_xpos; /* mouse x coordinate */ 275 short mouse_ypos; /* mouse y coordinate */ 276 short mouse_buttons; /* mouse buttons */ 277 int mouse_cut_start; /* mouse cut start pos */ 278 int mouse_cut_end; /* mouse cut end pos */ 279 struct proc *mouse_proc; /* proc* of controlling proc */ 280 pid_t mouse_pid; /* pid of controlling proc */ 281 int mouse_signal; /* signal # to report with */ 282 u_short bell_duration; 283 u_short bell_pitch; 284 u_char border; /* border color */ 285 int mode; /* mode */ 286 pid_t pid; /* pid of controlling proc */ 287 struct proc *proc; /* proc* of controlling proc */ 288 struct vt_mode smode; /* switch mode */ 289 sc_vtb_t *history; /* circular history buffer */ 290 int history_pos; /* position shown on screen */ 291 int history_size; /* size of history buffer */ 292 int splash_save_mode; /* saved mode for splash screen */ 293 int splash_save_status; /* saved status for splash screen */ 294#ifdef _SCR_MD_STAT_DECLARED_ 295 scr_md_stat_t md; /* machine dependent vars */ 296#endif 297} scr_stat; 298 299typedef struct default_attr { 300 int std_color; /* normal hardware color */ 301 int rev_color; /* reverse hardware color */ 302} default_attr; 303 304#ifndef SC_NORM_ATTR 305#define SC_NORM_ATTR (FG_LIGHTGREY | BG_BLACK) 306#endif 307#ifndef SC_NORM_REV_ATTR 308#define SC_NORM_REV_ATTR (FG_BLACK | BG_LIGHTGREY) 309#endif 310#ifndef SC_KERNEL_CONS_ATTR 311#define SC_KERNEL_CONS_ATTR (FG_WHITE | BG_BLACK) 312#endif 313#ifndef SC_KERNEL_CONS_REV_ATTR 314#define SC_KERNEL_CONS_REV_ATTR (FG_BLACK | BG_LIGHTGREY) 315#endif 316 317/* renderer function table */ 318typedef void vr_clear_t(scr_stat *scp, int c, int attr); 319typedef void vr_draw_border_t(scr_stat *scp, int color); 320typedef void vr_draw_t(scr_stat *scp, int from, int count, int flip); 321typedef void vr_set_cursor_t(scr_stat *scp, int base, int height, int blink); 322typedef void vr_draw_cursor_t(scr_stat *scp, int at, int blink, 323 int on, int flip); 324typedef void vr_blink_cursor_t(scr_stat *scp, int at, int flip); 325typedef void vr_set_mouse_t(scr_stat *scp); 326typedef void vr_draw_mouse_t(scr_stat *scp, int x, int y, int on); 327 328typedef struct sc_rndr_sw { 329 vr_clear_t *clear; 330 vr_draw_border_t *draw_border; 331 vr_draw_t *draw; 332 vr_set_cursor_t *set_cursor; 333 vr_draw_cursor_t *draw_cursor; 334 vr_blink_cursor_t *blink_cursor; 335 vr_set_mouse_t *set_mouse; 336 vr_draw_mouse_t *draw_mouse; 337} sc_rndr_sw_t; 338 339typedef struct sc_renderer { 340 char *name; 341 int mode; 342 sc_rndr_sw_t *rndrsw; 343} sc_renderer_t; 344 345#define RENDERER(name, mode, sw) \ 346 static struct sc_renderer name##_##mode##_renderer = { \ 347 #name, mode, &sw \ 348 }; \ 349 DATA_SET(scrndr_set, name##_##mode##_renderer) 350 351extern struct linker_set scrndr_set; 352 353typedef struct { 354 int cursor_start; 355 int cursor_end; 356 int shift_state; 357 int bell_pitch; 358} bios_values_t; 359 360/* other macros */ 361#define ISTEXTSC(scp) (!((scp)->status \ 362 & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE))) 363#define ISGRAPHSC(scp) (((scp)->status \ 364 & (UNKNOWN_MODE | GRAPHICS_MODE))) 365#define ISPIXELSC(scp) (((scp)->status \ 366 & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE))\ 367 == PIXEL_MODE) 368#define ISUNKNOWNSC(scp) ((scp)->status & UNKNOWN_MODE) 369 370#ifndef ISMOUSEAVAIL 371#ifdef SC_ALT_MOUSE_IMAGE 372#define ISMOUSEAVAIL(af) (1) 373#else 374#define ISMOUSEAVAIL(af) ((af) & V_ADP_FONT) 375#endif /* SC_ALT_MOUSE_IMAGE */ 376#define ISFONTAVAIL(af) ((af) & V_ADP_FONT) 377#define ISPALAVAIL(af) ((af) & V_ADP_PALETTE) 378#endif /* ISMOUSEAVAIL */ 379 380#define ISSIGVALID(sig) ((sig) > 0 && (sig) < NSIG) 381 382#define kbd_read_char(kbd, wait) \ 383 (*kbdsw[(kbd)->kb_index]->read_char)((kbd), (wait)) 384#define kbd_check_char(kbd) \ 385 (*kbdsw[(kbd)->kb_index]->check_char)((kbd)) 386#define kbd_enable(kbd) \ 387 (*kbdsw[(kbd)->kb_index]->enable)((kbd)) 388#define kbd_disable(kbd) \ 389 (*kbdsw[(kbd)->kb_index]->disable)((kbd)) 390#define kbd_lock(kbd, lockf) \ 391 (*kbdsw[(kbd)->kb_index]->lock)((kbd), (lockf)) 392#define kbd_ioctl(kbd, cmd, arg) \ 393 (((kbd) == NULL) ? \ 394 ENODEV : (*kbdsw[(kbd)->kb_index]->ioctl)((kbd), (cmd), (arg))) 395#define kbd_clear_state(kbd) \ 396 (*kbdsw[(kbd)->kb_index]->clear_state)((kbd)) 397#define kbd_get_fkeystr(kbd, fkey, len) \ 398 (*kbdsw[(kbd)->kb_index]->get_fkeystr)((kbd), (fkey), (len)) 399#define kbd_poll(kbd, on) \ 400 (*kbdsw[(kbd)->kb_index]->poll)((kbd), (on)) 401 402/* syscons.c */ 403extern int (*sc_user_ioctl)(dev_t dev, u_long cmd, caddr_t data, 404 int flag, struct proc *p); 405 406int sc_probe_unit(int unit, int flags); 407int sc_attach_unit(int unit, int flags); 408int sc_resume_unit(int unit); 409 410int set_mode(scr_stat *scp); 411 412void copy_font(scr_stat *scp, int operation, int font_size, 413 u_char *font_image); 414void set_border(scr_stat *scp, int color); 415 416void sc_touch_scrn_saver(void); 417void sc_clear_screen(scr_stat *scp); 418void sc_set_cursor_image(scr_stat *scp); 419int sc_clean_up(scr_stat *scp); 420void sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard); 421struct tty *scdevtotty(dev_t dev); 422#ifndef SC_NO_SYSMOUSE 423struct tty *sc_get_mouse_tty(void); 424#endif /* SC_NO_SYSMOUSE */ 425#ifndef SC_NO_CUTPASTE 426void sc_paste(scr_stat *scp, u_char *p, int count); 427#endif /* SC_NO_CUTPASTE */ 428 429/* schistory.c */ 430#ifndef SC_NO_HISTORY 431int sc_alloc_history_buffer(scr_stat *scp, int lines, 432 int prev_ysize, int wait); 433void sc_free_history_buffer(scr_stat *scp, int prev_ysize); 434void sc_hist_save(scr_stat *scp); 435#define sc_hist_save_one_line(scp, from) \ 436 sc_vtb_append(&(scp)->vtb, (from), (scp)->history, (scp)->xsize) 437int sc_hist_restore(scr_stat *scp); 438void sc_hist_home(scr_stat *scp); 439void sc_hist_end(scr_stat *scp); 440int sc_hist_up_line(scr_stat *scp); 441int sc_hist_down_line(scr_stat *scp); 442int sc_hist_ioctl(struct tty *tp, u_long cmd, caddr_t data, 443 int flag, struct proc *p); 444#endif /* SC_NO_HISTORY */ 445 446/* scmouse.c */ 447#ifndef SC_NO_CUTPASTE 448void sc_alloc_cut_buffer(scr_stat *scp, int wait); 449void sc_draw_mouse_image(scr_stat *scp); 450void sc_remove_mouse_image(scr_stat *scp); 451int sc_inside_cutmark(scr_stat *scp, int pos); 452void sc_remove_cutmarking(scr_stat *scp); 453void sc_remove_all_cutmarkings(sc_softc_t *scp); 454void sc_remove_all_mouse(sc_softc_t *scp); 455#else 456#define sc_inside_cutmark(scp, pos) FALSE 457#define sc_remove_cutmarking(scp) 458#endif /* SC_NO_CUTPASTE */ 459#ifndef SC_NO_SYSMOUSE 460void sc_mouse_set_level(int level); 461void sc_mouse_move(scr_stat *scp, int x, int y); 462int sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data, 463 int flag, struct proc *p); 464#endif /* SC_NO_SYSMOUSE */ 465 466/* scvidctl.c */ 467int sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode, 468 int xsize, int ysize, int fontsize); 469int sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode); 470int sc_set_pixel_mode(scr_stat *scp, struct tty *tp, 471 int xsize, int ysize, int fontsize); 472sc_rndr_sw_t *sc_render_match(scr_stat *scp, video_adapter_t *adp, int mode); 473int sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, 474 struct proc *p); 475 476/* scvtb.c */ 477void sc_vtb_init(sc_vtb_t *vtb, int type, int cols, int rows, 478 void *buffer, int wait); 479void sc_vtb_destroy(sc_vtb_t *vtb); 480size_t sc_vtb_size(int cols, int rows); 481void sc_vtb_clear(sc_vtb_t *vtb, int c, int attr); 482 483int sc_vtb_getc(sc_vtb_t *vtb, int at); 484int sc_vtb_geta(sc_vtb_t *vtb, int at); 485void sc_vtb_putc(sc_vtb_t *vtb, int at, int c, int a); 486vm_offset_t sc_vtb_putchar(sc_vtb_t *vtb, vm_offset_t p, int c, int a); 487vm_offset_t sc_vtb_pointer(sc_vtb_t *vtb, int at); 488int sc_vtb_pos(sc_vtb_t *vtb, int pos, int offset); 489 490#define sc_vtb_tail(vtb) ((vtb)->vtb_tail) 491#define sc_vtb_rows(vtb) ((vtb)->vtb_rows) 492#define sc_vtb_cols(vtb) ((vtb)->vtb_cols) 493 494void sc_vtb_copy(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, int to, 495 int count); 496void sc_vtb_append(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, 497 int count); 498void sc_vtb_seek(sc_vtb_t *vtb, int pos); 499void sc_vtb_erase(sc_vtb_t *vtb, int at, int count, int c, int attr); 500void sc_vtb_move(sc_vtb_t *vtb, int from, int to, int count); 501void sc_vtb_delete(sc_vtb_t *vtb, int at, int count, int c, int attr); 502void sc_vtb_ins(sc_vtb_t *vtb, int at, int count, int c, int attr); 503 504/* machine dependent functions */ 505int sc_max_unit(void); 506sc_softc_t *sc_get_softc(int unit, int flags); 507sc_softc_t *sc_find_softc(struct video_adapter *adp, struct keyboard *kbd); 508int sc_get_cons_priority(int *unit, int *flags); 509void sc_get_bios_values(bios_values_t *values); 510int sc_tone(int herz); 511 512#endif /* !_DEV_SYSCONS_SYSCONS_H_ */ 513