little more info in pagefault exception handler.
[minix.git] / boot / mkfhead.s
blob221e1faea940ace9046f1f9e7df6fdb36b7e8062
1 ! Mkfhead.s - DOS & BIOS support for mkfile.c Author: Kees J. Bot
2 ! 9 May 1998
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
8 .sect .text
10 .define _PSP
11 _PSP:
12 .space 256 ! Program Segment Prefix
14 mkfile:
15 cld ! C compiler wants UP
16 xor ax, ax ! Zero
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
21 rep stos ! Clear bss
23 xor cx, cx ! cx = argc
24 xor bx, bx
25 push bx ! argv[argc] = NULL
26 movb bl, (_PSP+0x80) ! Argument byte count
27 0: movb _PSP+0x81(bx), ch ! Null terminate
28 dec bx
29 js 9f
30 cmpb _PSP+0x81(bx), 0x20 ! Whitespace?
31 jbe 0b
32 1: dec bx ! One argument character
33 js 2f
34 cmpb _PSP+0x81(bx), 0x20 ! More argument characters?
35 ja 1b
36 2: lea ax, _PSP+0x81+1(bx) ! Address of argument
37 push ax ! argv[n]
38 inc cx ! argc++;
39 test bx, bx
40 jns 0b ! More arguments?
41 9: movb _PSP+0x81(bx), ch ! Make a null string
42 lea ax, _PSP+0x81(bx)
43 push ax ! to use as argv[0]
44 inc cx ! Final value of argc
45 mov ax, sp
46 push ax ! argv
47 push cx ! argc
48 call _main ! main(argc, argv)
49 push ax
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.
54 .define _creat
55 _creat:
56 mov bx, sp
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);
61 jc seterrno
62 ret
64 seterrno:
65 mov (_errno), ax ! Set errno to the DOS error code
66 mov ax, -1
67 cwd ! return -1L;
68 ret
70 ! int open(const char *path, int oflag)
71 ! Open a file with the oldfashioned two-argument open() call.
72 .define _open
73 _open:
74 mov bx, sp
75 mov dx, 2(bx) ! Filename
76 movb al, 4(bx) ! O_RDONLY, O_WRONLY, O_RDWR
77 movb ah, 0x3D ! "OPEN"
78 jmp dos
80 ! int close(int fd)
81 ! Close an open file.
82 .define _close
83 _close:
84 mov bx, sp
85 mov bx, 2(bx) ! bx = file handle
86 movb ah, 0x3E ! "CLOSE"
87 jmp dos
89 ! void exit(int status)
90 ! void _exit(int status)
91 ! Return to DOS.
92 .define _exit, __exit, ___exit
93 _exit:
94 __exit:
95 ___exit:
96 pop ax
97 pop ax ! al = status
98 movb ah, 0x4C ! "EXIT"
99 int 0x21
102 ! ssize_t read(int fd, void *buf, size_t n)
103 ! Read bytes from an open file.
104 .define _read
105 _read:
106 mov bx, sp
107 mov cx, 6(bx)
108 mov dx, 4(bx)
109 mov bx, 2(bx)
110 movb ah, 0x3F ! "READ"
111 jmp dos
113 ! ssize_t write(int fd, const void *buf, size_t n)
114 ! Write bytes to an open file.
115 .define _write
116 _write:
117 mov bx, sp
118 mov cx, 6(bx)
119 mov dx, 4(bx)
120 mov bx, 2(bx)
121 movb ah, 0x40 ! "WRITE"
122 jmp dos
124 ! off_t lseek(int fd, off_t offset, int whence)
125 ! Set file position for read or write.
126 .define _lseek
127 _lseek:
128 mov bx, sp
129 movb al, 8(bx) ! SEEK_SET, SEEK_CUR, SEEK_END
130 mov dx, 4(bx)
131 mov cx, 6(bx) ! cx:dx = offset
132 mov bx, 2(bx)
133 movb ah, 0x42 ! "LSEEK"
134 jmp dos
137 ! $PchId: mkfhead.ack.s,v 1.3 1999/01/14 21:17:06 philip Exp $