core: Reimplement writestr in C
authorMatt Fleming <matt.fleming@intel.com>
Wed, 19 Oct 2011 09:02:42 +0000 (10:02 +0100)
committerMatt Fleming <matt.fleming@intel.com>
Thu, 1 Dec 2011 13:14:07 +0000 (13:14 +0000)
Implement writestr in C instead of asm and move writestr.inc into
modules/ because it's required by modules/ver.asm.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
core/isolinux.asm
core/pxelinux.asm
core/rawcon.inc [deleted file]
core/writestr.c [new file with mode: 0644]
modules/ver.asm
modules/writestr.inc [moved from core/writestr.inc with 100% similarity]

index b0b21a3..8757c0f 100644 (file)
@@ -286,7 +286,7 @@ initial_csum:       xor edi,edi
                call writemsg
                mov al,dl
                call writehex2
-               call crlf
+               call crlf_early
 %endif
                ;
                ; Initialize spec packet buffers
@@ -326,7 +326,7 @@ initial_csum:       xor edi,edi
                call writemsg
                mov al,byte [sp_drive]
                call writehex2
-               call crlf
+               call crlf_early
 %endif
 
 found_drive:
@@ -393,7 +393,7 @@ found_file:
                mov si,offset_msg
                call writemsg
                call writehex8
-               call crlf
+               call crlf_early
 %endif
 
                ; Load the rest of the file.  However, just in case there
@@ -623,7 +623,7 @@ spec_query_failed:
                call writemsg
                mov al,dl
                call writehex2
-               call crlf
+               call crlf_early
 
                cmp byte [sp_drive],dl
                jne .maybe_broken
@@ -667,7 +667,7 @@ spec_query_failed:
                call writemsg
                mov al,dl
                call writehex2
-               call crlf
+               call crlf_early
                mov si,trysbm_msg
                call writemsg
                jmp .found_drive                ; Pray that this works...
@@ -690,6 +690,26 @@ writemsg:  push ax
                pop ax
                ret
 
+writestr_early:
+               pushfd
+               pushad
+.top:          lodsb
+               and al,al
+               jz .end
+               call writechr
+               jmp short .top
+.end:          popad
+               popfd
+               ret
+
+crlf_early:    push ax
+               mov al,CR
+               call writechr
+               mov al,LF
+               call writechr
+               pop ax
+               ret
+
 ;
 ; Write a character to the screen.  There is a more "sophisticated"
 ; version of this in the subsequent code, so we patch the pointer
@@ -1004,7 +1024,7 @@ xint13:           mov byte [RetryCount],retry_count
                call writestr_early
                mov al,dl
                call writehex2
-               call crlf
+               call crlf_early
                ; Fall through to kaboom
 
 ;
@@ -1016,8 +1036,8 @@ disk_error:
 kaboom:
                RESET_STACK_AND_SEGS AX
                mov si,err_bootfailed
-               call writestr
-               call getchar
+               pm_call pm_writestr
+               pm_call pm_getchar
                cli
                mov word [BIOS_magic],0 ; Cold reboot
                jmp 0F000h:0FFF0h       ; Reset vector address
@@ -1026,8 +1046,6 @@ kaboom:
 ;  Common modules needed in the first sector
 ; -----------------------------------------------------------------------------
 
-%include "writestr.inc"                ; String output
-writestr_early equ writestr
 %include "writehex.inc"                ; Hexadecimal output
 
 ; -----------------------------------------------------------------------------
@@ -1106,18 +1124,10 @@ all_read:
 ;
 %include "init.inc"
 
-               ; Patch the writechr routine to point to the full code
-               mov di,writechr
-               mov al,0e9h
-               stosb
-               mov ax,writechr_full-2
-               sub ax,di
-               stosw
-
 ; Tell the user we got this far...
 %ifndef DEBUG_MESSAGES                 ; Gets messy with debugging on
                mov si,copyright_str
-               call writestr_early
+               pm_call pm_writestr
 %endif
 
 ;
index 8a95d1e..178e354 100644 (file)
@@ -343,7 +343,7 @@ kaboom:
                pop cx
                loop .wait1
 .keypress:
