~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

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

ImportĀ upstreamĀ versionĀ 1.97~beta3

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