Fix the COM32 sample program
authorhpa <hpa>
Mon, 18 Nov 2002 22:22:37 +0000 (22:22 +0000)
committerhpa <hpa>
Mon, 18 Nov 2002 22:22:37 +0000 (22:22 +0000)
NEWS
com32/include/com32.h
comboot.doc
sample/Makefile
sample/c32entry.S [new file with mode: 0644]
sample/hello.c

diff --git a/NEWS b/NEWS
index 42bd36f..b18f1c5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ Changes in 2.01:
        * Update the mkdiskimage script to handle newer mtools
          versions, and be able to generate disk images with DOSEMU
          headers (controlled by the -d option).
+       * Fix the COM32 sample program.
 
 Changes in 2.00:
        * ALL: Add support for "COM32" (32-bit COMBOOT) images.
index 4b7266f..a56cc69 100644 (file)
@@ -46,11 +46,12 @@ typedef struct {
   reg32_t eflags;              /* Offset 40 */
 } com32sys_t;
 
-/* The standard prototype for _start() */
-int _start(unsigned int __nargs,
-          char *__cmdline,
-          void (*__syscall)(uint8_t, com32sys_t *, com32sys_t *),
-          void *__bounce_ptr,
-          unsigned int __bounce_len);
+extern struct com32_sys_args {
+  uint32_t cs_sysargs;
+  char *cs_cmdline;
+  void (*cs_syscall)(uint8_t, com32sys_t *, com32sys_t *);
+  void *cs_bounce;
+  uint32_t cs_bounce_size;
+} __com32;
 
 #endif /* _COM32_H */
index 43c80f9..f775313 100644 (file)
@@ -62,6 +62,9 @@ be possible to create a COM32 execution engine that would run under
 something like Linux DOSEMU, it is recommended that the code does not
 assume CPL 0 unless absolutely necessary.
 
+It is highly recommended that every COM32 program begins with the byte
+sequence B8 FF 4C CD 21 (mov eax,21cd4cffh) as a magic number.
+
 A COM32 file should have extension ".c32".
 
 On startup, CS will be set up as a flat 32-bit code segment, and DS ==
index 58d6d05..54fdb09 100644 (file)
@@ -18,6 +18,7 @@
 CC         = gcc
 LD         = ld
 CFLAGS     = -march=i386 -O2 -fomit-frame-pointer -I../com32/include
+SFLAGS     = -march=i386
 LDFLAGS    = -s
 OBJCOPY    = objcopy
 PPMTOLSS16 =   ../ppmtolss16
@@ -26,10 +27,16 @@ PPMTOLSS16 =        ../ppmtolss16
 
 all: syslogo.lss hello.c32
 
-.c.o:
+%.o: %.S
+       $(CC) $(SFLAGS) -c -o $@ $<
+
+%.o: %.c
        $(CC) $(CFLAGS) -c -o $@ $<
 
-.elf.c32:
+%.elf: c32entry.o %.o
+       $(LD) -Ttext 0x101000 -e _start -o $@ $^
+
+%.c32: %.elf
        $(OBJCOPY) -O binary $< $@
 
 syslogo.lss:   syslogo.png $(PPMTOLSS16)
@@ -37,9 +44,6 @@ syslogo.lss:  syslogo.png $(PPMTOLSS16)
                $(PPMTOLSS16) \#000000=0 \#d0d0d0=7 \#f6f6f6=15 \
                > syslogo.lss
 
-hello.elf: hello.o
-       $(LD) -Ttext 0x101000 -e _start -o $@ $<
-
 clean:
        rm -f *.lss *.o *.elf *.c32
 
diff --git a/sample/c32entry.S b/sample/c32entry.S
new file mode 100644 (file)
index 0000000..f1c476c
--- /dev/null
@@ -0,0 +1,14 @@
+               .section ".text","ax"
+               .globl _start
+_start:
+               movl $0x21cd4cff,%eax
+               leal 4(%esp),%esi
+               movl $__com32,%edi
+               mov $5,%ecx
+               cld
+               rep ; movsl
+               jmp __start
+
+               .section ".bss","a"
+               .globl __com32
+__com32:       .space 20
index bb8bbfa..a2b79dd 100644 (file)
@@ -27,9 +27,7 @@ static inline void memset(void *buf, int ch, unsigned int len)
               : "+D" (buf), "+c" (len) : "a" (ch) : "memory");
 }
 
-int _start(unsigned int nargs, char *cmdline,
-          void (*syscall)(unsigned char, com32sys_t *, com32sys_t *),
-          void *bounce_ptr, unsigned int bounce_len)
+int __start(void)
 {
   const char *msg = "Hello, World!\r\n";
   com32sys_t inreg, outreg;
@@ -40,7 +38,7 @@ int _start(unsigned int nargs, char *cmdline,
   for ( p = msg ; *p ; p++ ) {
     inreg.edx.b[0] = *p;
     inreg.eax.b[1] = 0x02;     /* Write Character */
-    syscall(0x21, &inreg, NULL);
+    __com32.cs_syscall(0x21, &inreg, NULL);
   }
 
   return 0;