Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / src / cpu / x86 / 16bit / entry16.inc
1 /*
2 This software and ancillary information (herein called SOFTWARE )
3 called LinuxBIOS          is made available under the terms described
4 here.  The SOFTWARE has been approved for release with associated
5 LA-CC Number 00-34   .  Unless otherwise indicated, this SOFTWARE has
6 been authored by an employee or employees of the University of
7 California, operator of the Los Alamos National Laboratory under
8 Contract No. W-7405-ENG-36 with the U.S. Department of Energy.  The
9 U.S. Government has rights to use, reproduce, and distribute this
10 SOFTWARE.  The public may copy, distribute, prepare derivative works
11 and publicly display this SOFTWARE without charge, provided that this
12 Notice and any statement of authorship are reproduced on all copies.
13 Neither the Government nor the University makes any warranty, express
14 or implied, or assumes any liability or responsibility for the use of
15 this SOFTWARE.  If SOFTWARE is modified to produce derivative works,
16 such modified SOFTWARE should be clearly marked, so as not to confuse
17 it with the version available from LANL.
18  */
19 /* Copyright 2000, Ron Minnich, Advanced Computing Lab, LANL
20  * rminnich@lanl.gov
21  */
22
23
24 /** Start code to put an i386 or later processor into 32-bit
25  * protected mode.
26  */
27
28 /* .section ".rom.text" */
29 #include <arch/rom_segs.h>
30 .code16
31 .globl _start
32 .type _start, @function
33
34 _start:
35         cli
36         /* Save the BIST result */
37         movl    %eax, %ebp
38
39 /* thanks to kmliu@sis.tw.com for this TBL fix ... */
40 /**/
41 /* IMMEDIATELY invalidate the translation lookaside buffer before executing*/
42 /* any further code.  Even though paging is disabled we could still get*/
43 /*false address translations due to the TLB if we didn't invalidate it.*/
44 /**/
45         xorl    %eax, %eax
46         movl    %eax, %cr3    /* Invalidate TLB*/
47
48
49         /* Invalidating the cache here seems to be a bad idea on
50          * modern processors.  Don't.
51          * If we are hyperthreaded or we have multiple cores it is bad,
52          * for SMP startup.  On Opterons it causes a 5 second delay.
53          * Invalidating the cache was pure paranoia in any event.
54          * If you cpu needs it you can write a cpu dependent version of
55          * entry16.inc.
56          */
57
58         /* Note: gas handles memory addresses in 16 bit code very poorly.
59          * In particular it doesn't appear to have a directive allowing you
60          * associate a section or even an absolute offset with a segment register.
61          *
62          * This means that anything except cs:ip relative offsets are
63          * a real pain in 16 bit mode.  And explains why it is almost
64          * imposible to get gas to do lgdt correctly.
65          *
66          * One way to work around this is to have the linker do the
67          * math instead of the assembler.  This solves the very
68          * pratical problem of being able to write code that can
69          * be relocated.
70          *
71          * An lgdt call before we have memory enabled cannot be
72          * position independent, as we cannot execute a call
73          * instruction to get our current instruction pointer.
74          * So while this code is relocateable it isn't arbitrarily
75          * relocatable.
76          *
77          * The criteria for relocation have been relaxed to their
78          * utmost, so that we can use the same code for both
79          * our initial entry point and startup of the second cpu.
80          * The code assumes when executing at _start that:
81          * (((cs & 0xfff) == 0) and (ip == _start & 0xffff))
82          * or
83          * ((cs == anything) and (ip == 0)).
84          *
85          * The restrictions in reset16.inc mean that _start initially
86          * must be loaded at or above 0xffff0000 or below 0x100000.
87          *
88          * The linker scripts computs gdtptr16_offset by simply returning
89          * the low 16 bits.  This means that the intial segment used
90          * when start is called must be 64K aligned.  This should not
91          * restrict the address as the ip address can be anything.
92          */
93
94         movw    %cs, %ax
95         shlw    $4, %ax
96         movw    $gdtptr16_offset, %bx
97         subw    %ax, %bx
98         data32  lgdt %cs:(%bx)
99
100         movl    %cr0, %eax
101         andl    $0x7FFAFFD1, %eax /* PG,AM,WP,NE,TS,EM,MP = 0 */
102         orl     $0x60000001, %eax /* CD, NW, PE = 1 */
103         movl    %eax, %cr0
104
105         /* Restore BIST to %eax */
106         movl    %ebp, %eax
107
108         /* Now that we are in protected mode jump to a 32 bit code segment. */
109         data32  ljmp    $ROM_CODE_SEG, $__protected_start
110
111         /**
112          * The gdt is defined in entry32.inc, it has a 4 Gb code segment
113          * at 0x08, and a 4 GB data segment at 0x10;
114          */
115 .align  4
116 .globl gdtptr16
117 gdtptr16:
118         .word   gdt_end - gdt -1 /* compute the table limit */
119         .long   gdt              /* we know the offset */
120
121 .globl _estart
122 _estart:
123         .code32
124