dos_file.S revision 1.1 1 /* $NetBSD: dos_file.S,v 1.1 2024/06/29 13:45:14 rin Exp $ */
2
3 /* extracted from Tor Egge's patches for NetBSD boot */
4
5 #include <machine/asm.h>
6
7 /*
8 # MSDOS call "INT 0x21 Function 0x3d" to open a file.
9 # Call with %ah = 0x3d
10 # %al = 0x0 (access and sharing modes)
11 # %ds:%dx = ASCIZ filename
12 # %cl = attribute mask of files to look for
13 */
14
15 .globl _C_LABEL(doserrno)
16 _C_LABEL(doserrno): .long 1
17
18 ENTRY(dosopen)
19 .code32
20 pushl %ebp
21 movl %esp, %ebp
22 pushl %edx
23 pushl %ebx
24 pushl %esi
25 pushl %edi
26
27 movl 0x8(%ebp), %edx # File name.
28
29 call _C_LABEL(prot_to_real) # enter real mode
30 .code16
31
32 push %ds
33 movl %edx, %eax
34 shrl $4, %eax
35 mov %ds, %si
36 add %si, %ax
37 mov %ax, %ds
38 and $0xf, %dx
39
40 movb $0x3d, %ah # Open existing file.
41 movb $0x0 , %al # ro
42
43 sti
44 int $0x21
45 cli
46 pop %ds
47
48 jnc ok1
49 mov %ax, _C_LABEL(doserrno)
50 movl $-1, %edx
51 jmp err1
52 ok1:
53 movl $0,%edx
54 mov %ax, %dx
55 err1:
56 calll _C_LABEL(real_to_prot) # back to protected mode
57 .code32
58
59 movl %edx, %eax # return value in %eax
60
61 popl %edi
62 popl %esi
63 popl %ebx
64 popl %edx
65 popl %ebp
66 ret
67
68 ENTRY(dosread)
69 .code32
70 pushl %ebp
71 movl %esp, %ebp
72 pushl %ebx
73 pushl %ecx
74 pushl %edx
75 pushl %esi
76 pushl %edi
77
78 movl 0x8(%ebp), %ebx # File handle
79 movl 0xc(%ebp), %edx # Buffer.
80 movl 0x10(%ebp), %ecx # Bytes to read
81
82 call _C_LABEL(prot_to_real) # enter real mode
83 .code16
84
85 push %ds
86 movl %edx, %eax
87 shrl $4, %eax
88 mov %ds, %si
89 add %si, %ax
90 mov %ax, %ds
91 and $0xf, %dx
92
93 movb $0x3f, %ah # Read from file or device
94
95 sti
96 int $0x21
97 cli
98 pop %ds
99
100 jnc ok2
101 mov %ax, _C_LABEL(doserrno)
102 movl $-1, %edx
103 jmp err2
104 ok2:
105 movl $0,%edx
106 mov %ax, %dx
107 err2:
108 calll _C_LABEL(real_to_prot) # back to protected mode
109 .code32
110
111 movl %edx, %eax # return value in %eax
112
113 popl %edi
114 popl %esi
115 popl %edx
116 popl %ecx
117 popl %ebx
118 popl %ebp
119 ret
120
121 ENTRY(dosclose)
122 .code32
123 pushl %ebp
124 movl %esp, %ebp
125 pushl %ebx
126 pushl %esi
127 pushl %edi
128
129 movl 0x8(%ebp), %ebx # File handle
130
131 call _C_LABEL(prot_to_real) # enter real mode
132 .code16
133
134 movb $0x3e, %ah # Close file.
135
136 sti
137 int $0x21
138 cli
139
140 jnc ok3
141 mov %ax, _C_LABEL(doserrno)
142 movl $-1, %ebx
143 jmp err3
144 ok3:
145 movl $0, %ebx
146 err3:
147 calll _C_LABEL(real_to_prot) # back to protected mode
148 .code32
149
150 movl %ebx, %eax # return value in %eax
151
152 popl %edi
153 popl %esi
154 popl %ebx
155 popl %ebp
156 ret
157
158 ENTRY(dosseek)
159 .code32
160 pushl %ebp
161 movl %esp, %ebp
162 pushl %ebx
163 pushl %ecx
164 pushl %edx
165 pushl %esi
166 pushl %edi
167
168 movl 0x8(%ebp), %ebx # File handle
169 movl 0xc(%ebp), %ecx # Offset
170 movl 0x10(%ebp) , %edx # whence
171
172 call _C_LABEL(prot_to_real) # enter real mode
173 .code16
174
175 movb $0x42, %ah # Seek
176 movb %dl, %al # whence
177 mov %cx, %dx #offs lo
178 shrl $0x10, %ecx #offs hi
179
180 sti
181 int $0x21
182 cli
183
184 jnc ok4
185 mov %ax, _C_LABEL(doserrno)
186 movl $-1, %edx
187 jmp err4
188 ok4:
189 shll $0x10, %edx #new ofs hi
190 mov %ax, %dx #new ofs lo
191 err4:
192 calll _C_LABEL(real_to_prot) # back to protected mode
193 .code32
194
195 movl %edx, %eax # return value in %eax
196
197 popl %edi
198 popl %esi
199 popl %edx
200 popl %ecx
201 popl %ebx
202 popl %ebp
203 ret
204