wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
Graeme Russ | fea2572 | 2011-04-13 19:43:28 +1000 | [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 | * |
| 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 | c81b26b | 2010-10-07 20:03:30 +1100 | [diff] [blame] | 29 | #include <asm/global_data.h> |
Graeme Russ | 0c24c9c | 2011-02-12 15:11:32 +1100 | [diff] [blame] | 30 | #include <asm/processor-flags.h> |
wdenk | 2262cfe | 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 | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 39 | start16: |
Graeme Russ | 8ffb2e8 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 40 | /* |
| 41 | * First we let the BSP do some early initialization |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 42 | * this code have to map the flash to its final position |
| 43 | */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 44 | jmp board_init16 |
Graeme Russ | 88fa0a6 | 2010-10-07 20:03:27 +1100 | [diff] [blame] | 45 | .globl board_init16_ret |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 46 | board_init16_ret: |
| 47 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 48 | /* Turn of cache (this might require a 486-class CPU) */ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 49 | movl %cr0, %eax |
Ondrej Kupka | 7b3d538 | 2011-09-30 21:05:11 +1100 | [diff] [blame] | 50 | orl $(X86_CR0_NW | X86_CR0_CD), %eax |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 51 | movl %eax, %cr0 |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 52 | wbinvd |
| 53 | |
Graeme Russ | c14a366 | 2010-04-24 00:05:43 +1000 | [diff] [blame] | 54 | /* load the temporary Global Descriptor Table */ |
Graeme Russ | 797960f | 2010-08-22 16:25:59 +1000 | [diff] [blame] | 55 | o32 cs lidt idt_ptr |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 56 | o32 cs lgdt gdt_ptr |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 57 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 58 | /* Now, we enter protected mode */ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 59 | movl %cr0, %eax |
Graeme Russ | 0c24c9c | 2011-02-12 15:11:32 +1100 | [diff] [blame] | 60 | orl $X86_CR0_PE, %eax |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 61 | movl %eax, %cr0 |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 62 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 63 | /* Flush the prefetch queue */ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 64 | jmp ff |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 65 | ff: |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 66 | /* Finally jump to the 32bit initialization code */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 67 | movw $code32start, %ax |
Graeme Russ | 8ffb2e8 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 68 | movw %ax, %bp |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 69 | o32 cs ljmp *(%bp) |
| 70 | |
| 71 | /* 48-bit far pointer */ |
| 72 | code32start: |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 73 | .long _start /* offset */ |
| 74 | .word 0x10 /* segment */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 75 | |
Graeme Russ | 797960f | 2010-08-22 16:25:59 +1000 | [diff] [blame] | 76 | idt_ptr: |
| 77 | .word 0 /* limit */ |
| 78 | .long 0 /* base */ |
| 79 | |
Graeme Russ | c14a366 | 2010-04-24 00:05:43 +1000 | [diff] [blame] | 80 | /* |
| 81 | * The following Global Descriptor Table is just enough to get us into |
| 82 | * 'Flat Protected Mode' - It will be discarded as soon as the final |
| 83 | * GDT is setup in a safe location in RAM |
| 84 | */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 85 | gdt_ptr: |
Graeme Russ | c14a366 | 2010-04-24 00:05:43 +1000 | [diff] [blame] | 86 | .word 0x20 /* limit (32 bytes = 4 GDT entries) */ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 87 | .long BOOT_SEG + gdt /* base */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 88 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 89 | /* The GDT table ... |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 90 | * |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 91 | * Selector Type |
| 92 | * 0x00 NULL |
| 93 | * 0x08 Unused |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 94 | * 0x10 32bit code |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 95 | * 0x18 32bit data/stack |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 96 | */ |
| 97 | |
| 98 | gdt: |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 99 | .word 0, 0, 0, 0 /* NULL */ |
| 100 | .word 0, 0, 0, 0 /* unused */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 101 | |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 102 | .word 0xFFFF /* 4Gb - (0x100000*0x1000 = 4Gb) */ |
| 103 | .word 0 /* base address = 0 */ |
| 104 | .word 0x9B00 /* code read/exec */ |
| 105 | .word 0x00CF /* granularity = 4096, 386 (+5th nibble of limit) */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 106 | |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 107 | .word 0xFFFF /* 4Gb - (0x100000*0x1000 = 4Gb) */ |
| 108 | .word 0x0 /* base address = 0 */ |
| 109 | .word 0x9300 /* data read/write */ |
| 110 | .word 0x00CF /* granularity = 4096, 386 (+5th nibble of limit) */ |