wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
Graeme Russ | cbfce1d | 2011-04-13 19:43:28 +1000 | [diff] [blame] | 2 | * U-boot - x86 Startup Code |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 3 | * |
Graeme Russ | 45fc1d8 | 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 | 60fbc8d | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 8 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 9 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 10 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
Graeme Russ | 80ccbac | 2010-10-07 20:03:30 +1100 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Graeme Russ | 93efcb2 | 2011-02-12 15:11:32 +1100 | [diff] [blame] | 14 | #include <asm/processor-flags.h> |
wdenk | 591dda5 | 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 | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 23 | start16: |
Gabe Black | ef89932 | 2012-11-03 11:41:28 +0000 | [diff] [blame] | 24 | /* Set the Cold Boot / Hard Reset flag */ |
| 25 | movl $GD_FLG_COLD_BOOT, %ebx |
| 26 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 27 | /* |
| 28 | * First we let the BSP do some early initialization |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 29 | * this code have to map the flash to its final position |
| 30 | */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 31 | jmp board_init16 |
Graeme Russ | 157b0e9 | 2010-10-07 20:03:27 +1100 | [diff] [blame] | 32 | .globl board_init16_ret |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 33 | board_init16_ret: |
| 34 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 35 | /* Turn of cache (this might require a 486-class CPU) */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 36 | movl %cr0, %eax |
Ondrej Kupka | 19c114a | 2011-09-30 21:05:11 +1100 | [diff] [blame] | 37 | orl $(X86_CR0_NW | X86_CR0_CD), %eax |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 38 | movl %eax, %cr0 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 39 | wbinvd |
| 40 | |
Graeme Russ | 59da5a5 | 2010-04-24 00:05:43 +1000 | [diff] [blame] | 41 | /* load the temporary Global Descriptor Table */ |
Graeme Russ | 4fdcc42 | 2010-08-22 16:25:59 +1000 | [diff] [blame] | 42 | o32 cs lidt idt_ptr |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 43 | o32 cs lgdt gdt_ptr |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 44 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 45 | /* Now, we enter protected mode */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 46 | movl %cr0, %eax |
Graeme Russ | 93efcb2 | 2011-02-12 15:11:32 +1100 | [diff] [blame] | 47 | orl $X86_CR0_PE, %eax |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 48 | movl %eax, %cr0 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 49 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 50 | /* Flush the prefetch queue */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 51 | jmp ff |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 52 | ff: |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 53 | /* Finally jump to the 32bit initialization code */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 54 | movw $code32start, %ax |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 55 | movw %ax, %bp |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 56 | o32 cs ljmp *(%bp) |
| 57 | |
| 58 | /* 48-bit far pointer */ |
| 59 | code32start: |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 60 | .long _start /* offset */ |
| 61 | .word 0x10 /* segment */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 62 | |
Graeme Russ | 4fdcc42 | 2010-08-22 16:25:59 +1000 | [diff] [blame] | 63 | idt_ptr: |
| 64 | .word 0 /* limit */ |
| 65 | .long 0 /* base */ |
| 66 | |
Graeme Russ | 59da5a5 | 2010-04-24 00:05:43 +1000 | [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 | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 72 | gdt_ptr: |
Graeme Russ | 59da5a5 | 2010-04-24 00:05:43 +1000 | [diff] [blame] | 73 | .word 0x20 /* limit (32 bytes = 4 GDT entries) */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 74 | .long BOOT_SEG + gdt /* base */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 75 | |
Graeme Russ | af3f2c8 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 76 | /* Some CPUs are picky about GDT alignment... */ |
| 77 | .align 16 |
| 78 | gdt: |
| 79 | /* |
| 80 | * The GDT table ... |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 81 | * |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 82 | * Selector Type |
| 83 | * 0x00 NULL |
| 84 | * 0x08 Unused |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 85 | * 0x10 32bit code |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 86 | * 0x18 32bit data/stack |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 87 | */ |
Graeme Russ | af3f2c8 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 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 */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 95 | |
Graeme Russ | af3f2c8 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 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 */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 103 | |
Graeme Russ | af3f2c8 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 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 */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 117 | |
Graeme Russ | af3f2c8 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 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 */ |