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