Debian Codegraph @

purgatory/arch/i386/entry32-16.S

raw
1 /*
2 * kexec: Linux boots Linux
3 *
4 * Copyright (C) 2003,2004 Eric Biederman ([email protected])
5 *
6 * This program 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 (version 2 of the License).
9 *
10 * This program 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 this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #undef i386
21 .text
22 .globl entry16, entry16_regs
23 .balign 16
24 entry16:
25 .code32
26 .arch i386
27 /* Compute where I am running at (assumes esp valid) */
28 call 1f
29 1: popl %ebx
30 subl $(1b - entry16), %ebx
31
32 /* Fixup my real mode segment */
33 movl %ebx, %eax
34 shrl $4, %eax
35 movw %ax, (2 + realptr - entry16)(%ebx)
36
37 /* Fixup the gdt */
38 leal (gdt - entry16)(%ebx), %eax
39 movl %eax, (0x02 + gdt - entry16)(%ebx)
40
41 movl %ebx, %eax
42 shll $16, %eax
43
44 movl %ebx, %ecx
45 shrl $16, %ecx
46 andl $0xff, %ecx
47
48 movl %ebx, %edx
49 andl $0xff000000, %edx
50 orl %edx, %ecx
51
52 orl %eax, (0x08 + gdt - entry16)(%ebx)
53 orl %ecx, (0x0c + gdt - entry16)(%ebx)
54 orl %eax, (0x10 + gdt - entry16)(%ebx)
55 orl %ecx, (0x14 + gdt - entry16)(%ebx)
56
57
58 /* Setup the classic BIOS interrupt table at 0x0 */
59 lidt (idtptr - entry16)(%ebx)
60
61 /* Provide us with 16bit segments that we can use */
62 lgdt (gdt - entry16)(%ebx)
63
64 /* Note we don't disable the a20 line, (this shouldn't be required)
65 * The code to do it is in kexec_test and it is a real pain.
66 * I will worry about that when I need it.
67 */
68
69 /* Load 16bit data segments, to ensure the segment limits are set */
70 movl $0x10, %eax
71 movl %eax, %ds
72 movl %eax, %es
73 movl %eax, %ss
74 movl %eax, %fs
75 movl %eax, %gs
76
77 /* switch to 16bit mode */
78 ljmp $0x08, $1f - entry16
79 1:
80 .code16
81 /* Disable Paging and protected mode */
82 /* clear the PG & PE bits of CR0 */
83 movl %cr0,%eax
84 andl $~((1 << 31)|(1<<0)),%eax
85 movl %eax,%cr0
86
87 /* make intersegment jmp to flush the processor pipeline
88 * and reload %cs:%eip (to clear upper 16 bits of %eip).
89 */
90 ljmp *(realptr - entry16)
91 3:
92 /* we are in real mode now
93 * set up the real mode segment registers : %ds, $ss, %es
94 */
95 /* Setup the data segment */
96 movw %cs, %ax
97 movw %ax, %ds
98
99 /* Load the registers */
100 movl eax - entry16, %eax
101 movl ebx - entry16, %ebx
102 movl ecx - entry16, %ecx
103 movl edx - entry16, %edx
104 movl esi - entry16, %esi
105 movl edi - entry16, %esi
106 movl esp - entry16, %esp
107 movl ebp - entry16, %ebp
108 movw es - entry16, %es
109 movw ss - entry16, %ss
110 movw fs - entry16, %fs
111 movw gs - entry16, %gs
112 movw ds - entry16, %ds
113
114 /* Jump to the kernel entrypoint */
115 ljmp %cs:*(realdest - entry16)
116
117 .balign 4
118 entry16_regs:
119 eax: .long 0x00000000
120 ebx: .long 0x00000000
121 ecx: .long 0x00000000
122 edx: .long 0x00000000
123 esi: .long 0x00000000
124 edi: .long 0x00000000
125 esp: .long 0x00000000
126 ebp: .long 0x00000000
127 ds: .word 0x0000
128 es: .word 0x0000
129 ss: .word 0x0000
130 fs: .word 0x0000
131 gs: .word 0x0000
132 realdest:
133 ip: .word 0x0000
134 cs: .word 0x0000
135 pad: .word 0x0000
136 .size entry16_regs, . - entry16_regs
137
138 .balign 16
139 realptr:
140 .word 3b - entry16
141 .word 0x0000
142
143 .data
144 .balign 16
145
146 idtptr:
147 /* 256 entry idt at 0 */
148 .word 0x400 - 1
149 .word 0, 0
150
151 .balign 16
152 gdt:
153 /* 0x00 unusable segment so used as the gdt ptr */
154 .word gdt_end - gdt - 1
155 .long 0 /* gdt */
156 .word 0
157
158 /* 0x08 16 bit real mode code segment */
159 .word 0xffff, 0x0000
160 .byte 0x00, 0x9b, 0x00, 0x00
161
162 /* 0x10 16 bit real mode data segment */
163 .word 0xffff, 0x0000
164 .byte 0x00, 0x93, 0x00, 0x00
165 gdt_end: