Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 2 | /* |
Bin Meng | 65db0c9 | 2015-01-20 11:25:44 +0800 | [diff] [blame] | 3 | * U-Boot - x86 Startup Code |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 4 | * |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 5 | * (C) Copyright 2008-2011 |
| 6 | * Graeme Russ, <graeme.russ@gmail.com> |
| 7 | * |
| 8 | * (C) Copyright 2002,2003 |
Albert ARIBAUD | 60fbc8d | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 9 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
Graeme Russ | 80ccbac | 2010-10-07 20:03:30 +1100 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Graeme Russ | 93efcb2 | 2011-02-12 15:11:32 +1100 | [diff] [blame] | 13 | #include <asm/processor-flags.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 14 | |
| 15 | #define BOOT_SEG 0xffff0000 /* linear segment of boot code */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 16 | |
| 17 | .section .start16, "ax" |
| 18 | .code16 |
| 19 | .globl start16 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 20 | start16: |
Simon Glass | 1f4476c | 2014-11-06 13:20:10 -0700 | [diff] [blame] | 21 | /* Save BIST */ |
| 22 | movl %eax, %ecx |
| 23 | |
Simon Glass | 727c414 | 2014-11-06 13:20:03 -0700 | [diff] [blame] | 24 | xorl %eax, %eax |
Bin Meng | 65db0c9 | 2015-01-20 11:25:44 +0800 | [diff] [blame] | 25 | movl %eax, %cr3 /* Invalidate TLB */ |
Simon Glass | 727c414 | 2014-11-06 13:20:03 -0700 | [diff] [blame] | 26 | |
Simon Glass | cbfd7ff | 2014-11-06 13:20:01 -0700 | [diff] [blame] | 27 | /* Turn off cache (this might require a 486-class CPU) */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 28 | movl %cr0, %eax |
Ondrej Kupka | 19c114a | 2011-09-30 21:05:11 +1100 | [diff] [blame] | 29 | orl $(X86_CR0_NW | X86_CR0_CD), %eax |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 30 | movl %eax, %cr0 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 31 | wbinvd |
| 32 | |
Graeme Russ | 59da5a5 | 2010-04-24 00:05:43 +1000 | [diff] [blame] | 33 | /* load the temporary Global Descriptor Table */ |
Masahiro Yamada | 19f2a6d | 2019-12-03 14:20:49 +0900 | [diff] [blame^] | 34 | data32 cs lidt idt_ptr |
| 35 | data32 cs lgdt gdt_ptr |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 36 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 37 | /* Now, we enter protected mode */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 38 | movl %cr0, %eax |
Graeme Russ | 93efcb2 | 2011-02-12 15:11:32 +1100 | [diff] [blame] | 39 | orl $X86_CR0_PE, %eax |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 40 | movl %eax, %cr0 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 41 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 42 | /* Flush the prefetch queue */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 43 | jmp ff |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 44 | ff: |
Simon Glass | 1f4476c | 2014-11-06 13:20:10 -0700 | [diff] [blame] | 45 | |
Bin Meng | 65db0c9 | 2015-01-20 11:25:44 +0800 | [diff] [blame] | 46 | /* Finally restore BIST and jump to the 32-bit initialization code */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 47 | movw $code32start, %ax |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 48 | movw %ax, %bp |
Simon Glass | 1f4476c | 2014-11-06 13:20:10 -0700 | [diff] [blame] | 49 | movl %ecx, %eax |
Masahiro Yamada | 19f2a6d | 2019-12-03 14:20:49 +0900 | [diff] [blame^] | 50 | data32 cs ljmp *(%bp) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 51 | |
| 52 | /* 48-bit far pointer */ |
| 53 | code32start: |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 54 | .long _start /* offset */ |
| 55 | .word 0x10 /* segment */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 56 | |
Graeme Russ | 4fdcc42 | 2010-08-22 16:25:59 +1000 | [diff] [blame] | 57 | idt_ptr: |
| 58 | .word 0 /* limit */ |
| 59 | .long 0 /* base */ |
| 60 | |
Bin Meng | 65db0c9 | 2015-01-20 11:25:44 +0800 | [diff] [blame] | 61 | /* |
| 62 | * The following Global Descriptor Table is just enough to get us into |
| 63 | * 'Flat Protected Mode' - It will be discarded as soon as the final |
| 64 | * GDT is setup in a safe location in RAM |
| 65 | */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 66 | gdt_ptr: |
Bin Meng | 0f39bc0 | 2014-10-16 22:58:35 +0800 | [diff] [blame] | 67 | .word 0x1f /* limit (31 bytes = 4 GDT entries - 1) */ |
Bin Meng | a3c9fb0 | 2015-06-07 11:33:13 +0800 | [diff] [blame] | 68 | .long BOOT_SEG + gdt_rom /* base */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 69 | |
Bin Meng | 65db0c9 | 2015-01-20 11:25:44 +0800 | [diff] [blame] | 70 | /* Some CPUs are picky about GDT alignment... */ |
| 71 | .align 16 |
Bin Meng | a3c9fb0 | 2015-06-07 11:33:13 +0800 | [diff] [blame] | 72 | .globl gdt_rom |
| 73 | gdt_rom: |
Graeme Russ | af3f2c8 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 74 | /* |
| 75 | * The GDT table ... |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 76 | * |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 77 | * Selector Type |
| 78 | * 0x00 NULL |
| 79 | * 0x08 Unused |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 80 | * 0x10 32bit code |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 81 | * 0x18 32bit data/stack |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 82 | */ |
Graeme Russ | af3f2c8 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 83 | /* The NULL Desciptor - Mandatory */ |
| 84 | .word 0x0000 /* limit_low */ |
| 85 | .word 0x0000 /* base_low */ |
| 86 | .byte 0x00 /* base_middle */ |
| 87 | .byte 0x00 /* access */ |
| 88 | .byte 0x00 /* flags + limit_high */ |
| 89 | .byte 0x00 /* base_high */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 90 | |
Graeme Russ | af3f2c8 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 91 | /* Unused Desciptor - (matches Linux) */ |
| 92 | .word 0x0000 /* limit_low */ |
| 93 | .word 0x0000 /* base_low */ |
| 94 | .byte 0x00 /* base_middle */ |
| 95 | .byte 0x00 /* access */ |
| 96 | .byte 0x00 /* flags + limit_high */ |
| 97 | .byte 0x00 /* base_high */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 98 | |
Graeme Russ | af3f2c8 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 99 | /* |
| 100 | * The Code Segment Descriptor: |
| 101 | * - Base = 0x00000000 |
| 102 | * - Size = 4GB |
| 103 | * - Access = Present, Ring 0, Exec (Code), Readable |
| 104 | * - Flags = 4kB Granularity, 32-bit |
| 105 | */ |
| 106 | .word 0xffff /* limit_low */ |
| 107 | .word 0x0000 /* base_low */ |
| 108 | .byte 0x00 /* base_middle */ |
| 109 | .byte 0x9b /* access */ |
| 110 | .byte 0xcf /* flags + limit_high */ |
| 111 | .byte 0x00 /* base_high */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 112 | |
Graeme Russ | af3f2c8 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 113 | /* |
| 114 | * The Data Segment Descriptor: |
| 115 | * - Base = 0x00000000 |
| 116 | * - Size = 4GB |
| 117 | * - Access = Present, Ring 0, Non-Exec (Data), Writable |
| 118 | * - Flags = 4kB Granularity, 32-bit |
| 119 | */ |
| 120 | .word 0xffff /* limit_low */ |
| 121 | .word 0x0000 /* base_low */ |
| 122 | .byte 0x00 /* base_middle */ |
| 123 | .byte 0x93 /* access */ |
| 124 | .byte 0xcf /* flags + limit_high */ |
| 125 | .byte 0x00 /* base_high */ |