Changeset 3604

Show
Ignore:
Timestamp:
09/26/08 20:36:26 (3 months ago)
Author:
stepan
Message:

* factor out serial hardware init
* add reverse color support for serial
* add cursor enable/disable support for serial
* fix tinycurses compilation if serial is disabled
* add functions to query whether serial or vga console is enabled in tinycurses
* initialize uninitialized COLOR_PAIRS variable
* implement has_colors(), wredrawln() functions in curses

Signed-off-by: Stefan Reinauer <stepan@…>
Acked-by: Jordan Crouse <jordan.crouse@…>

Location:
trunk/payloads/libpayload
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/payloads/libpayload/curses/keyboard.c

    r3580 r3604  
    4545/* ============== Serial ==================== */ 
    4646 
     47#ifdef CONFIG_SERIAL_CONSOLE 
    4748/* We treat serial like a vt100 terminal.  For now we 
    4849   do the cooking in here, but we should probably eventually 
     
    136137        } 
    137138} 
     139#endif 
    138140 
    139141/* ================ Keyboard ================ */ 
     
    216218                curses_flags &= ~F_ENABLE_CONSOLE; 
    217219} 
     220 
     221int curses_vga_enabled(void) 
     222{ 
     223        return (curses_flags & F_ENABLE_CONSOLE) != 0; 
     224} 
    218225#else 
    219226void curses_enable_vga(int state) { } 
     227int curses_vga_enabled(void) { return 0; } 
    220228#endif 
    221229 
     
    228236                curses_flags &= ~F_ENABLE_SERIAL; 
    229237} 
     238 
     239int curses_serial_enabled(void) 
     240{ 
     241        return (curses_flags & F_ENABLE_SERIAL) != 0; 
     242} 
     243 
    230244#else 
    231245void curses_enable_serial(int state) { } 
    232 #endif 
    233  
     246int curses_serial_enabled(void) { return 0; } 
     247#endif 
     248 
  • trunk/payloads/libpayload/curses/tinycurses.c

    r3598 r3604  
    7878/* Globals */ 
    7979int COLORS;             /* Currently unused? */ 
    80 int COLOR_PAIRS; 
     80int COLOR_PAIRS = 255; 
    8181WINDOW *stdscr; 
    8282WINDOW *curscr; 
     
    112112        }; 
    113113 
     114#ifdef CONFIG_SERIAL_CONSOLE 
    114115#ifdef CONFIG_SERIAL_ACS_FALLBACK 
    115116chtype serial_acs_map[128]; 
     
    136137        }; 
    137138#endif 
    138  
     139#endif 
     140 
     141#ifdef CONFIG_VIDEO_CONSOLE 
    139142/* See acsc of linux. */ 
    140143chtype console_acs_map[128] = 
     
    157160        '\263', '\363', '\362', '\343', '\330', '\234', '\376', 0, 
    158161        }; 
     162#endif 
    159163 
    160164// FIXME: Ugly (and insecure!) hack! 
     
    197201int curs_set(int on) 
    198202{ 
     203#ifdef CONFIG_SERIAL_CONSOLE 
    199204        if (curses_flags & F_ENABLE_SERIAL) { 
    200                 // TODO 
    201         } 
    202  
     205                serial_cursor_enable(on); 
     206        } 
     207#endif 
     208#ifdef CONFIG_VIDEO_CONSOLE 
    203209        if (curses_flags & F_ENABLE_CONSOLE) { 
    204210                video_console_cursor_enable(on); 
    205211        } 
     212#endif 
    206213 
    207214        return OK; 
     
    285292int flushinp(void) { /* TODO */ return 0; } 
    286293// WINDOW *getwin (FILE *) {} 
    287 bool has_colors (void) { /* TODO */ return(*(bool *)0); } 
     294bool has_colors (void) { return(TRUE); } 
    288295// bool has_ic (void) {} 
    289296// bool has_il (void) {} 
     
    301308        for (i = 0; i < 128; i++) 
    302309          acs_map[i] = (chtype) i | A_ALTCHARSET; 
    303  
     310#ifdef CONFIG_SERIAL_CONSOLE 
    304311        if (curses_flags & F_ENABLE_SERIAL) { 
    305312                serial_clear(); 
    306313        } 
    307  
     314#endif 
     315#ifdef CONFIG_VIDEO_CONSOLE 
    308316        if (curses_flags & F_ENABLE_CONSOLE) { 
    309317                /* Clear the screen and kill the cursor */ 
     
    312320                video_console_cursor_enable(0); 
    313321        } 
     322#endif 
    314323 
    315324        // Speaker init? 
    316325 
    317         stdscr = newwin(SCREEN_Y, SCREEN_X, 0, 0); 
     326        stdscr = newwin(SCREEN_Y, SCREEN_X + 1, 0, 0); 
    318327        // TODO: curscr, newscr? 
    319328 
     
    694703int wnoutrefresh(WINDOW *win) 
    695704{ 
     705#ifdef CONFIG_SERIAL_CONSOLE 
    696706        // FIXME. 
    697707        int serial_is_bold = 0; 
     708        int serial_is_reverse = 0; 
    698709        int serial_is_altcharset = 0; 
    699710        int serial_cur_pair = 0; 
    700711 
     712        int need_altcharset; 
     713        short fg, bg; 
     714#endif 
    701715        int x, y; 
    702716        chtype ch; 
    703         int need_altcharset; 
    704         short fg, bg; 
    705  
     717 
     718#ifdef CONFIG_SERIAL_CONSOLE 
    706719        serial_end_bold(); 
    707720        serial_end_altcharset(); 
     721#endif 
    708722 
    709723        for (y = 0; y <= win->_maxy; y++) { 
     
    714728                /* Position the serial cursor */ 
    715729 
     730#ifdef CONFIG_SERIAL_CONSOLE 
    716731                if (curses_flags & F_ENABLE_SERIAL) 
    717732                        serial_set_cursor(win->_begy + y, win->_begx + 
    718733                                        win->_line[y].firstchar); 
     734#endif 
    719735 
    720736                for (x = win->_line[y].firstchar; x <= win->_line[y].lastchar; x++) { 
     
    724740                                ((int)color_pairs[PAIR_NUMBER(attr)]) << 8; 
    725741 
     742#ifdef CONFIG_SERIAL_CONSOLE 
    726743                        if (curses_flags & F_ENABLE_SERIAL) { 
    727744                                ch = win->_line[y].text[x].chars[0]; 
     
    732749                                                serial_is_bold = 1; 
    733750                                        } 
    734                                 } 
    735                                 else { 
     751                                } else { 
    736752                                        if (serial_is_bold) { 
    737753                                                serial_end_bold(); 
     754                                                serial_is_bold = 0; 
     755                                                /* work around serial.c 
     756                                                 * shortcoming: 
     757                                                 */ 
     758                                                serial_is_reverse = 0; 
     759                                                serial_cur_pair = 0; 
     760                                        } 
     761                                } 
     762 
     763                                if (attr & A_REVERSE) { 
     764                                        if (!serial_is_reverse) { 
     765                                                serial_start_reverse(); 
     766                                                serial_is_reverse = 1; 
     767                                        } 
     768                                } else { 
     769                                        if (serial_is_reverse) { 
     770                                                serial_end_reverse(); 
     771                                                serial_is_reverse = 0; 
     772                                                /* work around serial.c 
     773                                                 * shortcoming: 
     774                                                 */ 
    738775                                                serial_is_bold = 0; 
    739776                                                serial_cur_pair = 0; 
     
    768805 
    769806                        } 
    770  
     807#endif 
     808#ifdef CONFIG_VIDEO_CONSOLE 
    771809                        c = SWAP_RED_BLUE(c); 
    772810 
     
    800838                                video_console_putc(win->_begy + y, win->_begx + x, c); 
    801839                        } 
     840#endif 
    802841                } 
    803842                win->_line[y].firstchar = _NOCHANGE; 
     
    805844        } 
    806845 
     846#ifdef CONFIG_SERIAL_CONSOLE 
    807847        if (curses_flags & F_ENABLE_SERIAL) 
    808848                serial_set_cursor(win->_begy + win->_cury, win->_begx + win->_curx); 
    809  
     849#endif 
     850 
     851#ifdef CONFIG_VIDEO_CONSOLE 
    810852        if (curses_flags & F_ENABLE_CONSOLE) 
    811853                video_console_set_cursor(win->_begx + win->_curx, win->_begy + win->_cury); 
     854#endif 
    812855 
    813856        return OK; 
     
    824867        return code; 
    825868} 
    826 // int wredrawln (WINDOW *,int,int) {} 
     869 
     870int wredrawln (WINDOW *win, int beg_line, int num_lines) 
     871{ 
     872        int i; 
     873 
     874        for (i = beg_line; i < beg_line + num_lines; i++) { 
     875                win->_line[i].firstchar = 0; 
     876                win->_line[i].lastchar = win->_maxx; 
     877        } 
     878 
     879        return OK; 
     880} 
     881 
    827882int wrefresh(WINDOW *win) 
    828883{ 
  • trunk/payloads/libpayload/drivers/serial.c

    r3565 r3604  
    3333 
    3434#define IOBASE lib_sysinfo.ser_ioport 
     35#define DIVISOR(x) (115200 / x) 
    3536 
    36 #ifdef CONFIG_SERIAL_SET_SPEED 
    37 #define DIVISOR (115200 / CONFIG_SERIAL_BAUD_RATE) 
    38 #endif 
     37void serial_hardware_init(int port, int speed, int word_bits, int parity, int stop_bits) 
     38{ 
     39        unsigned char reg; 
     40 
     41        /* We will assume 8n1 for now. Does anyone use anything else these days? */ 
     42 
     43        /* Disable interrupts. */ 
     44        outb(0, port + 0x01); 
     45 
     46        /* Assert RTS and DTR. */ 
     47        outb(3, port + 0x04); 
     48 
     49        /* Set the divisor latch. */ 
     50        reg = inb(port + 0x03); 
     51        outb(reg | 0x80, port + 0x03); 
     52 
     53        /* Write the divisor. */ 
     54        outb(DIVISOR(speed) & 0xFF, port); 
     55        outb(DIVISOR(speed) >> 8 & 0xFF, port + 1); 
     56 
     57        /* Restore the previous value of the divisor. */ 
     58        outb(reg &= ~0x80, port + 0x03); 
     59} 
    3960 
    4061void serial_init(void) 
    4162{ 
    4263#ifdef CONFIG_SERIAL_SET_SPEED 
    43         unsigned char reg; 
    44  
    45         /* Disable interrupts. */ 
    46         outb(0, IOBASE + 0x01); 
    47  
    48         /* Assert RTS and DTR. */ 
    49         outb(3, IOBASE + 0x04); 
    50  
    51         /* Set the divisor latch. */ 
    52         reg = inb(IOBASE + 0x03); 
    53         outb(reg | 0x80, IOBASE + 0x03); 
    54  
    55         /* Write the divisor. */ 
    56         outb(DIVISOR & 0xFF, IOBASE); 
    57         outb(DIVISOR >> 8 & 0xFF, IOBASE + 1); 
    58  
    59         /* Restore the previous value of the divisor. */ 
    60         outb(reg &= ~0x80, IOBASE + 0x03); 
     64        serial_hardware_init(IOBASE, CONFIG_SERIAL_BAUD_RATE, 8, 0, 1); 
    6165#endif 
    6266} 
     
    8286 
    8387#define VT100_CLEAR       "\e[H\e[J" 
     88/* These defines will fail if you use bold and reverse at the same time. 
     89 * Switching off one of them will switch off both. tinycurses knows about 
     90 * this and does the right thing. 
     91 */ 
    8492#define VT100_SBOLD       "\e[1m" 
    8593#define VT100_EBOLD       "\e[m" 
     94#define VT100_SREVERSE    "\e[7m" 
     95#define VT100_EREVERSE    "\e[m" 
    8696#define VT100_CURSOR_ADDR "\e[%d;%dH" 
     97#define VT100_CURSOR_ON   "\e[?25l" 
     98#define VT100_CURSOR_OFF  "\e[?25h" 
    8799/* The following smacs/rmacs are actually for xterm; a real vt100 has 
    88100   enacs=\E(B\E)0, smacs=^N, rmacs=^O.  */ 
     
    111123{ 
    112124        serial_putcmd(VT100_EBOLD); 
     125} 
     126 
     127void serial_start_reverse(void) 
     128{ 
     129        serial_putcmd(VT100_SREVERSE); 
     130} 
     131 
     132void serial_end_reverse(void) 
     133{ 
     134        serial_putcmd(VT100_EREVERSE); 
    113135} 
    114136 
     
    142164        serial_putcmd(buffer); 
    143165} 
     166 
     167void serial_cursor_enable(int state) 
     168{ 
     169        if (state) 
     170                serial_putcmd(VT100_CURSOR_ON); 
     171        else 
     172                serial_putcmd(VT100_CURSOR_OFF); 
     173} 
  • trunk/payloads/libpayload/include/curses.h

    r3234 r3604  
    16741674void curses_enable_serial(int); 
    16751675 
     1676int curses_vga_enabled(void); 
     1677int curses_serial_enabled(void); 
     1678 
    16761679#endif /* _CURSES_H */ 
  • trunk/payloads/libpayload/include/libpayload.h

    r3561 r3604  
    132132 */ 
    133133void serial_init(void); 
     134void serial_hardware_init(int port, int speed, int word_bits, int parity, int stop_bits); 
    134135void serial_putchar(unsigned char c); 
    135136int serial_havechar(void); 
     
    138139void serial_start_bold(void); 
    139140void serial_end_bold(void); 
     141void serial_start_reverse(void); 
     142void serial_end_reverse(void); 
    140143void serial_start_altcharset(void); 
    141144void serial_end_altcharset(void); 
    142145void serial_set_color(short fg, short bg); 
     146void serial_cursor_enable(int state); 
    143147void serial_set_cursor(int y, int x); 
    144148/** @} */