xref: /openbmc/u-boot/arch/x86/cpu/start16.S (revision 650f3664)
1/*
2 *  U-boot - x86 Startup Code
3 *
4 * (C) Copyright 2008-2011
5 * Graeme Russ, <graeme.russ@gmail.com>
6 *
7 * (C) Copyright 2002,2003
8 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
9 *
10 * See file CREDITS for list of people who contributed to this
11 * project.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 * MA 02111-1307 USA
27 */
28
29#include <asm/global_data.h>
30#include <asm/processor-flags.h>
31
32#define BOOT_SEG	0xffff0000	/* linear segment of boot code */
33#define a32		.byte 0x67;
34#define o32		.byte 0x66;
35
36.section .start16, "ax"
37.code16
38.globl start16
39start16:
40	/*
41	 * First we let the BSP do some early initialization
42	 * this code have to map the flash to its final position
43	 */
44	jmp	board_init16
45.globl board_init16_ret
46board_init16_ret:
47
48	/* Turn of cache (this might require a 486-class CPU) */
49	movl	%cr0, %eax
50	orl	$(X86_CR0_NW | X86_CR0_CD), %eax
51	movl	%eax, %cr0
52	wbinvd
53
54	/* load the temporary Global Descriptor Table */
55o32 cs	lidt	idt_ptr
56o32 cs	lgdt	gdt_ptr
57
58	/* Now, we enter protected mode */
59	movl	%cr0, %eax
60	orl	$X86_CR0_PE, %eax
61	movl	%eax, %cr0
62
63	/* Flush the prefetch queue */
64	jmp	ff
65ff:
66	/* Finally jump to the 32bit initialization code */
67	movw	$code32start, %ax
68	movw	%ax, %bp
69o32 cs	ljmp	*(%bp)
70
71	/* 48-bit far pointer */
72code32start:
73	.long	_start		/* offset */
74	.word	0x10		/* segment */
75
76idt_ptr:
77	.word	0		/* limit */
78	.long	0		/* base */
79
80/*
81 * The following Global Descriptor Table is just enough to get us into
82 * 'Flat Protected Mode' - It will be discarded as soon as the final
83 * GDT is setup in a safe location in RAM
84 */
85gdt_ptr:
86	.word	0x20		/* limit (32 bytes = 4 GDT entries) */
87	.long	BOOT_SEG + gdt	/* base */
88
89/* Some CPUs are picky about GDT alignment... */
90.align 16
91gdt:
92	/*
93	 * The GDT table ...
94	 *
95	 *	 Selector	Type
96	 *	 0x00		NULL
97	 *	 0x08		Unused
98	 *	 0x10		32bit code
99	 *	 0x18		32bit data/stack
100	 */
101	/* The NULL Desciptor - Mandatory */
102	.word	0x0000		/* limit_low */
103	.word	0x0000		/* base_low */
104	.byte	0x00		/* base_middle */
105	.byte	0x00		/* access */
106	.byte	0x00		/* flags + limit_high */
107	.byte	0x00		/* base_high */
108
109	/* Unused Desciptor - (matches Linux) */
110	.word	0x0000		/* limit_low */
111	.word	0x0000		/* base_low */
112	.byte	0x00		/* base_middle */
113	.byte	0x00		/* access */
114	.byte	0x00		/* flags + limit_high */
115	.byte	0x00		/* base_high */
116
117	/*
118	 * The Code Segment Descriptor:
119	 * - Base   = 0x00000000
120	 * - Size   = 4GB
121	 * - Access = Present, Ring 0, Exec (Code), Readable
122	 * - Flags  = 4kB Granularity, 32-bit
123	 */
124	.word	0xffff		/* limit_low */
125	.word	0x0000		/* base_low */
126	.byte	0x00		/* base_middle */
127	.byte	0x9b		/* access */
128	.byte	0xcf		/* flags + limit_high */
129	.byte	0x00		/* base_high */
130
131	/*
132	 * The Data Segment Descriptor:
133	 * - Base   = 0x00000000
134	 * - Size   = 4GB
135	 * - Access = Present, Ring 0, Non-Exec (Data), Writable
136	 * - Flags  = 4kB Granularity, 32-bit
137	 */
138	.word	0xffff		/* limit_low */
139	.word	0x0000		/* base_low */
140	.byte	0x00		/* base_middle */
141	.byte	0x93		/* access */
142	.byte	0xcf		/* flags + limit_high */
143	.byte	0x00		/* base_high */
144