wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
Bin Meng | fea1c47 | 2015-01-20 11:25:44 +0800 | [diff] [blame] | 2 | * U-Boot - x86 Startup Code |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 3 | * |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 4 | * (C) Copyright 2008-2011 |
| 5 | * Graeme Russ, <graeme.russ@gmail.com> |
| 6 | * |
| 7 | * (C) Copyright 2002,2003 |
Albert ARIBAUD | fa82f87 | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 8 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 9 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 10 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
Graeme Russ | c81b26b | 2010-10-07 20:03:30 +1100 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Graeme Russ | 0c24c9c | 2011-02-12 15:11:32 +1100 | [diff] [blame] | 14 | #include <asm/processor-flags.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 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 |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 23 | start16: |
Simon Glass | f67cd51 | 2014-11-06 13:20:10 -0700 | [diff] [blame] | 24 | /* Save BIST */ |
| 25 | movl %eax, %ecx |
| 26 | |
Gabe Black | 91d82a2 | 2012-11-03 11:41:28 +0000 | [diff] [blame] | 27 | /* Set the Cold Boot / Hard Reset flag */ |
| 28 | movl $GD_FLG_COLD_BOOT, %ebx |
| 29 | |
Simon Glass | 3c00695 | 2014-11-06 13:20:03 -0700 | [diff] [blame] | 30 | xorl %eax, %eax |
Bin Meng | fea1c47 | 2015-01-20 11:25:44 +0800 | [diff] [blame] | 31 | movl %eax, %cr3 /* Invalidate TLB */ |
Simon Glass | 3c00695 | 2014-11-06 13:20:03 -0700 | [diff] [blame] | 32 | |
Simon Glass | 85d8732 | 2014-11-06 13:20:01 -0700 | [diff] [blame] | 33 | /* Turn off cache (this might require a 486-class CPU) */ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 34 | movl %cr0, %eax |
Ondrej Kupka | 7b3d538 | 2011-09-30 21:05:11 +1100 | [diff] [blame] | 35 | orl $(X86_CR0_NW | X86_CR0_CD), %eax |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 36 | movl %eax, %cr0 |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 37 | wbinvd |
| 38 | |
Graeme Russ | c14a366 | 2010-04-24 00:05:43 +1000 | [diff] [blame] | 39 | /* load the temporary Global Descriptor Table */ |
Graeme Russ | 797960f | 2010-08-22 16:25:59 +1000 | [diff] [blame] | 40 | o32 cs lidt idt_ptr |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 41 | o32 cs lgdt gdt_ptr |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 42 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 43 | /* Now, we enter protected mode */ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 44 | movl %cr0, %eax |
Graeme Russ | 0c24c9c | 2011-02-12 15:11:32 +1100 | [diff] [blame] | 45 | orl $X86_CR0_PE, %eax |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 46 | movl %eax, %cr0 |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 47 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 48 | /* Flush the prefetch queue */ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 49 | jmp ff |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 50 | ff: |
Simon Glass | f67cd51 | 2014-11-06 13:20:10 -0700 | [diff] [blame] | 51 | |
Bin Meng | fea1c47 | 2015-01-20 11:25:44 +0800 | [diff] [blame] | 52 | /* Finally restore BIST and jump to the 32-bit initialization code */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 53 | movw $code32start, %ax |
Graeme Russ | 8ffb2e8 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 54 | movw %ax, %bp |
Simon Glass | f67cd51 | 2014-11-06 13:20:10 -0700 | [diff] [blame] | 55 | movl %ecx, %eax |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 56 | o32 cs ljmp *(%bp) |
| 57 | |
| 58 | /* 48-bit far pointer */ |
| 59 | code32start: |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 60 | .long _start /* offset */ |
| 61 | .word 0x10 /* segment */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 62 | |
Graeme Russ | 797960f | 2010-08-22 16:25:59 +1000 | [diff] [blame] | 63 | idt_ptr: |
| 64 | .word 0 /* limit */ |
| 65 | .long 0 /* base */ |
| 66 | |
Bin Meng | fea1c47 | 2015-01-20 11:25:44 +0800 | [diff] [blame] | 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 | */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 72 | gdt_ptr: |
Bin Meng | 35d4fed | 2014-10-16 22:58:35 +0800 | [diff] [blame] | 73 | .word 0x1f /* limit (31 bytes = 4 GDT entries - 1) */ |
Bin Meng | 002610f | 2015-06-07 11:33:13 +0800 | [diff] [blame] | 74 | .long BOOT_SEG + gdt_rom /* base */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 75 | |
Bin Meng | fea1c47 | 2015-01-20 11:25:44 +0800 | [diff] [blame] | 76 | /* Some CPUs are picky about GDT alignment... */ |
| 77 | .align 16 |
Bin Meng | 002610f | 2015-06-07 11:33:13 +0800 | [diff] [blame] | 78 | .globl gdt_rom |
| 79 | gdt_rom: |
Graeme Russ | 58c7a67 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 80 | /* |
| 81 | * The GDT table ... |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 82 | * |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 83 | * Selector Type |
| 84 | * 0x00 NULL |
| 85 | * 0x08 Unused |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 86 | * 0x10 32bit code |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 87 | * 0x18 32bit data/stack |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 88 | */ |
Graeme Russ | 58c7a67 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 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 */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 96 | |
Graeme Russ | 58c7a67 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 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 */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 104 | |
Graeme Russ | 58c7a67 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 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 */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 118 | |
Graeme Russ | 58c7a67 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 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 */ |