--- trunk/mkinitrd-magellan/isolinux/conio.inc 2010/08/19 08:27:19 1132 +++ trunk/mkinitrd-magellan/isolinux/conio.inc 2010/08/19 09:50:43 1133 @@ -1,7 +1,7 @@ -;; $Id: conio.inc,v 1.1 2007-09-01 22:44:04 niro Exp $ ;; ----------------------------------------------------------------------- -;; -;; Copyright 1994-2005 H. Peter Anvin - All Rights Reserved +;; +;; Copyright 1994-2008 H. Peter Anvin - All Rights Reserved +;; Copyright 2009 Intel Corporation; author: H. Peter Anvin ;; ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -15,81 +15,64 @@ ;; conio.inc ;; ;; Console I/O code, except: -;; writechr, writestr - module-dependent -;; cwritestr, crlf - writestr.inc +;; writechr, writestr_early - module-dependent +;; writestr, crlf - writestr.inc ;; writehex* - writehex.inc ;; ; -; loadkeys: Load a LILO-style keymap; SI and DX:AX set by searchdir +; loadkeys: Load a LILO-style keymap; file is open on the top of the +; getc stack. ; section .text loadkeys: - and dx,dx ; Should be 256 bytes exactly - jne loadkeys_ret - cmp ax,256 - jne loadkeys_ret - - mov bx,trackbuf - mov cx,1 ; 1 cluster should be >= 256 bytes - call getfssec + mov cx,256 + mov di,trackbuf + call readc + jc .done ; EOF already? + + ; Make sure we are at EOF now... + call getc + jnc .done ; We should be at EOF now! + ; It was okay, we can now move it into the KbdMap mov si,trackbuf mov di,KbdMap mov cx,256 >> 2 rep movsd -loadkeys_ret: ret - +.done: + call close + ret + ; ; get_msg_file: Load a text file and write its contents to the screen, -; interpreting color codes. Is called with SI and DX:AX -; set by routine searchdir +; interpreting color codes. Call with the file already +; on the top of the open/getc stack. +; +; Assumes CS == DS == ES. ; get_msg_file: - push es - shl edx,16 ; EDX <- DX:AX (length of file) - mov dx,ax - mov ax,xfer_buf_seg ; Use for temporary storage - mov es,ax - mov byte [TextAttribute],07h ; Default grey on white mov byte [DisplayMask],07h ; Display text in all modes call msg_initvars -get_msg_chunk: push edx ; EDX = length of file - xor bx,bx ; == xbs_textbuf - mov cx,[BufSafe] - call getfssec - pop edx - push si ; Save current cluster - xor si,si ; == xbs_textbuf - mov cx,[BufSafeBytes] ; Number of bytes left in chunk print_msg_file: - push cx - push edx - es lodsb +.getc: + call getc + jc .done cmp al,1Ah ; DOS EOF? - je msg_done_pop - push si - mov cl,[UsingVGA] - inc cl ; 01h = text mode, 02h = graphics + je .done + movzx cx,byte [UsingVGA] + and cl,01h + inc cx ; CL <- 01h = text mode, + ; 02h = graphics mode call [NextCharJump] ; Do what shall be done - pop si - pop edx - pop cx - dec edx - jz msg_done - loop print_msg_file - pop si - jmp short get_msg_chunk -msg_done_pop: - add sp,byte 6 ; Drop pushed EDX, CX -msg_done: - pop si - pop es - ret + jmp .getc +.done: + jmp close ; Tailcall! + msg_putchar: ; Normal character cmp al,0Fh ; ^O = color code follows je msg_ctrl_o @@ -220,18 +203,12 @@ jmp short msg_initvars msg_viewimage: - push es - push ds - pop es ; ES <- DS mov si,[VGAFilePtr] mov byte [si],0 ; Zero-terminate filename mov si,VGAFileBuf mov di,VGAFileMBuf - push di call mangle_name - pop di - call searchdir - pop es + call open jz msg_putcharnext ; Not there call vgadisplayfile ; Fall through @@ -279,12 +256,12 @@ in al,dx and al,ah cmp al,ah - jne .waitspace -.no_flow: + jne .waitspace +.no_flow: xchg dx,bx ; DX -> THR pop ax - call slow_out ; Send data + slow_out dx,al ; Send data .noserial: popad popfd .end: ret @@ -316,10 +293,14 @@ mov dx,[SerialPort] and dx,dx jz .done ; No serial port -> no input - add dx,byte 5 ; DX -> LSR + mov ax,[SerialTail] ; Already-queued input? + cli + cmp ax,[SerialHead] + jne .done_sti ; If so, return ZF = 0 + add dx,5 ; DX -> LSR in al,dx test al,1 ; ZF = 0 if data pending - jz .done + jz .done_sti inc dx ; DX -> MSR mov ah,[FlowIgnore] ; Required status bits in al,dx @@ -327,36 +308,56 @@ cmp al,ah setne al dec al ; Set ZF = 0 if equal +.done_sti: sti .done: popad ret ; ; getchar: Read a character from keyboard or serial port ; +getchar.sti_again: + sti getchar: - RESET_IDLE .again: - DO_IDLE + call do_idle mov ah,11h ; Poll keyboard int 16h jnz .kbd ; Keyboard input? mov bx,[SerialPort] and bx,bx jz .again + mov ax,[SerialTail] + cli + cmp ax,[SerialHead] + jne .serial_queued lea dx,[bx+5] ; DX -> LSR in al,dx test al,1 - jz .again + jz .sti_again inc dx ; DX -> MSR mov ah,[FlowIgnore] in al,dx and al,ah cmp al,ah - jne .again + jne .sti_again .serial: xor ah,ah ; Avoid confusion - xchg dx,bx ; Data port - in al,dx - ret + mov dx,bx ; Data port + in al,dx ; Read data + sti + jmp .done +.serial_queued: + sti ; We already know we'll consume data + xchg bx,ax + push ds + mov ax,aux_seg + (aux.serial >> 4) + mov ds,ax + mov al,[bx] + pop ds + inc bx + and bx,serial_buf_size-1 + mov [SerialTail],bx + jmp .done + .kbd: mov ah,10h ; Get keyboard input int 16h cmp al,0E0h @@ -367,7 +368,9 @@ jz .func_key mov bx,KbdMap ; Convert character sets xlatb -.func_key: ret +.func_key: +.done: + jmp reset_idle ; Character received %ifdef DEBUG_TRACERS ; @@ -386,6 +389,13 @@ %endif ; DEBUG_TRACERS section .data +%if IS_ISOLINUX == 0 ; Defined elsewhere for ISOLINUX +crlf_msg db CR, LF +null_msg db 0 +%endif +crff_msg db CR, FF, 0 + + section .config ; This is a word to pc_setint16 can set it DisplayCon dw 01h ; Console display enabled @@ -401,12 +411,20 @@ VidCols resb 1 ; Columns on screen-1 VidRows resb 1 ; Rows on screen-1 -; Serial console stuff... -BaudDivisor resw 1 ; Baud rate divisor +; Serial console stuff; don't put this in .config becasue we don't want +; loading a new config file to undo this setting. + section .data + alignz 4 +SerialPort dw 0 ; Serial port base (or 0 for no serial port) +BaudDivisor dw 115200/9600 ; Baud rate divisor FlowControl equ $ -FlowOutput resb 1 ; Outputs to assert for serial flow -FlowInput resb 1 ; Input bits for serial flow -FlowIgnore resb 1 ; Ignore input unless these bits set +FlowOutput db 0 ; Outputs to assert for serial flow +FlowInput db 0 ; Input bits for serial flow +FlowIgnore db 0 ; Ignore input unless these bits set +FlowDummy db 0 ; Unused + section .bss TextAttribute resb 1 ; Text attribute for message file DisplayMask resb 1 ; Display modes mask + +%include "serirq.inc"