keymap, font: use readc, so we can handle indeterminate file sizes syslinux-3.71-pre10
authorH. Peter Anvin <hpa@zytor.com>
Mon, 14 Jul 2008 19:44:21 +0000 (12:44 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Mon, 14 Jul 2008 19:50:24 +0000 (12:50 -0700)
The keymap and font commands still assumed that we knew the file size,
which is no longer true.  Fix that by instead using "readc" and
checking the CF.

core/conio.inc
core/font.inc
core/keywords.inc

index 6513f31..aa3fd0e 100644 (file)
 ;;
 
 ;
-; loadkeys:    Load a LILO-style keymap; SI and EAX set by searchdir
+; loadkeys:    Load a LILO-style keymap; file is open on the top of the
+;              getc stack.
 ;
                section .text
 
 loadkeys:
-               cmp eax,256                     ; Should be 256 bytes exactly
-               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,
index be9a365..a553f04 100644 (file)
 
 ;
 ; loadfont:    Load a .psf font file and install it onto the VGA console
-;              (if we're not on a VGA screen then ignore.)  It is called with
-;              SI and EAX set by routine searchdir
+;              (if we're not on a VGA screen then ignore.)
+;              The font is on top of the getc stack.
 ;
+loadfont.err:  jmp close                       ; Tailcall the close routine
+
 loadfont:
-               ; XXX: This can be 8K+4 bytes and the trackbuf is only
-               ; guaranteed to be 8K in size...
-               mov bx,trackbuf
-               mov cx,[BufSafe]
-               call getfssec
+               mov di,trackbuf
+               mov cx,4
+               call readc                      ; Read header
+               jc .err
 
                mov ax,[trackbuf]               ; Magic number
                cmp ax,0436h
-               jne lf_ret
+               jne .err
 
                mov al,[trackbuf+2]             ; File mode
                cmp al,5                        ; Font modes 0-5 supported
-               ja lf_ret
+               ja .err
 
-               mov bh,byte [trackbuf+3]        ; Height of font
+               xor bx,bx
+               mov bh,[trackbuf+3]             ; Height of font
                cmp bh,2                        ; VGA minimum
-               jb lf_ret
+               jb .err
                cmp bh,32                       ; VGA maximum
-               ja lf_ret
+               ja .err
+
+               ; Load the actual font
+               mov di,trackbuf
+               mov cx,bx                       ; Bytes = font height * 256
+               call readc
+               jc .err
+
+               call close
 
                ; Copy to font buffer
-               mov si,trackbuf+4               ; Start of font data
+               mov si,trackbuf                 ; Start of font data
                mov [VGAFontSize],bh
                mov di,vgafontbuf
-               mov cx,(32*256) >> 2            ; Maximum size
-               rep movsd
+               mov cx,bx
+               rep movsb
 
                mov [UserFont], byte 1          ; Set font flag
 
-               ; Fall through to use_font
-
 ;
 ; use_font:
 ;      This routine activates whatever font happens to be in the
@@ -92,7 +100,7 @@ use_font:
                shr ax,3                        ; 8 pixels/character
                dec ax
                mov [VidCols],al
-.lf_ret:       ret                             ; No need to call adjust_screen
+               ret                             ; No need to call adjust_screen
 
 .text:
                mov cx,256
@@ -104,8 +112,6 @@ use_font:
                mov ax,1103h                    ; Select page 0
                int 10h
 
-lf_ret         equ use_font.lf_ret
-
 ;
 ; adjust_screen: Set the internal variables associated with the screen size.
 ;              This is a subroutine in case we're loading a custom font.
index 65b657c..973d15b 100644 (file)
@@ -52,9 +52,9 @@ keywd_table:
                keyword initrd,         pc_filename,    InitRD
                keyword default,        pc_default
                keyword display,        pc_opencmd,     get_msg_file
-               keyword font,           pc_filecmd,     loadfont
+               keyword font,           pc_opencmd,     loadfont
                keyword implicit,       pc_setint16,    AllowImplicit
-               keyword kbdmap,         pc_filecmd,     loadkeys
+               keyword kbdmap,         pc_opencmd,     loadkeys
                keyword kernel,         pc_kernel,      VK_KERNEL
                keyword linux,          pc_kernel,      VK_LINUX
                keyword boot,           pc_kernel,      VK_BOOT