Add gPXE into the source tree; build unified image
[syslinux.git] / sample / filetest.c
blobb4ca2d802fed06705fb06a23ef977f1649f2c0e8
1 #include <com32.h>
2 #include <stdarg.h>
4 #define NULL ((void *)0)
5 int printf(const char *, ...);
6 int putchar(int);
8 static inline void memset(void *buf, int ch, unsigned int len)
10 asm volatile("cld; rep; stosb"
11 : "+D" (buf), "+c" (len) : "a" (ch) : "memory");
14 static void strcpy(char *dst, const char *src)
16 while ( *src )
17 *dst++ = *src++;
19 *dst = '\0';
22 static void printregs(const com32sys_t *r)
24 printf("eflags = %08x ds = %04x es = %04x fs = %04x gs = %04x\n"
25 "eax = %08x ebx = %08x ecx = %08x edx = %08x\n"
26 "ebp = %08x esi = %08x edi = %08x esp = %08x\n",
27 r->eflags.l, r->ds, r->es, r->fs, r->gs,
28 r->eax.l, r->ebx.l, r->ecx.l, r->edx.l,
29 r->ebp.l, r->esi.l, r->edi.l, r->_unused_esp.l);
32 int __start(void)
34 unsigned int ax,cx,si,t;
35 com32sys_t inreg,outreg;
36 char *p;
38 /* Test null system call */
39 inreg.eflags.l = 0xffffffff;
40 inreg.eax.l = 0x11110000;
41 inreg.ecx.l = 0x22222222;
42 inreg.edx.l = 0x33333333;
43 inreg.ebx.l = 0x44444444;
44 inreg.ebp.l = 0x55555555;
45 inreg.esi.l = 0x66666666;
46 inreg.edi.l = 0x77777777;
47 inreg.ds = 0xaaaa;
48 inreg.es = 0xbbbb;
49 inreg.fs = 0xcccc;
50 inreg.gs = 0xdddd;
51 printregs(&inreg);
52 __com32.cs_intcall(0x22, &inreg, &outreg);
53 printregs(&outreg);
54 printf("----\n");
56 memset(&inreg, 0, sizeof inreg);
57 memset(&outreg, 0, sizeof outreg);
58 strcpy(__com32.cs_bounce, "test.txt");
59 inreg.eax.w[0] = 0x0006; // Open file
60 inreg.esi.w[0] = OFFS(__com32.cs_bounce);
61 inreg.es = SEG(__com32.cs_bounce);
62 printregs(&inreg);
63 __com32.cs_intcall(0x22, &inreg, &outreg);
64 printregs(&outreg);
65 printf("----\n");
67 si = outreg.esi.w[0]; /* File handle */
68 cx = outreg.ecx.w[0]; /* Block size */
69 ax = outreg.eax.l; /* File length */
71 while ( si ) {
72 /* We can only read 64K per call */
73 t = ( ax > 65536 ) ? 65536/cx : (ax+cx-1)/cx;
75 memset(&inreg, 0, sizeof inreg);
76 inreg.esi.w[0] = si;
77 inreg.ecx.w[0] = t; /* Block count */
78 inreg.eax.w[0] = 0x0007; // Read file
79 inreg.ebx.w[0] = OFFS(__com32.cs_bounce);
80 inreg.es = SEG(__com32.cs_bounce);
81 printregs(&inreg);
82 __com32.cs_intcall(0x22, &inreg, &outreg);
83 printregs(&outreg);
84 printf("----\n");
85 si = outreg.esi.w[0];
87 /* Print the buffer */
88 t = (ax < 65536) ? ax : 65536;
89 p = __com32.cs_bounce;
90 while ( t ) {
91 putchar(*p++);
92 t--;
93 ax--;
97 return 0;