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