* Sync to trunk HEAD (r53318).
[reactos.git] / boot / freeldr / freeldr / arch / amd64 / 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 .text
21 .code16
22
23 #include <arch/pc/x86common.h>
24
25 EXTERN(DriveMapInt13HandlerStart)
26 Int13Handler:
27
28 pushw %bp
29 movw %sp,%bp
30 pushw %ax
31 pushw %cx
32 pushw %si
33
34 cld
35
36 /* Get callers flags from stack */
37 movw 0x06(%bp),%ax
38 movw %ax,%cs:(CallersFlags - Int13Handler)
39
40 /* Save the drive number they passed in */
41 movb %dl,%cs:(PassedInDriveNumber - Int13Handler)
42
43 /* Now we need to perform the mapping */
44 xorw %cx,%cx
45 movw $(Int13HandlerMapCount - Int13Handler),%si
46 /* Get the count of drives in the map list */
47 movb %cs:(%si),%cl
48 incw %si
49
50 /* If the map list is empty then just call the old int 13h handler */
51 cmpb $0,%cl
52 jz CallOldInt13Handler
53
54 GetMappedDriveNumberLoop:
55
56 /* Get the next drive number in the list */
57 lodsw %cs:(%si),%ax
58 /* Check to see if it's the one they are calling int 13h for */
59 cmpb %al,%dl
60 /* If not get the next one */
61 jne GetMappedDriveNumberLoopNext
62
63 /* If we get here then we have found a mapped drive */
64 /* Send new drive number on to the old int 13h handler */
65 movb %ah,%dl
66 /* Call BIOS Int 13 Handler */
67 jmp CallOldInt13Handler
68
69 GetMappedDriveNumberLoopNext:
70 loop GetMappedDriveNumberLoop
71
72 CallOldInt13Handler:
73 /* Restore the registers we changed off the stack */
74 popw %si
75 popw %cx
76 popw %ax
77
78 /* Put flags onto stack */
79 pushw %cs:(CallersFlags - Int13Handler)
80
81 /* Call old int 13h handler with new drive number */
82 .byte 0x9a /* lcall */
83 EXTERN(DriveMapOldInt13HandlerAddress)
84 .word 0
85 .word 0
86
87 /* Update the callers flags with the values the BIOS returned */
88 pushw %ax
89 pushf
90 popw %ax
91 movw %ax,0x06(%bp)
92 popw %ax
93 /* Restore the callers drive number */
94 movb %cs:(PassedInDriveNumber - Int13Handler),%dl
95
96 popw %bp
97
98 iret
99
100 CallersFlags:
101 .word 0
102
103 PassedInDriveNumber:
104 .byte 0
105
106 EXTERN(DriveMapInt13HandlerMapList)
107 Int13HandlerMapCount:
108 .byte 0
109
110 Int13HandlerDrive1:
111 .byte 0
112 Int13HandlerDriveNew1:
113 .byte 0
114
115 Int13HandlerDrive2:
116 .byte 0
117 Int13HandlerDriveNew2:
118 .byte 0
119
120 Int13HandlerDrive3:
121 .byte 0
122 Int13HandlerDriveNew3:
123 .byte 0
124
125 Int13HandlerDrive4:
126 .byte 0
127 Int13HandlerDriveNew4:
128 .byte 0
129
130 EXTERN(DriveMapInt13HandlerEnd)