Debian Codegraph @

purgatory/arch/i386/entry32-16-debug.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 #include "arch/debug.h"
21
22 #undef i386
23 .text
24 .globl entry16_debug, entry16_debug_regs
25 .globl entry16_debug_pre32
26 .globl entry16_debug_first32
27 .globl entry16_debug_old_first32
28 .balign 16
29 entry16_debug:
30 .code32
31 .arch i386
32 /* Compute where I am running at (assumes esp valid) */
33 call 1f
34 1: popl %ebx
35 subl $(1b - entry16_debug), %ebx
36
37 /* Fixup my real mode segment */
38 movl %ebx, %eax
39 shrl $4, %eax
40 movw %ax, (2 + realptr - entry16_debug)(%ebx)
41
42 /* Fixup the gdt */
43 leal (gdt - entry16_debug)(%ebx), %eax
44 movl %eax, (0x02 + gdt - entry16_debug)(%ebx)
45
46 movl %ebx, %eax
47 shll $16, %eax
48
49 movl %ebx, %ecx
50 shrl $16, %ecx
51 andl $0xff, %ecx
52
53 movl %ebx, %edx
54 andl $0xff000000, %edx
55 orl %edx, %ecx
56
57 orl %eax, (0x08 + gdt - entry16_debug)(%ebx)
58 orl %ecx, (0x0c + gdt - entry16_debug)(%ebx)
59 orl %eax, (0x10 + gdt - entry16_debug)(%ebx)
60 orl %ecx, (0x14 + gdt - entry16_debug)(%ebx)
61
62
63 DEBUG_CHAR('a')
64 /* Setup the classic BIOS interrupt table at 0x0 */
65 lidt (idtptr - entry16_debug)(%ebx)
66
67 DEBUG_CHAR('b')
68 /* Provide us with 16bit segments that we can use */
69 lgdt (gdt - entry16_debug)(%ebx)
70
71 DEBUG_CHAR('c')
72 /* Note we don't disable the a20 line, (this shouldn't be required)
73 * The code to do it is in kexec_test and it is a real pain.
74 * I will worry about that when I need it.
75 */
76
77 /* Load 16bit data segments, to ensure the segment limits are set */
78 movl $0x10, %eax
79 movl %eax, %ds
80 movl %eax, %es
81 movl %eax, %ss
82 movl %eax, %fs
83 movl %eax, %gs
84
85 DEBUG_CHAR('d')
86
87 /* switch to 16bit mode */
88 ljmp $0x08, $1f - entry16_debug
89 1:
90 .code16
91 DEBUG_CHAR('e')
92 /* Disable Paging and protected mode */
93 /* clear the PG & PE bits of CR0 */
94 movl %cr0,%eax
95 andl $~((1 << 31)|(1<<0)),%eax
96 movl %eax,%cr0
97
98 DEBUG_CHAR('f')
99 /* make intersegment jmp to flush the processor pipeline
100 * and reload %cs:%eip (to clear upper 16 bits of %eip).
101 */
102 ljmp *(realptr - entry16_debug)
103 3:
104 DEBUG_CHAR('g')
105 /* we are in real mode now
106 * set up the real mode segment registers : %ds, $ss, %es
107 */
108 /* Setup the data segment */
109 movw %cs, %ax
110 movw %ax, %ds
111
112 DEBUG_CHAR('h')
113 /* Load the registers */
114 movl eax - entry16_debug, %eax
115 movl ebx - entry16_debug, %ebx
116 movl ecx - entry16_debug, %ecx
117 movl edx - entry16_debug, %edx
118 movl esi - entry16_debug, %esi
119 movl edi - entry16_debug, %esi
120 movl esp - entry16_debug, %esp
121 movl ebp - entry16_debug, %ebp
122 movw es - entry16_debug, %es
123 movw ss - entry16_debug, %ss
124 movw fs - entry16_debug, %fs
125 movw gs - entry16_debug, %gs
126 movw ds - entry16_debug, %ds
127
128 /* Jump to the kernel entrypoint */
129 ljmp %cs:*(realdest - entry16_debug)
130
131 .balign 4
132 entry16_debug_regs:
133 eax: .long 0x00000000
134 ebx: .long 0x00000000
135 ecx: .long 0x00000000
136 edx: .long 0x00000000
137 esi: .long 0x00000000
138 edi: .long 0x00000000
139 esp: .long 0x00000000
140 ebp: .long 0x00000000
141 ds: .word 0x0000
142 es: .word 0x0000
143 ss: .word 0x0000
144 fs: .word 0x0000
145 gs: .word 0x0000
146 realdest:
147 ip: .word 0x0000
148 cs: .word 0x0000
149 pad: .word 0x0000
150 .size entry16_debug_regs, . - entry16_debug_regs
151
152 .balign 16
153 realptr:
154 .word 3b - entry16_debug
155 .word 0x0000
156
157 .data
158 .balign 16
159
160 idtptr:
161 /* 256 entry idt at 0 */
162 .word 0x400 - 1
163 .word 0, 0
164
165 gdt:
166 /* 0x00 unusable segment so used as the gdt ptr */
167 .word gdt_end - gdt - 1
168 .long 0 /* gdt */
169 .word 0
170
171 /* 0x08 16 bit real mode code segment */
172 .word 0xffff, 0x0000
173 .byte 0x00, 0x9b, 0x00, 0x00
174
175 /* 0x10 16 bit real mode data segment */
176 .word 0xffff, 0x0000
177 .byte 0x00, 0x93, 0x00, 0x00
178 gdt_end:
179 .size gdt, . - gdt
180
181 .text
182 entry16_debug_pre32:
183 .code16
184 DEBUG_CHAR('i')
185 cli # no interrupts allowed !
186 movb $0x80, %al # disable NMI for bootup
187 # sequence
188 outb %al, $0x70
189 lret
190 .size entry16_debug_pre32, . - entry16_debug_pre32
191
192 entry16_debug_first32:
193 .code32
194 DEBUG_CHAR('j')
195 .byte 0xb8 /* movl $0x10000, %eax */
196 entry16_debug_old_first32:
197 .long 0x100000
198 .size entry16_debug_old_first32, . - entry16_debug_old_first32
199 jmp *%eax
200 .size entry16_debug_first32, . - entry16_debug_first32