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