Branching for 0.3.15 release after two days of no response from a certain sphere...
[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
21 #include <asm.inc>
22 #include <arch/pc/x86common.h>
23
24 .code16
25
26 PUBLIC _DriveMapInt13HandlerStart
27 _DriveMapInt13HandlerStart:
28 Int13Handler:
29
30 push bp
31 mov bp, sp
32 push ax
33 push cx
34 push si
35
36 cld
37
38 /* Get callers flags from stack */
39 mov ax, [bp + 6]
40 mov word ptr cs:[CallersFlags - Int13Handler], ax
41
42 /* Save the drive number they passed in */
43 mov cs:[PassedInDriveNumber - Int13Handler], dl
44
45 /* Now we need to perform the mapping */
46 xor cx, cx
47 mov si, offset Int13HandlerMapCount - Int13Handler
48
49 /* Get the count of drives in the map list */
50 mov cl, cs:[si]
51 inc si
52
53 /* If the map list is empty then just call the old int 13h handler */
54 cmp cl, 0
55 jz CallOldInt13Handler
56
57 GetMappedDriveNumberLoop:
58
59 /* Get the next drive number in the list */
60 lods ax, cs:[si]
61
62 /* Check to see if it's the one they are calling int 13h for */
63 cmp dl, al
64
65 /* If not get the next one */
66 jne GetMappedDriveNumberLoopNext
67
68 /* If we get here then we have found a mapped drive */
69 /* Send new drive number on to the old int 13h handler */
70 mov dl, ah
71
72 /* Call BIOS Int 13 Handler */
73 jmp CallOldInt13Handler
74
75 GetMappedDriveNumberLoopNext:
76 loop GetMappedDriveNumberLoop
77
78 CallOldInt13Handler:
79 /* Restore the registers we changed off the stack */
80 pop si
81 pop cx
82 pop ax
83
84 /* Put flags onto stack */
85 push word ptr cs:[CallersFlags - Int13Handler]
86
87
88 /* Call old int 13h handler with new drive number */
89 .byte HEX(9a) /* lcall */
90 PUBLIC _DriveMapOldInt13HandlerAddress
91 _DriveMapOldInt13HandlerAddress:
92 .word 0
93 .word 0
94
95 /* Update the callers flags with the values the BIOS returned */
96 push ax
97 pushf
98 pop ax
99 mov [bp + 6], ax
100 pop ax
101
102 /* Restore the callers drive number */
103 mov dl, cs:[PassedInDriveNumber - Int13Handler]
104
105 pop bp
106
107 iret
108
109 CallersFlags:
110 .word 0
111
112 PassedInDriveNumber:
113 .byte 0
114
115 PUBLIC _DriveMapInt13HandlerMapList
116 _DriveMapInt13HandlerMapList:
117 Int13HandlerMapCount:
118 .byte 0
119
120 Int13HandlerDrive1:
121 .byte 0
122 Int13HandlerDriveNew1:
123 .byte 0
124
125 Int13HandlerDrive2:
126 .byte 0
127 Int13HandlerDriveNew2:
128 .byte 0
129
130 Int13HandlerDrive3:
131 .byte 0
132 Int13HandlerDriveNew3:
133 .byte 0
134
135 Int13HandlerDrive4:
136 .byte 0
137 Int13HandlerDriveNew4:
138 .byte 0
139
140 PUBLIC _DriveMapInt13HandlerEnd
141 _DriveMapInt13HandlerEnd: