561c19a52e96d6be5b093f7ee6412790a3ce4e34
[reactos.git] / boot / freeldr / freeldr / arch / i386 / drvmap.S
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <asm.inc>
21 #include <arch/pc/x86common.h>
22
23 .code16
24
25 PUBLIC _DriveMapInt13HandlerStart
26 _DriveMapInt13HandlerStart:
27
28 Int13Handler:
29 push bp
30 mov bp, sp
31 push ax
32 push cx
33 push si
34
35 cld
36
37 /* Get callers flags from stack */
38 mov ax, [bp + 6]
39 mov word ptr cs:[CallersFlags - Int13Handler], ax
40
41 /* Save the drive number they passed in */
42 mov byte ptr cs:[PassedInDriveNumber - Int13Handler], dl
43
44 /* Now we need to perform the mapping */
45 xor cx, cx
46 mov si, offset Int13HandlerMapCount - Int13Handler
47
48 /* Get the count of drives in the map list */
49 mov cl, byte ptr cs:[si]
50 inc si
51
52 /* If the map list is empty then just call the old int 13h handler */
53 cmp cl, 0
54 jz CallOldInt13Handler
55
56 GetMappedDriveNumberLoop:
57
58 /* Get the next drive number in the list (store it in AX) */
59 lods word ptr cs:[si]
60
61 /* Check to see if it's the one they are calling int 13h for */
62 cmp dl, al
63
64 /* If not get the next one */
65 jne GetMappedDriveNumberLoopNext
66
67 /* If we get here then we have found a mapped drive */
68 /* Send new drive number on to the old int 13h handler */
69 mov dl, ah
70
71 /* Call BIOS Int 13 Handler */
72 jmp CallOldInt13Handler
73
74 GetMappedDriveNumberLoopNext:
75 loop GetMappedDriveNumberLoop
76
77 CallOldInt13Handler:
78 /* Restore the registers we changed off the stack */
79 pop si
80 pop cx
81 pop ax
82
83 /* Put flags onto stack */
84 push word ptr cs:[CallersFlags - Int13Handler]
85
86 /* Call old int 13h handler with new drive number */
87 .byte HEX(9a) /* lcall */
88 PUBLIC _DriveMapOldInt13HandlerAddress
89 _DriveMapOldInt13HandlerAddress:
90 .word 0
91 .word 0
92
93 /* Update the callers flags with the values the BIOS returned */
94 push ax
95 pushf
96 pop ax
97 mov [bp + 6], ax
98 pop ax
99
100 /* Restore the callers drive number */
101 mov dl, byte ptr cs:[PassedInDriveNumber - Int13Handler]
102
103 pop bp
104
105 iret
106
107 CallersFlags:
108 .word 0
109
110 PassedInDriveNumber:
111 .byte 0
112
113 /* See the DRIVE_MAP_LIST structure in include/arch/i386/drivemap.h */
114 PUBLIC _DriveMapInt13HandlerMapList
115 _DriveMapInt13HandlerMapList:
116 Int13HandlerMapCount:
117 .byte 0
118
119 Int13HandlerDrive1:
120 .byte 0
121 Int13HandlerDriveNew1:
122 .byte 0
123
124 Int13HandlerDrive2:
125 .byte 0
126 Int13HandlerDriveNew2:
127 .byte 0
128
129 Int13HandlerDrive3:
130 .byte 0
131 Int13HandlerDriveNew3:
132 .byte 0
133
134 Int13HandlerDrive4:
135 .byte 0
136 Int13HandlerDriveNew4:
137 .byte 0
138
139 PUBLIC _DriveMapInt13HandlerEnd
140 _DriveMapInt13HandlerEnd:
141
142 .endcode16
143
144 END