dcons.c (131912) | dcons.c (132092) |
---|---|
1/* 2 * Copyright (C) 2003 3 * Hidetoshi Shimokawa. 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 --- 18 unchanged lines hidden (view full) --- 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * $Id: dcons.c,v 1.65 2003/10/24 03:24:55 simokawa Exp $ | 1/* 2 * Copyright (C) 2003 3 * Hidetoshi Shimokawa. 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 --- 18 unchanged lines hidden (view full) --- 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * $Id: dcons.c,v 1.65 2003/10/24 03:24:55 simokawa Exp $ |
35 * $FreeBSD: head/sys/dev/dcons/dcons.c 131912 2004-07-10 21:02:17Z marcel $ | 35 * $FreeBSD: head/sys/dev/dcons/dcons.c 132092 2004-07-13 09:41:45Z simokawa $ |
36 */ 37 38#include <sys/param.h> | 36 */ 37 38#include <sys/param.h> |
39#if __FreeBSD_version >= 502122 |
|
39#include <sys/kdb.h> | 40#include <sys/kdb.h> |
41#include <gdb/gdb.h> 42#endif |
|
40#include <sys/kernel.h> 41#include <sys/module.h> 42#include <sys/systm.h> 43#include <sys/types.h> 44#include <sys/conf.h> 45#include <sys/cons.h> 46#include <sys/consio.h> 47#include <sys/tty.h> --- 21 unchanged lines hidden (view full) --- 69#ifndef DCONS_BUF_SIZE 70#define DCONS_BUF_SIZE (16*1024) 71#endif 72 73#ifndef DCONS_FORCE_CONSOLE 74#define DCONS_FORCE_CONSOLE 0 /* mostly for FreeBSD-4 */ 75#endif 76 | 43#include <sys/kernel.h> 44#include <sys/module.h> 45#include <sys/systm.h> 46#include <sys/types.h> 47#include <sys/conf.h> 48#include <sys/cons.h> 49#include <sys/consio.h> 50#include <sys/tty.h> --- 21 unchanged lines hidden (view full) --- 72#ifndef DCONS_BUF_SIZE 73#define DCONS_BUF_SIZE (16*1024) 74#endif 75 76#ifndef DCONS_FORCE_CONSOLE 77#define DCONS_FORCE_CONSOLE 0 /* mostly for FreeBSD-4 */ 78#endif 79 |
80#ifndef DCONS_FORCE_GDB 81#define DCONS_FORCE_GDB 1 82#endif 83 |
|
77#if __FreeBSD_version >= 500101 | 84#if __FreeBSD_version >= 500101 |
78#define CONS_NODEV 1 /* for latest current */ | 85#define CONS_NODEV 1 86#if __FreeBSD_version < 502122 87static struct consdev gdbconsdev; |
79#endif | 88#endif |
89#endif |
|
80 81 82static d_open_t dcons_open; 83static d_close_t dcons_close; 84 85static struct cdevsw dcons_cdevsw = { 86#if __FreeBSD_version >= 500104 87 .d_version = D_VERSION, --- 35 unchanged lines hidden (view full) --- 123static struct callout dcons_callout; 124struct dcons_buf *dcons_buf; /* for local dconschat */ 125 126/* per device data */ 127static struct dcons_softc { 128 struct cdev *dev; 129 struct dcons_ch o, i; 130 int brk_state; | 90 91 92static d_open_t dcons_open; 93static d_close_t dcons_close; 94 95static struct cdevsw dcons_cdevsw = { 96#if __FreeBSD_version >= 500104 97 .d_version = D_VERSION, --- 35 unchanged lines hidden (view full) --- 133static struct callout dcons_callout; 134struct dcons_buf *dcons_buf; /* for local dconschat */ 135 136/* per device data */ 137static struct dcons_softc { 138 struct cdev *dev; 139 struct dcons_ch o, i; 140 int brk_state; |
141#define DC_GDB 1 |
|
131 int flags; 132} sc[DCONS_NPORT]; 133static void dcons_tty_start(struct tty *); 134static int dcons_tty_param(struct tty *, struct termios *); 135static void dcons_timeout(void *); 136static int dcons_drv_init(int); 137static int dcons_getc(struct dcons_softc *); 138static int dcons_checkc(struct dcons_softc *); 139static void dcons_putc(struct dcons_softc *, int); 140 141static cn_probe_t dcons_cnprobe; 142static cn_init_t dcons_cninit; 143static cn_getc_t dcons_cngetc; 144static cn_checkc_t dcons_cncheckc; 145static cn_putc_t dcons_cnputc; 146 147CONS_DRIVER(dcons, dcons_cnprobe, dcons_cninit, NULL, dcons_cngetc, 148 dcons_cncheckc, dcons_cnputc, NULL); 149 | 142 int flags; 143} sc[DCONS_NPORT]; 144static void dcons_tty_start(struct tty *); 145static int dcons_tty_param(struct tty *, struct termios *); 146static void dcons_timeout(void *); 147static int dcons_drv_init(int); 148static int dcons_getc(struct dcons_softc *); 149static int dcons_checkc(struct dcons_softc *); 150static void dcons_putc(struct dcons_softc *, int); 151 152static cn_probe_t dcons_cnprobe; 153static cn_init_t dcons_cninit; 154static cn_getc_t dcons_cngetc; 155static cn_checkc_t dcons_cncheckc; 156static cn_putc_t dcons_cnputc; 157 158CONS_DRIVER(dcons, dcons_cnprobe, dcons_cninit, NULL, dcons_cngetc, 159 dcons_cncheckc, dcons_cnputc, NULL); 160 |
161#if __FreeBSD_version >= 502122 162static gdb_probe_f dcons_dbg_probe; 163static gdb_init_f dcons_dbg_init; 164static gdb_term_f dcons_dbg_term; 165static gdb_getc_f dcons_dbg_getc; 166static gdb_checkc_f dcons_dbg_checkc; 167static gdb_putc_f dcons_dbg_putc; 168 169GDB_DBGPORT(dcons, dcons_dbg_probe, dcons_dbg_init, dcons_dbg_term, 170 dcons_dbg_checkc, dcons_dbg_getc, dcons_dbg_putc); 171 172extern struct gdb_dbgport *gdb_cur; 173#endif 174 |
|
150#if __FreeBSD_version < 500000 151#define THREAD proc 152#else 153#define THREAD thread 154#endif 155 156static int 157dcons_open(struct cdev *dev, int flag, int mode, struct THREAD *td) --- 205 unchanged lines hidden (view full) --- 363 364 c = ch->buf[ch->pos]; 365 ch->pos ++; 366 if (ch->pos >= ch->size) { 367 ch->gen = next_gen; 368 ch->pos = 0; 369 } 370 | 175#if __FreeBSD_version < 500000 176#define THREAD proc 177#else 178#define THREAD thread 179#endif 180 181static int 182dcons_open(struct cdev *dev, int flag, int mode, struct THREAD *td) --- 205 unchanged lines hidden (view full) --- 388 389 c = ch->buf[ch->pos]; 390 ch->pos ++; 391 if (ch->pos >= ch->size) { 392 ch->gen = next_gen; 393 ch->pos = 0; 394 } 395 |
396#if __FreeBSD_version >= 502122 |
|
371#if KDB && ALT_BREAK_TO_DEBUGGER | 397#if KDB && ALT_BREAK_TO_DEBUGGER |
372 if (kdb_alt_break(c, &dc->brk_state)) 373 breakpoint(); | 398 if (kdb_alt_break(c, &dc->brk_state)) { 399 if ((dc->flags & DC_GDB) != 0) { 400 if (gdb_cur == &dcons_gdb_dbgport) { 401 kdb_dbbe_select("gdb"); 402 breakpoint(); 403 } 404 } else 405 breakpoint(); 406 } |
374#endif | 407#endif |
408#else 409#if DDB && ALT_BREAK_TO_DEBUGGER 410 switch (dc->brk_state) { 411 case STATE1: 412 if (c == KEY_TILDE) 413 dc->brk_state = STATE2; 414 else 415 dc->brk_state = STATE0; 416 break; 417 case STATE2: 418 dc->brk_state = STATE0; 419 if (c == KEY_CTRLB) { 420#if DCONS_FORCE_GDB 421 if (dc->flags & DC_GDB) 422 boothowto |= RB_GDB; 423#endif 424 breakpoint(); 425 } 426 } 427 if (c == KEY_CR) 428 dc->brk_state = STATE1; 429#endif 430#endif |
|
375 return (c); 376} 377 378static void 379dcons_putc(struct dcons_softc *dc, int c) 380{ 381 struct dcons_ch *ch; 382 --- 76 unchanged lines hidden (view full) --- 459 size = (dg.size - offset); 460 size0 = size * 3 / 4; 461 462 dcons_init_port(0, offset, size0); 463 offset += size0; 464 dcons_init_port(1, offset, size - size0); 465 dg.buf->version = htonl(DCONS_VERSION); 466 dg.buf->magic = ntohl(DCONS_MAGIC); | 431 return (c); 432} 433 434static void 435dcons_putc(struct dcons_softc *dc, int c) 436{ 437 struct dcons_ch *ch; 438 --- 76 unchanged lines hidden (view full) --- 515 size = (dg.size - offset); 516 size0 = size * 3 / 4; 517 518 dcons_init_port(0, offset, size0); 519 offset += size0; 520 dcons_init_port(1, offset, size - size0); 521 dg.buf->version = htonl(DCONS_VERSION); 522 dg.buf->magic = ntohl(DCONS_MAGIC); |
523 524#if __FreeBSD_version < 502122 525#if DDB && DCONS_FORCE_GDB 526#if CONS_NODEV 527 gdbconsdev.cn_arg = (void *)&sc[DCONS_GDB]; 528#if __FreeBSD_version >= 501109 529 sprintf(gdbconsdev.cn_name, "dgdb"); 530#endif 531 gdb_arg = &gdbconsdev; 532#else 533 gdbdev = makedev(CDEV_MAJOR, DCONS_GDB); 534#endif 535 gdb_getc = dcons_cngetc; 536 gdb_putc = dcons_cnputc; 537#endif 538#endif |
|
467 drv_init = 1; 468 469 return 0; 470} 471 472 473static int 474dcons_attach_port(int port, char *name, int flags) --- 19 unchanged lines hidden (view full) --- 494} 495 496static int 497dcons_attach(void) 498{ 499 int polltime; 500 501 dcons_attach_port(DCONS_CON, "dcons", 0); | 539 drv_init = 1; 540 541 return 0; 542} 543 544 545static int 546dcons_attach_port(int port, char *name, int flags) --- 19 unchanged lines hidden (view full) --- 566} 567 568static int 569dcons_attach(void) 570{ 571 int polltime; 572 573 dcons_attach_port(DCONS_CON, "dcons", 0); |
574 dcons_attach_port(DCONS_GDB, "dgdb", DC_GDB); |
|
502#if __FreeBSD_version < 500000 503 callout_init(&dcons_callout); 504#else 505 callout_init(&dcons_callout, 0); 506#endif 507 polltime = hz / poll_hz; 508 if (polltime < 1) 509 polltime = 1; --- 42 unchanged lines hidden (view full) --- 552 dcons_cninit(&dcons_consdev); 553 cnadd(&dcons_consdev); 554 } 555#endif 556 break; 557 case MOD_UNLOAD: 558 printf("dcons: unload\n"); 559 callout_stop(&dcons_callout); | 575#if __FreeBSD_version < 500000 576 callout_init(&dcons_callout); 577#else 578 callout_init(&dcons_callout, 0); 579#endif 580 polltime = hz / poll_hz; 581 if (polltime < 1) 582 polltime = 1; --- 42 unchanged lines hidden (view full) --- 625 dcons_cninit(&dcons_consdev); 626 cnadd(&dcons_consdev); 627 } 628#endif 629 break; 630 case MOD_UNLOAD: 631 printf("dcons: unload\n"); 632 callout_stop(&dcons_callout); |
633#if __FreeBSD_version < 502122 634#if DDB && DCONS_FORCE_GDB 635#if CONS_NODEV 636 gdb_arg = NULL; 637#else 638 gdbdev = NULL; 639#endif 640#endif 641#endif |
|
560#if __FreeBSD_version >= 500000 561 cnremove(&dcons_consdev); 562#endif 563 dcons_detach(DCONS_CON); | 642#if __FreeBSD_version >= 500000 643 cnremove(&dcons_consdev); 644#endif 645 dcons_detach(DCONS_CON); |
646 dcons_detach(DCONS_GDB); |
|
564 dg.buf->magic = 0; 565 566 contigfree(dg.buf, DCONS_BUF_SIZE, M_DEVBUF); 567 568 break; 569 case MOD_SHUTDOWN: 570 break; 571 } 572 return(err); 573} 574 | 647 dg.buf->magic = 0; 648 649 contigfree(dg.buf, DCONS_BUF_SIZE, M_DEVBUF); 650 651 break; 652 case MOD_SHUTDOWN: 653 break; 654 } 655 return(err); 656} 657 |
658#if __FreeBSD_version >= 502122 659/* Debugger interface */ 660 661static int 662dcons_dbg_probe(void) 663{ 664 return(DCONS_FORCE_GDB); 665} 666 667static void 668dcons_dbg_init(void) 669{ 670} 671 672static void 673dcons_dbg_term(void) 674{ 675} 676 677static void 678dcons_dbg_putc(int c) 679{ 680 dcons_putc(&sc[DCONS_GDB], c); 681} 682 683static int 684dcons_dbg_checkc(void) 685{ 686 return (dcons_checkc(&sc[DCONS_GDB])); 687} 688 689static int 690dcons_dbg_getc(void) 691{ 692 return (dcons_getc(&sc[DCONS_GDB])); 693} 694#endif 695 |
|
575DEV_MODULE(dcons, dcons_modevent, NULL); 576MODULE_VERSION(dcons, DCONS_VERSION); | 696DEV_MODULE(dcons, dcons_modevent, NULL); 697MODULE_VERSION(dcons, DCONS_VERSION); |