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 | * |
| 10 | * See file CREDITS for list of people who contributed to this |
| 11 | * project. |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or |
| 14 | * modify it under the terms of the GNU General Public License as |
| 15 | * published by the Free Software Foundation; either version 2 of |
| 16 | * the License, or (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, write to the Free Software |
| 25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 26 | * MA 02111-1307 USA |
| 27 | */ |
| 28 | |
Graeme Russ | 80ccbac | 2010-10-07 20:03:30 +1100 | [diff] [blame] | 29 | #include <asm/global_data.h> |
Graeme Russ | 93efcb2 | 2011-02-12 15:11:32 +1100 | [diff] [blame] | 30 | #include <asm/processor-flags.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 31 | |
| 32 | #define BOOT_SEG 0xffff0000 /* linear segment of boot code */ |
| 33 | #define a32 .byte 0x67; |
| 34 | #define o32 .byte 0x66; |
| 35 | |
| 36 | .section .start16, "ax" |
| 37 | .code16 |
| 38 | .globl start16 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 39 | start16: |
Gabe Black | ef89932 | 2012-11-03 11:41:28 +0000 | [diff] [blame] | 40 | /* Set the Cold Boot / Hard Reset flag */ |
| 41 | movl $GD_FLG_COLD_BOOT, %ebx |
| 42 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 43 | /* |
| 44 | * First we let the BSP do some early initialization |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 45 | * this code have to map the flash to its final position |
| 46 | */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 47 | jmp board_init16 |
Graeme Russ | 157b0e9 | 2010-10-07 20:03:27 +1100 | [diff] [blame] | 48 | .globl board_init16_ret |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 49 | board_init16_ret: |
| 50 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 51 | /* Turn of cache (this might require a 486-class CPU) */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 52 | movl %cr0, %eax |
Ondrej Kupka | 19c114a | 2011-09-30 21:05:11 +1100 | [diff] [blame] | 53 | orl $(X86_CR0_NW | X86_CR0_CD), %eax |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 54 | movl %eax, %cr0 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 55 | wbinvd |
| 56 | |
Graeme Russ | 59da5a5 | 2010-04-24 00:05:43 +1000 | [diff] [blame] | 57 | /* load the temporary Global Descriptor Table */ |
Graeme Russ | 4fdcc42 | 2010-08-22 16:25:59 +1000 | [diff] [blame] | 58 | o32 cs lidt idt_ptr |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 59 | o32 cs lgdt gdt_ptr |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 60 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 61 | /* Now, we enter protected mode */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 62 | movl %cr0, %eax |
Graeme Russ | 93efcb2 | 2011-02-12 15:11:32 +1100 | [diff] [blame] | 63 | orl $X86_CR0_PE, %eax |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 64 | movl %eax, %cr0 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 65 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 66 | /* Flush the prefetch queue */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 67 | jmp ff |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 68 | ff: |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 69 | /* Finally jump to the 32bit initialization code */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 70 | movw $code32start, %ax |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 71 | movw %ax, %bp |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 72 | o32 cs ljmp *(%bp) |
| 73 | |
| 74 | /* 48-bit far pointer */ |
| 75 | code32start: |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 76 | .long _start /* offset */ |
| 77 | .word 0x10 /* segment */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 78 | |
Graeme Russ | 4fdcc42 | 2010-08-22 16:25:59 +1000 | [diff] [blame] | 79 | idt_ptr: |
| 80 | .word 0 /* limit */ |
| 81 | .long 0 /* base */ |
| 82 | |
Graeme Russ | 59da5a5 | 2010-04-24 00:05:43 +1000 | [diff] [blame] | 83 | /* |
| 84 | * The following Global Descriptor Table is just enough to get us into |
| 85 | * 'Flat Protected Mode' - It will be discarded as soon as the final |
| 86 | * GDT is setup in a safe location in RAM |
| 87 | */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 88 | gdt_ptr: |
Graeme Russ | 59da5a5 | 2010-04-24 00:05:43 +1000 | [diff] [blame] | 89 | .word 0x20 /* limit (32 bytes = 4 GDT entries) */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 90 | .long BOOT_SEG + gdt /* base */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 91 | |
Graeme Russ | af3f2c8 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 92 | /* Some CPUs are picky about GDT alignment... */ |
| 93 | .align 16 |
| 94 | gdt: |
| 95 | /* |
| 96 | * The GDT table ... |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 97 | * |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 98 | * Selector Type |
| 99 | * 0x00 NULL |
| 100 | * 0x08 Unused |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 101 | * 0x10 32bit code |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 102 | * 0x18 32bit data/stack |
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 | /* The NULL Desciptor - Mandatory */ |
| 105 | .word 0x0000 /* limit_low */ |
| 106 | .word 0x0000 /* base_low */ |
| 107 | .byte 0x00 /* base_middle */ |
| 108 | .byte 0x00 /* access */ |
| 109 | .byte 0x00 /* flags + limit_high */ |
| 110 | .byte 0x00 /* base_high */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 111 | |
Graeme Russ | af3f2c8 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 112 | /* Unused Desciptor - (matches Linux) */ |
| 113 | .word 0x0000 /* limit_low */ |
| 114 | .word 0x0000 /* base_low */ |
| 115 | .byte 0x00 /* base_middle */ |
| 116 | .byte 0x00 /* access */ |
| 117 | .byte 0x00 /* flags + limit_high */ |
| 118 | .byte 0x00 /* base_high */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 119 | |
Graeme Russ | af3f2c8 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 120 | /* |
| 121 | * The Code Segment Descriptor: |
| 122 | * - Base = 0x00000000 |
| 123 | * - Size = 4GB |
| 124 | * - Access = Present, Ring 0, Exec (Code), Readable |
| 125 | * - Flags = 4kB Granularity, 32-bit |
| 126 | */ |
| 127 | .word 0xffff /* limit_low */ |
| 128 | .word 0x0000 /* base_low */ |
| 129 | .byte 0x00 /* base_middle */ |
| 130 | .byte 0x9b /* access */ |
| 131 | .byte 0xcf /* flags + limit_high */ |
| 132 | .byte 0x00 /* base_high */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 133 | |
Graeme Russ | af3f2c8 | 2011-12-19 14:26:18 +1100 | [diff] [blame] | 134 | /* |
| 135 | * The Data Segment Descriptor: |
| 136 | * - Base = 0x00000000 |
| 137 | * - Size = 4GB |
| 138 | * - Access = Present, Ring 0, Non-Exec (Data), Writable |
| 139 | * - Flags = 4kB Granularity, 32-bit |
| 140 | */ |
| 141 | .word 0xffff /* limit_low */ |
| 142 | .word 0x0000 /* base_low */ |
| 143 | .byte 0x00 /* base_middle */ |
| 144 | .byte 0x93 /* access */ |
| 145 | .byte 0xcf /* flags + limit_high */ |
| 146 | .byte 0x00 /* base_high */ |