xref: /openbmc/u-boot/arch/x86/cpu/start16.S (revision 85ab0452)
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 * SPDX-License-Identifier:	GPL-2.0+
11 */
12
13#include <asm/global_data.h>
14#include <asm/processor-flags.h>
15
16#define BOOT_SEG	0xffff0000	/* linear segment of boot code */
17#define a32		.byte 0x67;
18#define o32		.byte 0x66;
19
20.section .start16, "ax"
21.code16
22.globl start16
23start16:
24	/* Save BIST */
25	movl	%eax, %ecx
26
27	/* Set the Cold Boot / Hard Reset flag */
28	movl	$GD_FLG_COLD_BOOT, %ebx
29
30	xorl	%eax, %eax
31	movl	%eax, %cr3	/* Invalidate TLB */
32
33	/* Turn off cache (this might require a 486-class CPU) */
34	movl	%cr0, %eax
35	orl	$(X86_CR0_NW | X86_CR0_CD), %eax
36	movl	%eax, %cr0
37	wbinvd
38
39	/* load the temporary Global Descriptor Table */
40o32 cs	lidt	idt_ptr
41o32 cs	lgdt	gdt_ptr
42
43	/* Now, we enter protected mode */
44	movl	%cr0, %eax
45	orl	$X86_CR0_PE, %eax
46	movl	%eax, %cr0
47
48	/* Flush the prefetch queue */
49	jmp	ff
50ff:
51
52	/* Finally restore BIST and jump to the 32-bit initialization code */
53	movw	$code32start, %ax
54	movw	%ax, %bp
55	movl	%ecx, %eax
56o32 cs	ljmp	*(%bp)
57
58	/* 48-bit far pointer */
59code32start:
60	.long	_start		/* offset */
61	.word	0x10		/* segment */
62
63idt_ptr:
64	.word	0		/* limit */
65	.long	0		/* base */
66
67	/*
68	 * The following Global Descriptor Table is just enough to get us into
69	 * 'Flat Protected Mode' - It will be discarded as soon as the final
70	 * GDT is setup in a safe location in RAM
71	 */
72gdt_ptr:
73	.word	0x1f		/* limit (31 bytes = 4 GDT entries - 1) */
74	.long	BOOT_SEG + gdt_rom	/* base */
75
76	/* Some CPUs are picky about GDT alignment... */
77	.align	16
78.globl gdt_rom
79gdt_rom:
80	/*
81	 * The GDT table ...
82	 *
83	 *	 Selector	Type
84	 *	 0x00		NULL
85	 *	 0x08		Unused
86	 *	 0x10		32bit code
87	 *	 0x18		32bit data/stack
88	 */
89	/* The NULL Desciptor - Mandatory */
90	.word	0x0000		/* limit_low */
91	.word	0x0000		/* base_low */
92	.byte	0x00		/* base_middle */
93	.byte	0x00		/* access */
94	.byte	0x00		/* flags + limit_high */
95	.byte	0x00		/* base_high */
96
97	/* Unused Desciptor - (matches Linux) */
98	.word	0x0000		/* limit_low */
99	.word	0x0000		/* base_low */
100	.byte	0x00		/* base_middle */
101	.byte	0x00		/* access */
102	.byte	0x00		/* flags + limit_high */
103	.byte	0x00		/* base_high */
104
105	/*
106	 * The Code Segment Descriptor:
107	 * - Base   = 0x00000000
108	 * - Size   = 4GB
109	 * - Access = Present, Ring 0, Exec (Code), Readable
110	 * - Flags  = 4kB Granularity, 32-bit
111	 */
112	.word	0xffff		/* limit_low */
113	.word	0x0000		/* base_low */
114	.byte	0x00		/* base_middle */
115	.byte	0x9b		/* access */
116	.byte	0xcf		/* flags + limit_high */
117	.byte	0x00		/* base_high */
118
119	/*
120	 * The Data Segment Descriptor:
121	 * - Base   = 0x00000000
122	 * - Size   = 4GB
123	 * - Access = Present, Ring 0, Non-Exec (Data), Writable
124	 * - Flags  = 4kB Granularity, 32-bit
125	 */
126	.word	0xffff		/* limit_low */
127	.word	0x0000		/* base_low */
128	.byte	0x00		/* base_middle */
129	.byte	0x93		/* access */
130	.byte	0xcf		/* flags + limit_high */
131	.byte	0x00		/* base_high */
132