~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

Viewing changes to commands/i386/pc/drivemap_int13h.S

Tags: upstream-1.99~20101122
ImportĀ upstreamĀ versionĀ 1.99~20101122

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* drivemap_int13h.S - interrupt handler for the BIOS drive remapper */
2
 
/*
3
 
 *  GRUB  --  GRand Unified Bootloader
4
 
 *  Copyright (C) 2008, 2009  Free Software Foundation, Inc.
5
 
 *
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.
10
 
 *
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.
15
 
 *
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/>.
18
 
 */
19
 
 
20
 
#include <grub/symbol.h>
21
 
 
22
 
#define INT13H_OFFSET(x) ((x) - EXT_C(grub_drivemap_handler))
23
 
 
24
 
.code16
25
 
 
26
 
/* Copy starts here.  When deployed, this code must be segment-aligned.  */
27
 
 
28
 
/* The replacement int13 handler.   Preserve all registers.  */
29
 
FUNCTION(grub_drivemap_handler)
30
 
        /* Save %dx for future restore. */
31
 
        push    %dx
32
 
        /* Push flags. Used to simulate interrupt with original flags. */
33
 
        pushf
34
 
 
35
 
        /* Map the drive number (always in DL).  */
36
 
        push    %ax
37
 
        push    %bx
38
 
#ifdef APPLE_CC
39
 
        grub_drivemap_mapstart_ofs = INT13H_OFFSET(EXT_C(grub_drivemap_mapstart))
40
 
        movw    $grub_drivemap_mapstart_ofs, %bx
41
 
#else
42
 
        movw    $INT13H_OFFSET(EXT_C(grub_drivemap_mapstart)), %bx
43
 
#endif
44
 
 
45
 
more_remaining:
46
 
        movw    %cs:(%bx), %ax
47
 
        cmpb    %ah, %al
48
 
        jz      not_found /* DRV=DST => map end - drive not remapped, keep DL.  */
49
 
        inc     %bx
50
 
        inc     %bx
51
 
        cmpb    %dl, %al
52
 
        jnz     more_remaining /* Not found, but more remaining, loop.  */
53
 
        movb    %ah, %dl /* Found - drive remapped, modify DL.  */
54
 
 
55
 
not_found:
56
 
        pop     %bx
57
 
        pop     %ax
58
 
 
59
 
        /* If the call isn't ah=0x8 or ah=0x15 we must restore %dx.  */
60
 
        cmpb    $0x8, %ah
61
 
        jz      norestore
62
 
        cmpb    $0x15, %ah
63
 
        jz      norestore
64
 
 
65
 
        /* Restore flags.  */
66
 
        popf
67
 
        pushf
68
 
 
69
 
#ifdef APPLE_CC
70
 
        grub_drivemap_oldhandler_ofs = INT13H_OFFSET (EXT_C (grub_drivemap_oldhandler))
71
 
        lcall *%cs:grub_drivemap_oldhandler_ofs
72
 
#else
73
 
        lcall *%cs:INT13H_OFFSET (EXT_C (grub_drivemap_oldhandler))
74
 
#endif
75
 
 
76
 
        push    %bp
77
 
        mov     %sp, %bp
78
 
 
79
 
tail:
80
 
        /* Save new flags below %esp so the caller will recieve new flags.  */
81
 
        pushf
82
 
        pop     %dx
83
 
        mov     %dx, 8(%bp)
84
 
 
85
 
        pop     %bp
86
 
 
87
 
        /* Restore %dx.  */
88
 
        pop     %dx
89
 
        iret
90
 
 
91
 
norestore:
92
 
 
93
 
        /* Restore flags.  */
94
 
        popf
95
 
        pushf
96
 
 
97
 
#ifdef APPLE_CC
98
 
        lcall *%cs:grub_drivemap_oldhandler_ofs
99
 
#else
100
 
        lcall *%cs:INT13H_OFFSET (EXT_C (grub_drivemap_oldhandler))
101
 
#endif
102
 
 
103
 
        push    %bp
104
 
        mov     %sp, %bp
105
 
 
106
 
        /* Save %dx. So it won't be restored to original value.  */
107
 
        mov     %dx, 2(%bp)
108
 
 
109
 
        jmp tail
110
 
 
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)
114
 
        .word 0x0, 0x0
115
 
 
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.  */
118
 
.align 2
119
 
VARIABLE(grub_drivemap_mapstart)