~ubuntu-branches/debian/sid/grub2/sid-200907171840

« back to all changes in this revision

Viewing changes to kern/i386/loader.S

  • Committer: Bazaar Package Importer
  • Author(s): Robert Millan
  • Date: 2007-11-01 13:18:51 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071101131851-tczt5tevrsnpt1tq
Tags: 1.95+20071101-1
* New CVS snapshot.
  - patches/linuxbios.diff: Remove (supported in upstream now).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  GRUB  --  GRand Unified Bootloader
 
3
 *  Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007 Free Software Foundation, Inc.
 
4
 *
 
5
 *  GRUB is free software: you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation, either version 3 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  GRUB is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
 
 
20
/*
 
21
 * Note: These functions defined in this file may be called from C.
 
22
 *       Be careful of that you must not modify some registers. Quote
 
23
 *       from gcc-2.95.2/gcc/config/i386/i386.h:
 
24
        
 
25
   1 for registers not available across function calls.
 
26
   These must include the FIXED_REGISTERS and also any
 
27
   registers that can be used without being saved.
 
28
   The latter must include the registers where values are returned
 
29
   and the register where structure-value addresses are passed.
 
30
   Aside from that, you can include as many other registers as you like.
 
31
 
 
32
  ax,dx,cx,bx,si,di,bp,sp,st,st1,st2,st3,st4,st5,st6,st7,arg
 
33
{  1, 1, 1, 0, 0, 0, 0, 1, 1,  1,  1,  1,  1,  1,  1,  1,  1 }
 
34
 */
 
35
 
 
36
/*
 
37
 * Note: GRUB is compiled with the options -mrtd and -mregparm=3.
 
38
 *       So the first three arguments are passed in %eax, %edx, and %ecx,
 
39
 *       respectively, and if a function has a fixed number of arguments
 
40
 *       and the number if greater than three, the function must return
 
41
 *       with "ret $N" where N is ((the number of arguments) - 3) * 4.
 
42
 */
 
43
 
 
44
/*
 
45
 *  This is the area for all of the special variables.
 
46
 */
 
47
 
 
48
        .p2align        2       /* force 4-byte alignment */
 
49
        
 
50
/*
 
51
 * void grub_linux_boot_zimage (void)
 
52
 */
 
53
VARIABLE(grub_linux_prot_size)
 
54
        .long   0
 
55
VARIABLE(grub_linux_tmp_addr)
 
56
        .long   0
 
57
VARIABLE(grub_linux_real_addr)
 
58
        .long   0
 
59
        
 
60
FUNCTION(grub_linux_boot_zimage)
 
61
        /* copy the kernel */
 
62
        movl    EXT_C(grub_linux_prot_size), %ecx
 
63
        addl    $3, %ecx
 
64
        shrl    $2, %ecx
 
65
        movl    $GRUB_LINUX_BZIMAGE_ADDR, %esi
 
66
        movl    $GRUB_LINUX_ZIMAGE_ADDR, %edi
 
67
        cld
 
68
        rep
 
69
        movsl
 
70
 
 
71
FUNCTION(grub_linux_boot_bzimage)
 
72
        call    EXT_C(grub_dl_unload_all)
 
73
        
 
74
        movl    EXT_C(grub_linux_real_addr), %ebx
 
75
 
 
76
        /* copy the real mode code */
 
77
        movl    EXT_C(grub_linux_tmp_addr), %esi
 
78
        movl    %ebx, %edi
 
79
        movl    $GRUB_LINUX_SETUP_MOVE_SIZE, %ecx
 
80
        cld
 
81
        rep
 
82
        movsb
 
83
 
 
84
        /* change %ebx to the segment address */
 
85
        shrl    $4, %ebx
 
86
        movl    %ebx, %eax
 
87
        addl    $0x20, %eax
 
88
        movw    %ax, linux_setup_seg
 
89
 
 
90
        /* XXX new stack pointer in safe area for calling functions */
 
91
        movl    $0x4000, %esp
 
92
        call    EXT_C(grub_stop_floppy)
 
93
 
 
94
        /* final setup for linux boot */
 
95
        call    prot_to_real
 
96
        .code16
 
97
 
 
98
        cli
 
99
        movw    %bx, %ss
 
100
        movw    $GRUB_LINUX_SETUP_STACK, %sp
 
101
 
 
102
        movw    %bx, %ds
 
103
        movw    %bx, %es
 
104
        movw    %bx, %fs
 
105
        movw    %bx, %gs
 
106
 
 
107
        /* ljmp */
 
108
        .byte   0xea
 
109
        .word   0
 
110
linux_setup_seg:
 
111
        .word   0
 
112
        .code32
 
113
 
 
114
                
 
115
/*
 
116
 * This starts the multiboot kernel.
 
117
 */
 
118
 
 
119
FUNCTION(grub_multiboot_real_boot)
 
120
        /* Push the entry address on the stack.  */
 
121
        pushl   %eax
 
122
        /* Move the address of the multiboot information structure to ebx.  */
 
123
        movl    %edx,%ebx
 
124
        
 
125
        /* Unload all modules and stop the floppy driver.  */
 
126
        call    EXT_C(grub_dl_unload_all)
 
127
        call    EXT_C(grub_stop_floppy)
 
128
 
 
129
        /* Interrupts should be disabled.  */
 
130
        cli
 
131
        
 
132
        /* Move the magic value into eax and jump to the kernel.  */
 
133
        movl    $MULTIBOOT_MAGIC2,%eax
 
134
        popl    %ecx
 
135
        jmp     *%ecx
 
136
 
 
137
/*
 
138
 * This starts the multiboot 2 kernel.
 
139
 */
 
140
 
 
141
FUNCTION(grub_multiboot2_real_boot)
 
142
        /* Push the entry address on the stack.  */
 
143
        pushl   %eax
 
144
        /* Move the address of the multiboot information structure to ebx.  */
 
145
        movl    %edx,%ebx
 
146
 
 
147
        /* Unload all modules and stop the floppy driver.  */
 
148
        call    EXT_C(grub_dl_unload_all)
 
149
        call    EXT_C(grub_stop_floppy)
 
150
 
 
151
        /* Interrupts should be disabled.  */
 
152
        cli
 
153
 
 
154
        /* Move the magic value into eax and jump to the kernel.  */
 
155
        movl    $MULTIBOOT2_BOOTLOADER_MAGIC,%eax 
 
156
        popl    %ecx
 
157
        jmp     *%ecx