📄 console.c
字号:
/* * Redirection of .INSTAT does not work: 167-Bug crashes. * Switch the input stream to the specified port. * Make sure this is atomic code. */ rtems_interrupt_disable( previous_level ); asm volatile( "movew %1, -(%%sp)\n\t"/* Channel */ "trap #15\n\t" /* Trap to 167Bug */ ".short 0x61\n\t" /* Code for .REDIR_I */ "trap #15\n\t" /* Trap to 167Bug */ ".short 0x01\n\t" /* Code for .INSTAT */ "move %%cc, %0\n\t" /* Get condition codes */ "andil #4, %0" /* Keep the Zero bit */ : "=d" (char_not_available) : "d" (minor): "%%cc" ); if (char_not_available) { rtems_interrupt_enable( previous_level ); return -1; } /* Read the char and return it */ asm volatile( "subq.l #2,%%a7\n\t" /* Space for result */ "trap #15\n\t" /* Trap to 167 Bug */ ".short 0x00\n\t" /* Code for .INCHR */ "moveb (%%a7)+, %0" /* Pop char into c */ : "=d" (c) : ); rtems_interrupt_enable( previous_level ); return (int)c;}/* * _167Bug_pollWrite * * Output buffer through 167Bug. Returns only once every character has been * sent (polled output). * * Input parameters: * minor - selected channel * buf - output buffer * len - number of chars to output * * Output parameters: NONE * * Return value: IGNORED * * CANNOT BE COMBINED WITH INTERRUPT DRIVEN I/O! */int _167Bug_pollWrite( int minor, const char *buf, int len){ const char *endbuf = buf + len; asm volatile( "pea (%0)\n\t" /* endbuf */ "pea (%1)\n\t" /* buf */ "movew #0x21, -(%%sp)\n\t" /* Code for .OUTSTR */ "movew %2, -(%%sp)\n\t" /* Channel */ "trap #15\n\t" /* Trap to 167Bug */ ".short 0x60" /* Code for .REDIR */ :: "a" (endbuf), "a" (buf), "d" (minor) ); /* Return something */ return RTEMS_SUCCESSFUL;}/* * do_poll_read * * Input characters through 167Bug. Returns has soon as a character has been * received. Otherwise, if we wait for the number of requested characters, we * could be here forever! * * CR is converted to LF on input. The terminal should not send a CR/LF pair * when the return or enter key is pressed. * * Input parameters: * major - ignored. Should be the major number for this driver. * minor - selected channel. * arg->buffer - where to put the received characters. * arg->count - number of characters to receive before returning--Ignored. * * Output parameters: * arg->bytes_moved - the number of characters read. Always 1. * * Return value: RTEMS_SUCCESSFUL * * CANNOT BE COMBINED WITH INTERRUPT DRIVEN I/O! */rtems_status_code do_poll_read( rtems_device_major_number major, rtems_device_minor_number minor, void * arg){ rtems_libio_rw_args_t *rw_args = arg; int c; while( (c = _167Bug_pollRead (minor)) == -1 ); rw_args->buffer[0] = (unsigned8)c; if( rw_args->buffer[0] == '\r' ) rw_args->buffer[0] = '\n'; rw_args->bytes_moved = 1; return RTEMS_SUCCESSFUL;}/* * do_poll_write * * Output characters through 167Bug. Returns only once every character has * been sent. * * CR is transmitted AFTER a LF on output. * * Input parameters: * major - ignored. Should be the major number for this driver. * minor - selected channel * arg->buffer - where to get the characters to transmit. * arg->count - the number of characters to transmit before returning. * * Output parameters: * arg->bytes_moved - the number of characters read * * Return value: RTEMS_SUCCESSFUL * * CANNOT BE COMBINED WITH INTERRUPT DRIVEN I/O! */rtems_status_code do_poll_write( rtems_device_major_number major, rtems_device_minor_number minor, void * arg){ rtems_libio_rw_args_t *rw_args = arg; unsigned32 i; char cr ='\r'; for( i = 0; i < rw_args->count; i++ ) { _167Bug_pollWrite(minor, &(rw_args->buffer[i]), 1); if ( rw_args->buffer[i] == '\n' ) _167Bug_pollWrite(minor, &cr, 1); } rw_args->bytes_moved = i; return RTEMS_SUCCESSFUL;}/* * _BSP_output_char * * printk() function prototyped in bspIo.h. Does not use termios. */void _BSP_output_char(char c){ rtems_device_minor_number printk_minor; char cr ='\r'; /* * Can't rely on console_initialize having been called before this function * is used. */ if ( NVRAM_CONFIGURE ) /* J1-4 is on, use NVRAM info for configuration */ printk_minor = (nvram->console_printk_port & 0x30) >> 4; else printk_minor = PRINTK_MINOR; _167Bug_pollWrite(printk_minor, &c, 1); if ( c == '\n' ) _167Bug_pollWrite(printk_minor, &cr, 1);} /* *************** * BOILERPLATE * *************** * * All these functions are prototyped in rtems/c/src/lib/include/console.h. *//* * Initialize and register the device */rtems_device_driver console_initialize( rtems_device_major_number major, rtems_device_minor_number minor, void *arg){ rtems_status_code status; rtems_device_minor_number console_minor; /* * Set up TERMIOS if needed */ if ( NVRAM_CONFIGURE ) { /* J1-4 is on, use NVRAM info for configuration */ console_minor = nvram->console_printk_port & 0x03; if ( nvram->console_mode & 0x01 ) /* termios */ rtems_termios_initialize (); } else { console_minor = CONSOLE_MINOR;#if CD2401_USE_TERMIOS == 1 rtems_termios_initialize ();#endif } /* * Do device-specific initialization * Does not affect 167-Bug. */ cd2401_initialize (); /* * Register the devices */ status = rtems_io_register_name ("/dev/tty0", major, 0); if (status != RTEMS_SUCCESSFUL) rtems_fatal_error_occurred (status); status = rtems_io_register_name ("/dev/tty1", major, 1); if (status != RTEMS_SUCCESSFUL) rtems_fatal_error_occurred (status); status = rtems_io_register_name ("/dev/console", major, console_minor); if (status != RTEMS_SUCCESSFUL) rtems_fatal_error_occurred (status); status = rtems_io_register_name ("/dev/tty2", major, 2); if (status != RTEMS_SUCCESSFUL) rtems_fatal_error_occurred (status); status = rtems_io_register_name ("/dev/tty3", major, 3); if (status != RTEMS_SUCCESSFUL) rtems_fatal_error_occurred (status); return RTEMS_SUCCESSFUL;}/* * Open the device */rtems_device_driver console_open( rtems_device_major_number major, rtems_device_minor_number minor, void * arg){ static const rtems_termios_callbacks pollCallbacks = { NULL, /* firstOpen */ NULL, /* lastClose */ _167Bug_pollRead, /* pollRead */ _167Bug_pollWrite, /* write */ NULL, /* setAttributes */ NULL, /* stopRemoteTx */ NULL, /* startRemoteTx */ 0 /* outputUsesInterrupts */ }; static const rtems_termios_callbacks intrCallbacks = { cd2401_firstOpen, /* firstOpen */ cd2401_lastClose, /* lastClose */ NULL, /* pollRead */ cd2401_write, /* write */ cd2401_setAttributes, /* setAttributes */ cd2401_stopRemoteTx, /* stopRemoteTx */ cd2401_startRemoteTx, /* startRemoteTx */ 1 /* outputUsesInterrupts */ }; if ( NVRAM_CONFIGURE ) /* J1-4 is on, use NVRAM info for configuration */ if ( nvram->console_mode & 0x01 ) /* termios */ if ( nvram->console_mode & 0x02 ) /* interrupt-driven I/O */ return rtems_termios_open (major, minor, arg, &intrCallbacks); else /* polled I/O */ return rtems_termios_open (major, minor, arg, &pollCallbacks); else /* no termios -- default to polled I/O */ return RTEMS_SUCCESSFUL;#if CD2401_USE_TERMIOS == 1#if CD2401_IO_MODE != 1 else /* termios & polled I/O*/ return rtems_termios_open (major, minor, arg, &pollCallbacks);#else else /* termios & interrupt-driven I/O*/ return rtems_termios_open (major, minor, arg, &intrCallbacks);#endif#else else /* no termios -- default to polled I/O */ return RTEMS_SUCCESSFUL;#endif}/* * Close the device */rtems_device_driver console_close( rtems_device_major_number major, rtems_device_minor_number minor, void * arg){ if ( NVRAM_CONFIGURE ) { /* J1-4 is on, use NVRAM info for configuration */ if ( nvram->console_mode & 0x01 ) /* termios */ return rtems_termios_close (arg); else /* no termios */ return RTEMS_SUCCESSFUL; }#if CD2401_USE_TERMIOS == 1 else /* termios */ return rtems_termios_close (arg);#else else /* no termios */ return RTEMS_SUCCESSFUL;#endif}/* * Read from the device */rtems_device_driver console_read( rtems_device_major_number major, rtems_device_minor_number minor, void * arg){ if ( NVRAM_CONFIGURE ) { /* J1-4 is on, use NVRAM info for configuration */ if ( nvram->console_mode & 0x01 ) /* termios */ return rtems_termios_read (arg); else /* no termios -- default to polled */ return do_poll_read (major, minor, arg); }#if CD2401_USE_TERMIOS == 1 else /* termios */ return rtems_termios_read (arg);#else else /* no termios -- default to polled */ return do_poll_read (major, minor, arg);#endif}/* * Write to the device */rtems_device_driver console_write( rtems_device_major_number major, rtems_device_minor_number minor, void * arg){ if ( NVRAM_CONFIGURE ) { /* J1-4 is on, use NVRAM info for configuration */ if ( nvram->console_mode & 0x01 ) /* termios */ return rtems_termios_write (arg); else /* no termios -- default to polled */ return do_poll_write (major, minor, arg); }#if CD2401_USE_TERMIOS == 1 else /* termios */ return rtems_termios_write (arg);#else else /* no termios -- default to polled */ return do_poll_write (major, minor, arg);#endif}/* * Handle ioctl request. */rtems_device_driver console_control( rtems_device_major_number major, rtems_device_minor_number minor, void * arg){ if ( NVRAM_CONFIGURE ) { /* J1-4 is on, use NVRAM info for configuration */ if ( nvram->console_mode & 0x01 ) /* termios */ return rtems_termios_ioctl (arg); else /* no termios -- default to polled */ return RTEMS_SUCCESSFUL; }#if CD2401_USE_TERMIOS == 1 else /* termios */ return rtems_termios_ioctl (arg);#else else /* no termios -- default to polled */ return RTEMS_SUCCESSFUL;#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -