]> git.ipfire.org Git - people/ms/u-boot.git/blame - arch/x86/cpu/start16.S
Add GPL-2.0+ SPDX-License-Identifier to source files
[people/ms/u-boot.git] / arch / x86 / cpu / start16.S
CommitLineData
2262cfee 1/*
fea25720 2 * U-boot - x86 Startup Code
2262cfee 3 *
dbf7115a
GR
4 * (C) Copyright 2008-2011
5 * Graeme Russ, <graeme.russ@gmail.com>
6 *
7 * (C) Copyright 2002,2003
fa82f871 8 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
2262cfee 9 *
1a459660 10 * SPDX-License-Identifier: GPL-2.0+
2262cfee
WD
11 */
12
c81b26be 13#include <asm/global_data.h>
0c24c9cc 14#include <asm/processor-flags.h>
2262cfee
WD
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
8bde7f77 23start16:
91d82a29
GB
24 /* Set the Cold Boot / Hard Reset flag */
25 movl $GD_FLG_COLD_BOOT, %ebx
26
8ffb2e8f
GR
27 /*
28 * First we let the BSP do some early initialization
2262cfee
WD
29 * this code have to map the flash to its final position
30 */
2262cfee 31 jmp board_init16
88fa0a6e 32.globl board_init16_ret
8bde7f77
WD
33board_init16_ret:
34
2262cfee 35 /* Turn of cache (this might require a 486-class CPU) */
53677ef1 36 movl %cr0, %eax
7b3d5380 37 orl $(X86_CR0_NW | X86_CR0_CD), %eax
53677ef1 38 movl %eax, %cr0
8bde7f77
WD
39 wbinvd
40
c14a3669 41 /* load the temporary Global Descriptor Table */
797960fd 42o32 cs lidt idt_ptr
53677ef1 43o32 cs lgdt gdt_ptr
2262cfee 44
2262cfee 45 /* Now, we enter protected mode */
53677ef1 46 movl %cr0, %eax
0c24c9cc 47 orl $X86_CR0_PE, %eax
53677ef1 48 movl %eax, %cr0
8bde7f77 49
2262cfee 50 /* Flush the prefetch queue */
53677ef1 51 jmp ff
2262cfee 52ff:
2262cfee 53 /* Finally jump to the 32bit initialization code */
8bde7f77 54 movw $code32start, %ax
8ffb2e8f 55 movw %ax, %bp
2262cfee
WD
56o32 cs ljmp *(%bp)
57
58 /* 48-bit far pointer */
59code32start:
53677ef1
WD
60 .long _start /* offset */
61 .word 0x10 /* segment */
2262cfee 62
797960fd
GR
63idt_ptr:
64 .word 0 /* limit */
65 .long 0 /* base */
66
c14a3669
GR
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 */
2262cfee 72gdt_ptr:
c14a3669 73 .word 0x20 /* limit (32 bytes = 4 GDT entries) */
53677ef1 74 .long BOOT_SEG + gdt /* base */
2262cfee 75
58c7a675
GR
76/* Some CPUs are picky about GDT alignment... */
77.align 16
78gdt:
79 /*
80 * The GDT table ...
2262cfee 81 *
53677ef1
WD
82 * Selector Type
83 * 0x00 NULL
84 * 0x08 Unused
8bde7f77 85 * 0x10 32bit code
2262cfee 86 * 0x18 32bit data/stack
2262cfee 87 */
58c7a675
GR
88 /* The NULL Desciptor - Mandatory */
89 .word 0x0000 /* limit_low */
90 .word 0x0000 /* base_low */
91 .byte 0x00 /* base_middle */
92 .byte 0x00 /* access */
93 .byte 0x00 /* flags + limit_high */
94 .byte 0x00 /* base_high */
2262cfee 95
58c7a675
GR
96 /* Unused Desciptor - (matches Linux) */
97 .word 0x0000 /* limit_low */
98 .word 0x0000 /* base_low */
99 .byte 0x00 /* base_middle */
100 .byte 0x00 /* access */
101 .byte 0x00 /* flags + limit_high */
102 .byte 0x00 /* base_high */
53677ef1 103
58c7a675
GR
104 /*
105 * The Code Segment Descriptor:
106 * - Base = 0x00000000
107 * - Size = 4GB
108 * - Access = Present, Ring 0, Exec (Code), Readable
109 * - Flags = 4kB Granularity, 32-bit
110 */
111 .word 0xffff /* limit_low */
112 .word 0x0000 /* base_low */
113 .byte 0x00 /* base_middle */
114 .byte 0x9b /* access */
115 .byte 0xcf /* flags + limit_high */
116 .byte 0x00 /* base_high */
53677ef1 117
58c7a675
GR
118 /*
119 * The Data Segment Descriptor:
120 * - Base = 0x00000000
121 * - Size = 4GB
122 * - Access = Present, Ring 0, Non-Exec (Data), Writable
123 * - Flags = 4kB Granularity, 32-bit
124 */
125 .word 0xffff /* limit_low */
126 .word 0x0000 /* base_low */
127 .byte 0x00 /* base_middle */
128 .byte 0x93 /* access */
129 .byte 0xcf /* flags + limit_high */
130 .byte 0x00 /* base_high */