wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 2 | * U-boot - i386 Startup Code |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 3 | * |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 4 | * Copyright (c) 2002, 2003 Omicron Ceti AB, Daniel Engström <denaiel@omicron.se> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | #define BOOT_SEG 0xffff0000 /* linear segment of boot code */ |
| 27 | #define a32 .byte 0x67; |
| 28 | #define o32 .byte 0x66; |
| 29 | |
| 30 | .section .start16, "ax" |
| 31 | .code16 |
| 32 | .globl start16 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 33 | start16: |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 34 | /* First we let the BSP do some early initialization |
| 35 | * this code have to map the flash to its final position |
| 36 | */ |
| 37 | mov $board_init16_ret, %bp |
| 38 | jmp board_init16 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 39 | board_init16_ret: |
| 40 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 41 | /* Turn of cache (this might require a 486-class CPU) */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 42 | movl %cr0, %eax |
| 43 | orl $0x60000000,%eax |
| 44 | movl %eax, %cr0 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 45 | wbinvd |
| 46 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 47 | /* load the descriptor tables */ |
| 48 | o32 cs lidt idt_ptr |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 49 | o32 cs lgdt gdt_ptr |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 50 | |
| 51 | |
| 52 | /* Now, we enter protected mode */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 53 | movl %cr0, %eax |
| 54 | orl $1,%eax |
| 55 | movl %eax, %cr0 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 56 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 57 | /* Flush the prefetch queue */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 58 | jmp ff |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 59 | ff: |
| 60 | |
| 61 | /* Finally jump to the 32bit initialization code */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 62 | movw $code32start, %ax |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 63 | movw %ax,%bp |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 64 | o32 cs ljmp *(%bp) |
| 65 | |
| 66 | /* 48-bit far pointer */ |
| 67 | code32start: |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 68 | .long _start /* offset */ |
| 69 | .word 0x10 /* segment */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 70 | |
| 71 | idt_ptr: |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 72 | .word 0 /* limit */ |
| 73 | .long 0 /* base */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 74 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 75 | gdt_ptr: |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 76 | .word 0x30 /* limit (48 bytes = 6 GDT entries) */ |
| 77 | .long BOOT_SEG + gdt /* base */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 78 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 79 | /* The GDT table ... |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 80 | * |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 81 | * Selector Type |
| 82 | * 0x00 NULL |
| 83 | * 0x08 Unused |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 84 | * 0x10 32bit code |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 85 | * 0x18 32bit data/stack |
| 86 | * 0x20 16bit code |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 87 | * 0x28 16bit data/stack |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 88 | */ |
| 89 | |
| 90 | gdt: |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 91 | .word 0, 0, 0, 0 /* NULL */ |
| 92 | .word 0, 0, 0, 0 /* unused */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 93 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 94 | .word 0xFFFF /* 4Gb - (0x100000*0x1000 = 4Gb) */ |
| 95 | .word 0 /* base address = 0 */ |
| 96 | .word 0x9B00 /* code read/exec */ |
| 97 | .word 0x00CF /* granularity = 4096, 386 (+5th nibble of limit) */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 98 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 99 | .word 0xFFFF /* 4Gb - (0x100000*0x1000 = 4Gb) */ |
| 100 | .word 0x0 /* base address = 0 */ |
| 101 | .word 0x9300 /* data read/write */ |
| 102 | .word 0x00CF /* granularity = 4096, 386 (+5th nibble of limit) */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 103 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 104 | .word 0xFFFF /* 64kb */ |
| 105 | .word 0 /* base address = 0 */ |
| 106 | .word 0x9b00 /* data read/write */ |
| 107 | .word 0x0010 /* granularity = 1 (+5th nibble of limit) */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 108 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 109 | .word 0xFFFF /* 64kb */ |
| 110 | .word 0 /* base address = 0 */ |
| 111 | .word 0x9300 /* data read/write */ |
| 112 | .word 0x0010 /* granularity = 1 (+5th nibble of limit) */ |