]> git.proxmox.com Git - grub2.git/blame - mmap/i386/pc/mmap_helper.S
2009-06-04 Vladimir Serbinenko <phcoder@gmail.com>
[grub2.git] / mmap / i386 / pc / mmap_helper.S
CommitLineData
09d842b9 1/* Mmap management. */
2/*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 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 DS(x) ((x) - segstart)
23
24segstart:
25VARIABLE(grub_machine_mmaphook_start)
26 .code16
27VARIABLE(grub_machine_mmaphook_int12)
28 push %ds
29 push %cs
30 pop %ds
3e325901 31#ifdef APPLE_CC
32 grub_machine_mmaphook_kblow_rel = DS (EXT_C (grub_machine_mmaphook_kblow))
33 movw (grub_machine_mmaphook_kblow_rel), %ax
34#else
09d842b9 35 movw DS (EXT_C (grub_machine_mmaphook_kblow)), %ax
3e325901 36#endif
09d842b9 37 pop %ds
38 iret
39
40VARIABLE(grub_machine_mmaphook_int15)
41 pushf
42 cmpw $0xe801, %ax
43 jz e801
44 cmpw $0xe820, %ax
45 jz e820
46 cmpb $0x88, %ah
47 jz h88
48 popf
49 /* ljmp */
50 .byte 0xea
51VARIABLE (grub_machine_mmaphook_int15offset)
52 .word 0
53VARIABLE (grub_machine_mmaphook_int15segment)
54 .word 0
55
56e801:
57 popf
58 push %ds
59 push %cs
60 pop %ds
3e325901 61#ifdef APPLE_CC
62 grub_machine_mmaphook_kbin16mb_rel = DS (EXT_C (grub_machine_mmaphook_kbin16mb))
63 grub_machine_mmaphook_64kbin4gb_rel = DS (EXT_C (grub_machine_mmaphook_64kbin4gb))
64 movw (grub_machine_mmaphook_kbin16mb_rel), %ax
65 movw (grub_machine_mmaphook_64kbin4gb_rel), %bx
66#else
09d842b9 67 movw DS (EXT_C (grub_machine_mmaphook_kbin16mb)), %ax
68 movw DS (EXT_C (grub_machine_mmaphook_64kbin4gb)), %bx
3e325901 69#endif
09d842b9 70 movw %ax, %cx
71 movw %bx, %dx
72 pop %ds
73 clc
74 iret
75
76h88:
77 popf
78 push %ds
79 push %cs
80 pop %ds
3e325901 81#ifdef APPLE_CC
82 movw (grub_machine_mmaphook_kbin16mb_rel), %ax
83#else
09d842b9 84 movw DS (EXT_C (grub_machine_mmaphook_kbin16mb)), %ax
3e325901 85#endif
09d842b9 86 pop %ds
87 clc
88 iret
89
90e820:
3e325901 91#ifdef APPLE_CC
92 mmaphook_mmap_rel = DS(mmaphook_mmap)
93 mmaphook_mmap_num_rel = DS(EXT_C(grub_machine_mmaphook_mmap_num))
94#endif
09d842b9 95 popf
96 push %ds
97 push %cs
98 pop %ds
99 cmpw $20, %cx
100 jb errexit
3e325901 101#ifdef APPLE_CC
102 cmpw (mmaphook_mmap_num_rel), %bx
103#else
09d842b9 104 cmpw DS (EXT_C (grub_machine_mmaphook_mmap_num)), %bx
3e325901 105#endif
09d842b9 106 jae errexit
107 cmp $0x534d4150, %edx
108 jne errexit
109 push %si
110 push %di
111 movw $20, %cx
3e325901 112#ifdef APPLE_CC
113 movl $(mmaphook_mmap_rel), %esi
114#else
09d842b9 115 movw $(DS(mmaphook_mmap)), %si
3e325901 116#endif
09d842b9 117 mov %bx, %ax
118 imul $20, %ax
119 add %ax, %si
120 rep movsb
121 pop %di
122 pop %si
123 movl $20, %ecx
124 inc %bx
3e325901 125#ifdef APPLE_CC
126 cmpw (mmaphook_mmap_num_rel), %bx
127#else
09d842b9 128 cmpw DS(EXT_C(grub_machine_mmaphook_mmap_num)), %bx
3e325901 129#endif
09d842b9 130 jb noclean
131 xor %bx, %bx
132noclean:
133 mov $0x534d4150, %eax
134 pop %ds
135 clc
136 iret
137errexit:
138 mov $0x534d4150, %eax
139 pop %ds
140 stc
141 xor %bx, %bx
142 iret
143
144VARIABLE(grub_machine_mmaphook_mmap_num)
145 .word 0
146VARIABLE(grub_machine_mmaphook_kblow)
147 .word 0
148VARIABLE (grub_machine_mmaphook_kbin16mb)
149 .word 0
150VARIABLE (grub_machine_mmaphook_64kbin4gb)
151 .word 0
152mmaphook_mmap:
153 /* Memory map is placed just after the interrupt handlers. */
154VARIABLE(grub_machine_mmaphook_end)