~ilya-yanok/ubuntu/precise/grub2/fix-for-948716

« back to all changes in this revision

Viewing changes to boot/i386/pc/lnxboot.S

  • Committer: Bazaar Package Importer
  • Author(s): Robert Millan
  • Date: 2009-07-25 19:00:53 UTC
  • mfrom: (1.6.3 upstream)
  • mto: (17.4.13 sid)
  • mto: This revision was merged to the branch mainline in revision 53.
  • Revision ID: james.westby@ubuntu.com-20090725190053-uv3lm6ya3zxs77ep
ImportĀ upstreamĀ versionĀ 1.96+20090725

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 */
19
19
 
20
20
#include <config.h>
21
 
#include <grub/symbol.h>
22
21
#include <grub/boot.h>
23
22
#include <grub/machine/boot.h>
24
23
#include <grub/machine/kernel.h>
26
25
 
27
26
        .file   "lnxboot.S"
28
27
 
 
28
#ifdef APPLE_CC
 
29
#error Building lnxboot.img with Apple's as results in an unusable image
 
30
#endif
 
31
 
29
32
#define CODE_ADDR       0x6000
30
 
#define CODE_SECTORS    1
 
33
#ifndef APPLE_CC
 
34
#define CODE_LENG       (code_end - start)
 
35
#endif
31
36
#define DATA_ADDR       ((GRUB_BOOT_MACHINE_KERNEL_ADDR) + 0x200)
32
37
 
33
38
#define BLCK_LENG       0x4000
40
45
 
41
46
data_start:
42
47
        xorl    %ebp, %ebp
43
 
        jmp     LOCAL(linux_next)
 
48
        jmp     linux_next
44
49
 
45
50
        . = data_start + 0x1F1
46
51
 
47
52
setup_sects:
48
 
        .byte   CODE_SECTORS
 
53
/* Apple's cc can't fill this value.  */
 
54
#ifdef APPLE_CC
 
55
        .byte   0
 
56
#else
 
57
        .byte   (CODE_LENG >> 9)
 
58
#endif
49
59
root_flags:
50
60
        .word   0
51
61
syssize:
64
74
start:
65
75
_start:
66
76
 
67
 
        jmp LOCAL(linux_init)
 
77
        jmp linux_init
68
78
 
69
79
        .ascii  "HdrS"                  /* Header signature.  */
70
80
        .word   0x0203                  /* Header version number.  */
122
132
data_leng:
123
133
        .long   0
124
134
 
125
 
LOCAL(linux_init):
 
135
linux_init:
 
136
 
 
137
#ifdef APPLE_CC
 
138
        reg_edx_rel = reg_edx - start
 
139
        code32_start_rel = code32_start - start
 
140
        movw    %cs:(reg_edx_rel), %dx
 
141
        movl    %cs:(code32_start_rel), %ebp
 
142
#else
126
143
        movw    %cs:(reg_edx - start), %dx
127
144
        movl    %cs:(code32_start - start), %ebp
128
 
 
129
 
LOCAL(linux_next):
130
 
 
131
 
        call    LOCAL(normalize)
132
 
 
133
 
LOCAL(normalize):
 
145
#endif
 
146
 
 
147
linux_next:
 
148
 
 
149
        call    normalize
 
150
 
 
151
normalize:
134
152
        popw    %bx
135
 
        subw    $(LOCAL(normalize) - start), %bx
 
153
#ifdef APPLE_CC
 
154
        normalize_rel = normalize - start
 
155
        subw    $(normalize_rel), %bx
 
156
#else
 
157
        subw    $(normalize - start), %bx
 
158
#endif
136
159
        shrw    $4, %bx
137
160
        movw    %cs, %ax
138
161
        addw    %bx, %ax
139
162
        pushw   %ax
 
163
#ifdef APPLE_CC
 
164
        real_code_rel = real_code - start
 
165
        pushw   $(real_code_rel)
 
166
#else
140
167
        pushw   $(real_code - start)
 
168
#endif
141
169
        lret                            /* Jump to real_code.  */
142
170
 
143
171
real_code:
163
191
 
164
192
        rep
165
193
        movsl
 
194
 
 
195
#ifdef APPLE_CC
 
196
        real_code_2_rel = real_code_2 - start
 
197
        ljmp    $(CODE_ADDR >> 4), $(real_code_2_rel)
 
198
#else
166
199
        ljmp    $(CODE_ADDR >> 4), $(real_code_2  - start)
 
200
#endif
167
201
 
168
202
real_code_2:
169
203
 
