1 /* Copyright (C) 1996 Robert de Bath <robert@mayday.compulink.co.uk>
2 * This file is part of the Linux-8086 C library and is distributed
3 * under the GNU Library General Public License.
6 /* Modified 14-Jan-2002 by John Coffman <johninsd@san.rr.com> for inclusion
7 * in the set of LILO diagnostics. This code is the property of Robert
8 * de Bath, and is used with his permission.
14 #if !__FIRST_ARG_IN_AX__
24 char ** environ = { 0 };
27 void (*__cleanup)() = 0;
33 .word 0,0,0,0,0,0,0,0 ! A struct REGS
36 .word 0,0,0,0 ! A struct SREGS
48 .word 0,0 ! dirty area if startup SS & SP are to be seen
50 export ___cstartup ! Crt0 startup
55 cmp word ptr [0],#$20CD ! "int 20h" at psp: ES:0000
57 push ax ! DOS provides us a stack
59 add ax,#$10 ! bump CS by 0x10
61 mov ax,#is_dos ! resume address
63 retf ! continue at next instruction
65 pop ax ! restore saved AX
67 mov word ptr [iret_ins-2],es ! patch return to int 20h exit
74 mov [sssp_save+2],ss ! save startup SS:SP
84 push [sssp_save+2] ! startup SS
93 push [sssp_save] ! startup SP to flags
95 pushf ! to flags, but why?
99 push di ! save the startup registers
100 push si ! pushes are shorter than mov mem,reg
106 xor sp,sp ! maximum stack
107 push bp ! perhaps bp should be zeroed first
108 sti ! now turn on interrupts
110 push ss ! set up the ES and DS
111 pop ds ! equal to the SS
113 zap_bss: ! Clear the BSS
125 mov ax,#defarg ! Don`t define __mkargv, standalone programs don`t
126 push ax ! get any arguments.
130 mov bx,#auto_start ! Pointer to first autostart function
136 call bx ! Call the function
141 jmp auto_run ! And round for the next.
143 call_exit: ! Last item called by above.
145 push ax ! At the end the last called was main() push it`s
146 call _exit ! return val and call exit();
148 jmp bad_exit ! Exit returned !!
151 .word _main ! Segment 2 is the trailing pointers, main and the
152 .word call_exit ! routine to call exit.
157 _exit: ! exit(rv) function
159 push [bx+2] ! Copy the `rv` for the exit fuctions.
160 mov bx,[___cleanup] ! Call exit, normally this is `__do_exit`
162 je no_clean ! But it`s default is null
175 mov [$E6*4],#iret_ins
177 int $E6 ! Try to exit DOSEMU
178 ! If we get here we`re not in dosemu.
180 mov [$472],#$1234 ! Warm reboot.
182 jmpi $0000,$FFFF ! DO NOT SEPARATE
183 iret_ins: ! THIS LABEL FROM THE jmpi ...
184 iret ! interrupt return!! not retf (==reti)
186 export ___mkargv ! must resolve this reference
194 /****************************************************************************/
202 if(fd == 1 || fd == 2)
207 if( c == '\n') bios_putc('\r');
212 return (*__files)(CMD_WRITE, fd, buf, len);
216 /****************************************************************************/
223 if(fd == 0) return bios_rdline(buf, len);
224 return (*__files)(CMD_READ, fd, buf, len);
228 /****************************************************************************/
232 lseek(fd, offt, whence)
236 if( fd >= 0 && fd <= 2 ) errno = ESPIPE;
239 if( (*__files)(CMD_LSEEK, fd, &offt, whence) >= 0 )
246 /****************************************************************************/
252 if( fd >= 0 && fd <= 2 ) errno = ENOSYS;
254 return (*__files)(CMD_CLOSE, fd);
259 /****************************************************************************/
261 #ifdef L_bios_nofiles
262 int (*__files)() = __nofiles;
264 int __nofiles(cmd, fd, buf, len)
274 /****************************************************************************/
280 if( fd >= 0 && fd <= 2 ) return 1;
285 /****************************************************************************/