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.
8 #if !__FIRST_ARG_IN_AX__
18 char ** environ
= { 0 };
21 void (*__cleanup
)() = 0;
27 .word
0,0,0,0,0,0,0,0 ! A
struct REGS
: ax
, bx
, cx
, dx
, si
, di
, cflag
, flags
36 export ___cstartup
! Crt0 startup
39 #ifndef AOUT_STANDALONE
41 cmp word ptr
[0],#$20CD ! "int 20h" at psp: CS:0000
44 ! DOS
- only AX has a defined value
.
45 ! All the segment registers are pointing at the PSP
46 ! SP points to the top of the segment so is probably useable
.
50 add ax
,#$10 ! bump CS by 0x10
52 mov ax
,#is_dos ! resume address
54 retf
! continue at next instruction
56 .word
0 ! Set to
1 if DOS
60 pop ax
! restore saved AX
70 push
[dos_flag
] ! Set the carry flag
if we
're under DOS.
84 zap_bss: ! Clear the BSS
86 pop es ! ES now data seg
95 !mov bp,ax ! Top frame pointer, only needed if we get a debugger
97 mov ax,#defarg ! Don`t define __mkargv, standalone programs don`t
98 push ax ! get any arguments.
102 mov bx,#auto_start ! Pointer to first autostart function
108 call bx ! Call the function
113 jmp auto_run ! And round for the next.
115 call_exit: ! Last item called by above.
117 push ax ! At the end the last called was main() push it`s
118 call _exit ! return val and call exit();
120 jmp bad_exit ! Exit returned !!
123 .word _main ! Segment 2 is the trailing pointers, main and the
124 .word call_exit ! routine to call exit.
129 _exit: ! exit(rv) function
131 push [bx+2] ! Copy the `rv` for the exit fuctions.
132 mov bx,[___cleanup] ! Call exit, normally this is `__do_exit`
134 je no_clean ! But it`s default is null
142 #ifndef AOUT_STANDALONE
144 cmp [dos_flag],#0 ! Should we do a DOS exit
157 int $E6 ! Try to exit DOSEMU
158 ! If we get here we`re not in dosemu.
159 mov [$472],#$1234 ! Warm reboot.
168 /****************************************************************************/
176 if(fd == 1 || fd == 2)
185 return (*__files)(CMD_WRITE, fd, buf, len);
189 /****************************************************************************/
196 if(fd == 0) return bios_rdline(buf, len);
197 return (*__files)(CMD_READ, fd, buf, len);
201 /****************************************************************************/
205 lseek(fd, offt, whence)
209 if( fd >= 0 && fd <= 2 ) errno = ESPIPE;
212 if( (*__files)(CMD_LSEEK, fd, &offt, whence) >= 0 )
219 /****************************************************************************/
225 if( fd >= 0 && fd <= 2 ) errno = ENOSYS;
227 return (*__files)(CMD_CLOSE, fd);
232 /****************************************************************************/
234 #ifdef L_bios_nofiles
235 int (*__files)() = __nofiles;
237 int __nofiles(cmd, fd, buf, len)
247 /****************************************************************************/
253 if( fd >= 0 && fd <= 2 ) return 1;
258 /****************************************************************************/
263 static const char msg[] = "Program aborted, press return:";
264 write(2, msg, sizeof(msg)-1);
271 /****************************************************************************/