182
216
        addl    %ecx, %esi
183
217
        movl    $DATA_ADDR, %edi
184
218
 
185
 
        call    LOCAL(move_memory)
 
219
        call    move_memory
186
220
 
187
221
        /* Check for multiboot signature.  */
188
222
        cmpl    $MULTIBOOT_MAGIC, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_DATA_END)
189
223
        jz      1f
190
224
 
 
225
#ifdef APPLE_CC
 
226
        ramdisk_image_rel = ramdisk_image - start
 
227
        ramdisk_size_rel = ramdisk_size - start
 
228
        movl    (ramdisk_image_rel), %esi
 
229
        movl    (ramdisk_size_rel), %ecx
 
230
#else
191
231
        movl    (ramdisk_image - start), %esi
192
232
        movl    (ramdisk_size - start), %ecx
 
233
#endif
193
234
        movl    $(DATA_ADDR - 0x200), %edi
194
235
        jmp     2f
195
236
 
199
240
        addl    $(GRUB_KERNEL_MACHINE_RAW_SIZE - 0x200), %ecx
200
241
 
201
242
2:
202
 
        call    LOCAL(move_memory)
 
243
        call    move_memory
203
244
 
204
245
        movsbl  %dh, %eax
205
246
        movl    %eax, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART)
 
247
 
 
248
#ifdef APPLE_CC
 
249
        reg_edx_rel = reg_edx - start
 
250
        movsbl  (reg_edx_rel + 2), %eax
 
251
#else
206
252
        movsbl  (reg_edx + 2 - start), %eax
 
253
#endif
207
254
        movl    %eax, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART)
208
255
 
209
256
        movb    $0xFF, %dh
217
264
 *   ecx: number of bytes
218
265
 */
219
266
 
220
 
LOCAL(move_memory):
 
267
move_memory:
221
268
        incl    %ecx
222
269
        andb    $0xFE, %cl
223
270
        pushw   %dx
232
279
        pushl   %ecx
233
280
 
234
281
        movl    %esi, %eax
 
282
#ifdef APPLE_CC
 
283
        gdt_src1_rel = gdt_src1 - start
 
284
        gdt_src2_rel = gdt_src2 - start
 
285
        gdt_dst1_rel = gdt_dst1 - start
 
286
        gdt_dst2_rel = gdt_dst2 - start
 
287
        gdt_rel = gdt - start
 
288
 
 
289
        movw    %si, (gdt_src1_rel)
 
290
        shrl    $16, %eax
 
291
        movb    %al, (gdt_src1_rel + 2)
 
292
        movb    %ah, (gdt_src2_rel)
 
293
 
 
294
        movl    %edi, %eax
 
295
        movw    %di, (gdt_dst1_rel)
 
296
        shrl    $16, %eax
 
297
        movb    %al, (gdt_dst1_rel + 2)
 
298
        movb    %ah, (gdt_dst2_rel)
 
299
 
 
300
        movw    $(gdt_rel), %si
 
301
        movb    $0x87, %ah
 
302
        shrw    $1, %cx
 
303
#else
235
304
        movw    %si, (gdt_src1 - start)
236
305
        shrl    $16, %eax
237
306
        movb    %al, (gdt_src1 + 2 - start)
246
315
        movw    $(gdt - start), %si
247
316
        movb    $0x87, %ah
248
317
        shrw    $1, %cx
 
318
#endif
249
319
 
250
320
        int     $0x15
251
321
 
255
325
        popl    %esi
256
326
 
257
327
        jnc     2f
 
328
#ifdef APPLE_CC
 
329
        err_int15_msg_rel = err_int15_msg - start
 
330
        movw    $(err_int15_msg_rel), %si
 
331
#else
258
332
        movw    $(err_int15_msg - start), %si
259
 
        jmp     LOCAL(fail)
 
333
#endif
 
334
        jmp     fail
260
335
 
261
336
2:
262
337
 
274
349
 *   si: message
275
350
 */
276
351
 
277
 
LOCAL(fail):
 
352
fail:
278
353
        movb    $0x0e, %ah
279
354
        xorw    %bx, %bx
280
355
1:
287
362
err_int15_msg:
288
363
        .ascii  "move memory fails\0"
289
364
 
290
 
        . = _start + CODE_SECTORS * 512
 
365
        /* Unsupported feature in Apple's cc.  */
 
366
#ifndef APPLE_CC
 
367
        . = (.  & (~0x1FF)) + 0x1FF
 
368
#endif
 
369
 
 
370
        .byte   0
 
371
 
 
372
code_end: