Fix COMBOOT/COM32 command-line generation.
authorhpa <hpa>
Mon, 24 Nov 2003 02:44:42 +0000 (02:44 +0000)
committerhpa <hpa>
Mon, 24 Nov 2003 02:44:42 +0000 (02:44 +0000)
Add test programs.

12 files changed:
BUGS
NEWS
cmdline.inc [new file with mode: 0644]
com32.inc
comboot.doc
comboot.inc
isolinux.asm
ldlinux.asm
pxelinux.asm
sample/Makefile
sample/c32echo.c [new file with mode: 0644]
sample/comecho.asm [new file with mode: 0644]

diff --git a/BUGS b/BUGS
index a3ccc7f..9639da8 100644 (file)
--- a/BUGS
+++ b/BUGS
@@ -1,6 +1,4 @@
 Known bugs that have not yet been fixed:
 
-- APPEND doesn't work with COMBOOT/COM32 images.
-
 - PXELINUX: Some PXE stacks fail with routing enabled, some with
   routing disabled.  Try both?
diff --git a/NEWS b/NEWS
index fde4a47..c796e80 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,8 @@ them.
 Changes in 2.08:
        * Add "timeoutcmd" to allow timeout to have a different action
          than just pressing Enter.
+       * Fix bugs in the COMBOOT/COM32 command-line parsing.  APPEND
+         now works with COMBOOT/COM32 images.
 
 Changes in 2.07:
        * MEMDISK: Workaround for BIOSes which go into a snit when
diff --git a/cmdline.inc b/cmdline.inc
new file mode 100644 (file)
index 0000000..11a81e3
--- /dev/null
@@ -0,0 +1,44 @@
+;; $Id$
+;; -----------------------------------------------------------------------
+;;   
+;;   Copyright 2003 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,
+;;   Bostom MA 02111-1307, USA; either version 2 of the License, or
+;;   (at your option) any later version; incorporated herein by reference.
+;;
+;; -----------------------------------------------------------------------
+
+;;
+;; cmdline.inc
+;;
+;; Common routine to assemble [null-terminated] command line into
+;; real_mode_seg:cmd_line_here.
+;; Not used by plain kernel due to BOOT_IMAGE= etc.
+;;
+
+;
+; Assumes DS == CS
+make_plain_cmdline:
+               push es
+               ; ui.inc has already copied the actual command line
+               mov ax,real_mode_seg
+               mov es,ax
+
+               mov si,[CmdOptPtr]
+               mov di,[CmdLinePtr]
+               
+.loop:         lodsb
+               stosb
+               and al,al
+               jnz .loop
+
+               dec di
+               mov [CmdLinePtr],di
+
+               pop es
+               ret
+
+
index 59d1cb8..d0bfb3e 100644 (file)
--- a/com32.inc
+++ b/com32.inc
@@ -41,6 +41,19 @@ com32_rmidt:
                dd 0                    ; Address
 
 is_com32_image:
+               push si                 ; Save file handle
+
+               call make_plain_cmdline
+               ; Copy the command line into the low cmdline buffer
+               mov ax,real_mode_seg
+               mov fs,ax
+               mov si,cmd_line_here
+               mov di,command_line
+               mov cx,[CmdLinePtr]
+               inc cx                  ; Include final null
+               sub cx,si
+               fs rep movsb
+
                call highmemsize        ; We need the high memory size...
                call comboot_setup_api  ; Set up the COMBOOT-style API
 
@@ -48,6 +61,7 @@ is_com32_image:
                xchg eax,edx            ; Gotta fix this insanity...
                shl eax,16
                mov ax,dx
+               pop si                  ; File handle
                call load_high
                call crlf
 
@@ -146,8 +160,7 @@ com32_call_start:
                push dword (1 << 16)            ; 64K bounce buffer
                push dword (comboot_seg << 4)   ; Bounce buffer address
                push dword com32_intcall        ; Intcall entry point
-               movzx esi,word [word CmdOptPtr]
-               push esi                        ; Command line pointer
+               push dword command_line         ; Command line pointer
                push dword 5                    ; Argument count
                sti                             ; Interrupts OK now
                call pm_entry                   ; Run the program...
index 89fe6e4..5d1a954 100644 (file)
@@ -179,6 +179,10 @@ INT 21h AH=08h     Get Key without Echo
        Reads a key fron the console input, without echoing it to the
        console output.  The read character is returned in AL.
 
