1 ! Mkfhead.s
- DOS
& BIOS support for mkfile.c Author
: Kees J. Bot
4 ! This file contains the startup
and low level support for the MKFILE.COM
5 ! utility. See doshead.ack.s for more comments on
.COM files.
7 .sect .text; .sect .rom; .sect .data; .sect .bss
12 .space 256 ! Program Segment Prefix
15 cld
! C compiler wants UP
17 mov di
, _edata
! Start of bss is at end of data
18 mov cx
, _end
! End of bss
(begin of heap
)
19 sub cx
, di
! Number of bss bytes
20 shr cx
, 1 ! Number of words
23 xor cx
, cx
! cx
= argc
25 push bx
! argv
[argc
] = NULL
26 movb
bl, (_PSP+
0x80) ! Argument byte count
27 0: movb _PSP+
0x81(bx
), ch
! Null terminate
30 cmpb _PSP+
0x81(bx
), 0x20 ! Whitespace?
32 1: dec bx
! One argument character
34 cmpb _PSP+
0x81(bx
), 0x20 ! More argument characters?
36 2: lea ax
, _PSP+
0x81+1(bx
) ! Address of argument
40 jns
0b ! More arguments?
41 9: movb _PSP+
0x81(bx
), ch
! Make
a null string
43 push ax
! to use as argv
[0]
44 inc cx
! Final value of argc
48 call _main
! main
(argc
, argv
)
50 call _exit
! exit
(main
(argc
, argv
))
52 ! int creat
(const char
*path
, mode_t mode
)
53 ! Create
a file with the old creat
() call.
57 mov dx
, 2(bx
) ! Filename
58 xor cx
, cx
! Ignore mode
, always read-write
59 movb ah
, 0x3C ! "CREAT"
60 dos
: int
0x21 ! ax
= creat
(path
, 0666);
65 mov
(_errno
), ax
! Set errno to the DOS error code
70 ! int open
(const char
*path
, int oflag
)
71 ! Open
a file with the oldfashioned two-argument open
() call.
75 mov dx
, 2(bx
) ! Filename
76 movb al
, 4(bx
) ! O_RDONLY
, O_WRONLY
, O_RDWR
77 movb ah
, 0x3D ! "OPEN"
85 mov bx
, 2(bx
) ! bx
= file handle
86 movb ah
, 0x3E ! "CLOSE"
89 ! void exit
(int status
)
90 ! void _exit
(int status
)
92 .define _exit, __exit, ___exit
98 movb ah
, 0x4C ! "EXIT"
102 ! ssize_t read
(int
fd, void
*buf
, size_t n
)
103 ! Read bytes from an open file.
110 movb ah
, 0x3F ! "READ"
113 ! ssize_t write
(int
fd, const void
*buf
, size_t n
)
114 ! Write bytes to an open file.
121 movb ah
, 0x40 ! "WRITE"
124 ! off_t lseek
(int
fd, off_t offset
, int whence
)
125 ! Set file position for read
or write.
129 movb al
, 8(bx
) ! SEEK_SET
, SEEK_CUR
, SEEK_END
131 mov cx
, 6(bx
) ! cx
:dx
= offset
133 movb ah
, 0x42 ! "LSEEK"
137 ! $PchId
: mkfhead.ack.s
,v
1.3 1999/01/14 21:17:06 philip Exp $