-               call crlf
+               pm_call crlf
                mov word [BIOS_magic],0 ; Cold reboot
                jmp 0F000h:0FFF0h       ; Reset vector address
 
diff --git a/core/rawcon.inc b/core/rawcon.inc
deleted file mode 100644 (file)
index f0d434c..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-;
-; writechr:    Write a single character in AL to the console without
-;              mangling any registers.  This does raw console writes,
-;              since some PXE BIOSes seem to interfere regular console I/O.
-;
-%if IS_ISOLINUX
-writechr_full:
-%else
-writechr:
-%endif
-               pushfd
-               push ds
-               push cs
-               pop ds
-               test byte [UsingVGA], 08h
-               jz .videook
-               call vgaclearmode
-.videook:
-               call write_serial       ; write to serial port if needed
-               test byte [DisplayCon],01h      ; Write to screen?
-               jz .nothing
-
-               pushad
-               mov bh,[BIOS_page]
-               push ax
-                mov ah,03h              ; Read cursor position
-                int 10h
-               pop ax
-               cmp al,8
-               je .bs
-               cmp al,13
-               je .cr
-               cmp al,10
-               je .lf
-               push dx
-                mov bh,[BIOS_page]
-               mov bl,07h              ; White on black
-               mov cx,1                ; One only
-               mov ah,09h              ; Write char and attribute
-               int 10h
-               pop dx
-               inc dl
-               cmp dl,[VidCols]
-               jna .curxyok
-               xor dl,dl
-.lf:           inc dh
-               cmp dh,[VidRows]
-               ja .scroll
-.curxyok:      mov bh,[BIOS_page]
-               mov ah,02h              ; Set cursor position
-               int 10h
-.ret:          popad
-.nothing:
-               pop ds
-               popfd
-               ret
-.scroll:       dec dh
-               mov bh,[BIOS_page]
-               mov ah,02h
-               int 10h
-               mov ax,0601h            ; Scroll up one line
-               mov bh,[ScrollAttribute]
-               xor cx,cx
-               mov dx,[ScreenSize]     ; The whole screen
-               int 10h
-               jmp short .ret
-.cr:           xor dl,dl
-               jmp short .curxyok
-.bs:           sub dl,1
-               jnc .curxyok
-               mov dl,[VidCols]
-               sub dh,1
-               jnc .curxyok
-               xor dh,dh
-               jmp short .curxyok
diff --git a/core/writestr.c b/core/writestr.c
new file mode 100644 (file)
index 0000000..66d126a
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * -----------------------------------------------------------------------
+ *
+ *   Copyright 1994-2008 H. Peter Anvin - All Rights Reserved
+ *
+ *   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
+ *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
+ *   Boston MA 02111-1307, USA; either version 2 of the License, or
+ *   (at your option) any later version; incorporated herein by reference.
+ *
+ * -----------------------------------------------------------------------
+ *
+ *
+ * writestr.c
+ *
+ * Code to write a simple string.
+ */
+#include <com32.h>
+
+/*
+ * crlf: Print a newline
+ */
+void crlf(void)
+{
+       writechr('\r');
+       writechr('\n');
+}
+
+/*
+ * writestr: write a null-terminated string to the console, saving
+ *            registers on entry.
+ *
+ * Note: writestr_early and writestr are distinct in
+ * SYSLINUX and EXTLINUX, but not PXELINUX and ISOLINUX
+ */
+void writestr(char *str)
+{
+       while (*str)
+               writechr(*str++);
+}
+
+void pm_writestr(com32sys_t *regs)
+{
+       writestr(MK_PTR(regs->ds, regs->esi.w[0]));
+}
index 8ef63fa..600def0 100644 (file)
@@ -565,7 +565,7 @@ is_zf:
                ret
 
 %include "../core/macros.inc"          ; CR/LF
-%include "../core/writestr.inc"                ; String output
+%include "writestr.inc"                        ; String output
 %include "../core/writehex.inc"                ; Hexadecimal output
 %include "../core/writedec.inc"                ; Decimal output
 
similarity index 100%
rename from core/writestr.inc
rename to modules/writestr.inc