+INT 21h AH=09h Write DOS String to Console
+
+       Writes a DOS $-terminated string in DS:DX to the console.
+
 INT 21h AH=0Bh Check Keyboard
 
        Returns AL=FFh if there is a keystroke waiting (which can then
index 454d42c..c8dbff1 100644 (file)
@@ -75,16 +75,15 @@ is_comboot_image:
                cmp ax,0ff00h           ; Max size in bytes
                jae comboot_too_large
 
+               push si                 ; Save file handle
+
+               call make_plain_cmdline
+
                call comboot_setup_api
 
                mov cx,comboot_seg
                mov es,cx
 
-               mov bx,100h             ; Load at <seg>:0100h
-
-               mov cx,[ClustPerMoby]   ; Absolute maximum # of clusters
-               call getfssec
-
                xor di,di
                mov cx,64               ; 256 bytes (size of PSP)
                xor eax,eax             ; Clear PSP
@@ -104,23 +103,32 @@ is_comboot_image:
 %endif
 %endif
                ; Copy the command line from high memory
+               mov si,cmd_line_here
                mov cx,125              ; Max cmdline len (minus space and CR)
-               mov si,[CmdOptPtr]
                mov di,081h             ; Offset in PSP for command line
                mov al,' '              ; DOS command lines begin with a space
                stosb
 
-comboot_cmd_cp:        es lodsb
+.loop:         es lodsb
                and al,al
-               jz comboot_end_cmd
+               jz .done
                stosb
-               loop comboot_cmd_cp
-comboot_end_cmd: mov al,0Dh            ; CR after last character
+               loop .loop
+.done:
+
+               mov al,0Dh              ; CR after last character
                stosb
-               mov al,126              ; Include space but not CR
-               sub al,cl
-               mov [es:80h], al        ; Store command line length
+               mov ax,di
+               sub al,82h              ; Include space but not CR
+               mov [es:80h],al         ; Store command line length
+
+               ; Now actually load the file...
+               pop si                  ; File handle
+               mov bx,100h             ; Load at <seg>:0100h
+               mov cx,[ClustPerMoby]   ; Absolute maximum # of clusters
+               call getfssec
 
+               ; And invoke the program...
                mov [SavedSSSP],sp
                mov [SavedSSSP+2],ss    ; Save away SS:SP
 
index 51d9468..7b92fd4 100644 (file)
@@ -860,6 +860,7 @@ load_config:
 ;
 %include "comboot.inc"
 %include "com32.inc"
+%include "cmdline.inc"
 
 ;
 ; Boot sector loading code
index c8faa60..b39c905 100644 (file)
@@ -1059,6 +1059,7 @@ mkkeymap: stosb
 ;
 %include "comboot.inc"
 %include "com32.inc"
+%include "cmdline.inc"
 
 ;
 ; Boot sector loading code
index b8aa92d..fd2877a 100644 (file)
@@ -928,6 +928,7 @@ config_scan:
 ;
 %include "comboot.inc"
 %include "com32.inc"
+%include "cmdline.inc"
 
 ;
 ; Boot sector loading code
index 0d23c98..373828c 100644 (file)
@@ -18,6 +18,7 @@
 CC         = gcc
 LD         = ld
 AR        = ar
+NASM      = nasm
 RANLIB    = ranlib
 CFLAGS     = -march=i386 -O2 -fomit-frame-pointer -I../com32/include
 SFLAGS     = -march=i386
@@ -30,7 +31,7 @@ LIBOBJS          = conio.o
 
 .SUFFIXES: .lss .c .o .elf .c32
 
-all: syslogo.lss hello.c32 hello2.c32 filetest.c32
+all: syslogo.lss comecho.com hello.c32 hello2.c32 filetest.c32 c32echo.c32
 
 %.o: %.S
        $(CC) $(SFLAGS) -c -o $@ $<
@@ -44,6 +45,9 @@ all: syslogo.lss hello.c32 hello2.c32 filetest.c32
 %.c32: %.elf
        $(OBJCOPY) -O binary $< $@
 
+%.com: %.asm
+       $(NASM) -f bin -o $@ -l $*.lst $<
+
 $(LIB): $(LIBOBJS)
        rm -f $@
        $(AR) cq $@ $^
diff --git a/sample/c32echo.c b/sample/c32echo.c
new file mode 100644 (file)
index 0000000..9733d41
--- /dev/null
@@ -0,0 +1,49 @@
+#ident "$Id$"
+/* ----------------------------------------------------------------------- *
+ *   
+ *   Copyright 2002 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,
+ *   Bostom MA 02111-1307, USA; either version 2 of the License, or
+ *   (at your option) any later version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * c32echo.c
+ *
+ * Simple COM32 program which only prints out its own command line
+ */
+
+#include <com32.h>
+
+#define NULL ((void *)0)
+
+static inline void memset(void *buf, int ch, unsigned int len)
+{
+  asm volatile("cld; rep; stosb"
+              : "+D" (buf), "+c" (len) : "a" (ch) : "memory");
+}
+
+int __start(void)
+{
+  com32sys_t inreg, outreg;
+  const char *p;
+
+  memset(&inreg, 0, sizeof inreg);
+  inreg.eax.b[1] = 0x02;       /* Write Character */
+
+  for ( p = __com32.cs_cmdline ; *p ; p++ ) {
+    inreg.edx.b[0] = *p;
+    __com32.cs_intcall(0x21, &inreg, NULL);
+  }
+
+  inreg.edx.b[0] = '\r';
+  __com32.cs_intcall(0x21, &inreg, NULL);
+  inreg.edx.b[0] = '\n';
+  __com32.cs_intcall(0x21, &inreg, NULL);
+
+  return 0;
+}
diff --git a/sample/comecho.asm b/sample/comecho.asm
new file mode 100644 (file)
index 0000000..3cdf601
--- /dev/null
@@ -0,0 +1,35 @@
+;
+; Simple COMBOOT program that just prints out its own command line.
+; This also works in DOS.
+;
+
+       org 100h
+
+_start:
+       xor cx,cx
+       mov cl,[80h]                    ; Command line len
+       mov si,81h                      ; Command line
+
+       mov dl,"<"
+       mov ah,02h
+       int 21h
+       
+.writechar:
+       lodsb
+       mov dl,al
+       mov ah,02h
+       int 21h
+       loop .writechar
+
+       mov dx,end_str
+       mov ah,09h
+       int 21h
+
+       ; Exit with near return, INT 20h, or INT 21h AX=4C00h
+       ret
+       
+               
+end_str        db ">", 0Dh, 0Ah, "$"
+       
+       
+       
\ No newline at end of file