1
/* drivemap_int13h.S - interrupt handler for the BIOS drive remapper */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2008, 2009 Free Software Foundation, Inc.
6
* GRUB is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* GRUB is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20
#include <grub/symbol.h>
22
#define INT13H_OFFSET(x) ((x) - EXT_C(grub_drivemap_handler))
26
/* Copy starts here. When deployed, this code must be segment-aligned. */
28
/* The replacement int13 handler. Preserve all registers. */
29
FUNCTION(grub_drivemap_handler)
30
/* Save %dx for future restore. */
32
/* Push flags. Used to simulate interrupt with original flags. */
35
/* Map the drive number (always in DL). */
39
grub_drivemap_mapstart_ofs = INT13H_OFFSET(EXT_C(grub_drivemap_mapstart))
40
movw $grub_drivemap_mapstart_ofs, %bx
42
movw $INT13H_OFFSET(EXT_C(grub_drivemap_mapstart)), %bx
48
jz not_found /* DRV=DST => map end - drive not remapped, keep DL. */
52
jnz more_remaining /* Not found, but more remaining, loop. */
53
movb %ah, %dl /* Found - drive remapped, modify DL. */
59
/* If the call isn't ah=0x8 or ah=0x15 we must restore %dx. */
70
grub_drivemap_oldhandler_ofs = INT13H_OFFSET (EXT_C (grub_drivemap_oldhandler))
71
lcall *%cs:grub_drivemap_oldhandler_ofs
73
lcall *%cs:INT13H_OFFSET (EXT_C (grub_drivemap_oldhandler))
80
/* Save new flags below %esp so the caller will recieve new flags. */
98
lcall *%cs:grub_drivemap_oldhandler_ofs
100
lcall *%cs:INT13H_OFFSET (EXT_C (grub_drivemap_oldhandler))
106
/* Save %dx. So it won't be restored to original value. */
111
/* Far pointer to the old handler. Stored as a CS:IP in the style of real-mode
112
IVT entries (thus PI:SC in mem). */
113
VARIABLE(grub_drivemap_oldhandler)
116
/* This label MUST be at the end of the copied block, since the installer code
117
reserves additional space for mappings at runtime and copies them over it. */
119
VARIABLE(grub_drivemap_mapstart)