From: hpa Date: Mon, 18 Nov 2002 22:22:37 +0000 (+0000) Subject: Fix the COM32 sample program X-Git-Tag: syslinux-3.11~636 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b918509b86a1d65427fe9270886c41b5d0491344;p=platform%2Fupstream%2Fsyslinux.git Fix the COM32 sample program --- diff --git a/NEWS b/NEWS index 42bd36f..b18f1c5 100644 --- 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. diff --git a/com32/include/com32.h b/com32/include/com32.h index 4b7266f..a56cc69 100644 --- a/com32/include/com32.h +++ b/com32/include/com32.h @@ -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 */ diff --git a/comboot.doc b/comboot.doc index 43c80f9..f775313 100644 --- a/comboot.doc +++ b/comboot.doc @@ -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 == diff --git a/sample/Makefile b/sample/Makefile index 58d6d05..54fdb09 100644 --- a/sample/Makefile +++ b/sample/Makefile @@ -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 index 0000000..f1c476c --- /dev/null +++ b/sample/c32entry.S @@ -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 diff --git a/sample/hello.c b/sample/hello.c index bb8bbfa..a2b79dd 100644 --- a/sample/hello.c +++ b/sample/hello.c @@ -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;