syslinux-3.08-2 sources from FC4
[bootcd.git] / syslinux / sample / c32echo.c
1 #ident "$Id: c32echo.c,v 1.3 2005/01/03 08:23:16 hpa Exp $"
2 /* ----------------------------------------------------------------------- *
3  *   
4  *   Copyright 2002 H. Peter Anvin - All Rights Reserved
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9  *   Boston MA 02111-1307, USA; either version 2 of the License, or
10  *   (at your option) any later version; incorporated herein by reference.
11  *
12  * ----------------------------------------------------------------------- */
13
14 /*
15  * c32echo.c
16  *
17  * Simple COM32 program which only prints out its own command line
18  */
19
20 #include <com32.h>
21
22 #define NULL ((void *)0)
23
24 static inline void memset(void *buf, int ch, unsigned int len)
25 {
26   asm volatile("cld; rep; stosb"
27                : "+D" (buf), "+c" (len) : "a" (ch) : "memory");
28 }
29
30 int __start(void)
31 {
32   com32sys_t inreg;
33   const char *p;
34
35   memset(&inreg, 0, sizeof inreg);
36   inreg.eax.b[1] = 0x02;        /* Write Character */
37
38   for ( p = __com32.cs_cmdline ; *p ; p++ ) {
39     inreg.edx.b[0] = *p;
40     __com32.cs_intcall(0x21, &inreg, NULL);
41   }
42
43   inreg.edx.b[0] = '\r';
44   __com32.cs_intcall(0x21, &inreg, NULL);
45   inreg.edx.b[0] = '\n';
46   __com32.cs_intcall(0x21, &inreg, NULL);
47
48   return 0;
49 }