# 1 "/sources/tmptrees/LinuxBIOSv3-tmp/arch/x86/stage0_i586.S"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/sources/tmptrees/LinuxBIOSv3-tmp/build/config.h" 1
# 1 "<command-line>" 2
# 1 "/sources/tmptrees/LinuxBIOSv3-tmp/build/build.h" 1
# 1 "<command-line>" 2
# 1 "/sources/tmptrees/LinuxBIOSv3-tmp/arch/x86/stage0_i586.S"
##
## This file is part of the coreboot project.
##
## Copyright (C) 2000,2007 Ronald G. Minnich <rminnich@gmail.com>
## Copyright (C) 2005 Eswar Nallusamy, LANL
## Copyright (C) 2005 Tyan
## (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
## Copyright (C) 2007 coresystems GmbH
## (Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH)
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; version 2 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
##

# init code - switch cpu to pmode and enable cache as ram.

# 1 "/sources/tmptrees/LinuxBIOSv3-tmp/arch/x86/macros.h" 1
# 28 "/sources/tmptrees/LinuxBIOSv3-tmp/arch/x86/stage0_i586.S" 2






 .code16
 .globl _stage0
_stage0:
 cli


 movl %eax, %ebp;
# 49 "/sources/tmptrees/LinuxBIOSv3-tmp/arch/x86/stage0_i586.S"
 xorl %eax, %eax
 movl %eax, %cr3
# 59 "/sources/tmptrees/LinuxBIOSv3-tmp/arch/x86/stage0_i586.S"
 data32 lgdt %cs:gdtptr

 movl %cr0, %eax
 andl $0x7FFAFFD1, %eax
 orl $0x60000001, %eax
 movl %eax, %cr0


 movl %ebp, %eax




 data32 ljmp $0x08, $protected_stage0

 #.byte 0x66
 .code32
 #ljmp $0x08, $protected_stage0

 #.code16
 .align 4
 .globl gdt16
gdt16 = . - _stage0
gdt16x:
 .word gdt16xend - gdt16x -1
 .long gdt16x
 .word 0


 .word 0xffff, 0x0000
 .byte 0x00, 0x9b, 0xcf, 0x00


 .word 0xffff, 0x0000
 .byte 0x00, 0x93, 0xcf, 0x00
gdt16xend:



 .code32
# 111 "/sources/tmptrees/LinuxBIOSv3-tmp/arch/x86/stage0_i586.S"
 .align 4
 .globl gdtptr
 .globl gdt_limit
gdt_limit = gdt_end - gdt - 1

gdt:
gdtptr:
 .word gdt_end - gdt -1
 .long gdt
 .word 0


 .word 0xffff, 0x0000
 .byte 0x00, 0x9b, 0xcf, 0x00


 .word 0xffff, 0x0000
 .byte 0x00, 0x93, 0xcf, 0x00


 .word 0xffff, 0x0000
 .byte 0x00, 0x9b, 0xcf, 0x00


 .word 0xffff, 0x0000
 .byte 0x00, 0x93, 0xcf, 0x00
gdt_end:
# 151 "/sources/tmptrees/LinuxBIOSv3-tmp/arch/x86/stage0_i586.S"
 .align 4
 .globl protected_stage0
protected_stage0:

 lgdt %cs:gdtptr
 ljmp $0x08, $__protected_stage0

.globl __protected_stage0
__protected_stage0:

 movl %eax, %ebp

 movb $0x01, %al; outb %al, $0x80

 movw $0x10, %ax
 movw %ax, %ds
 movw %ax, %es
 movw %ax, %ss
 movw %ax, %fs
 movw %ax, %gs


 movl %ebp, %eax

.align 4
# 191 "/sources/tmptrees/LinuxBIOSv3-tmp/arch/x86/stage0_i586.S"
# 1 "/sources/tmptrees/LinuxBIOSv3-tmp/arch/x86/mtrr.h" 1
# 192 "/sources/tmptrees/LinuxBIOSv3-tmp/arch/x86/stage0_i586.S" 2


 movl %eax, %ebp

CacheAsRam:

        movl $01, %eax
        cpuid
        btl $28, %edx
        jnc NotHtProcessor
        bswapl %ebx
        cmpb $01, %bh
        jbe NotHtProcessor
# 215 "/sources/tmptrees/LinuxBIOSv3-tmp/arch/x86/stage0_i586.S"
        xorl %eax, %eax
        xorl %edx, %edx
        movl $0x250, %ecx
        wrmsr






        movl $0xFEE00020, %esi
        movl (%esi), %ebx
        andl $0xFF000000, %ebx
        bswapl %ebx
        btl $0, %ebx
        jnc LogicalAP0
        andb $0xFE, %bl
        jmp SendSIPI
LogicalAP0:
        orb $0x01, %bl
SendSIPI:
        bswapl %ebx






RetrySIPI:
        movl %ebx, %eax
        movl $0xFEE00310, %esi
        movl %eax, (%esi)


        movl $0x000006F9, %eax
        movl $0xFEE00300, %esi
        movl %eax, (%esi)

        movl $0x30, %ecx
SIPIDelay:
        pause
        decl %ecx
        jnz SIPIDelay

        movl (%esi), %eax
        andl $0x00001000, %eax
        jnz RetrySIPI


LogicalAPSIPINotdone:
        movl $0x250, %ecx
        rdmsr
        orl %eax, %eax
        jz LogicalAPSIPINotdone



NotHtProcessor:

        movl $0x2ff, %ecx
        xorl %edx, %edx

        movl $0x00000c00, %eax
        wrmsr


 xorl %edx, %edx
 movl $fixed_mtrr_msr, %esi
clear_fixed_var_mtrr:
        lodsl (%esi), %eax
        testl %eax, %eax
        jz clear_fixed_var_mtrr_out

        movl %eax, %ecx
        xorl %eax, %eax
        wrmsr

        jmp clear_fixed_var_mtrr
clear_fixed_var_mtrr_out:






.macro extractmask segs, reg
.if \segs <= 0




 xorl \reg, \reg
.elseif \segs == 1
 movl $0x06000000, \reg
.elseif \segs == 2
 movl $0x06060000, \reg
.elseif \segs == 3
 movl $0x06060600, \reg
.elseif \segs >= 4
 movl $0x06060606, \reg
.endif
.endm




.macro simplemask carsize, windowoffset
 .set gas_bug_workaround,(((\carsize - \windowoffset) / 0x1000) - 4)
 extractmask gas_bug_workaround, %eax
 .set gas_bug_workaround,(((\carsize - \windowoffset) / 0x1000))
 extractmask gas_bug_workaround, %edx





.endm
# 351 "/sources/tmptrees/LinuxBIOSv3-tmp/arch/x86/stage0_i586.S"
        movl $0x269, %ecx
 simplemask 0x1000, 0
 wrmsr
# 371 "/sources/tmptrees/LinuxBIOSv3-tmp/arch/x86/stage0_i586.S"
        movl %cr0, %eax
        andl $0x9fffffff,%eax
        movl %eax, %cr0


        movl $0x8f000, %esi
 cld
        movl $(0x1000>>2), %ecx
        rep lodsl


        movl $0x8f000, %edi
        movl $(0x1000>>2), %ecx
        xorl %eax, %eax
        rep stosl
# 433 "/sources/tmptrees/LinuxBIOSv3-tmp/arch/x86/stage0_i586.S"
 movl $(0x8f000 +0x1000 -4), %eax
 movl %eax, %esp


 movw $0x20, %ax
 movw %ax, %ds
 movw %ax, %es
 movw %ax, %ss

lout:




 movl $0x8f000, %eax
 pushl %eax


 movl %ebp, %eax

 movl %esp, %ebp
 pushl %eax
 call stage1_main

fixed_mtrr_msr:
        .long 0x250, 0x258, 0x259
        .long 0x268, 0x269, 0x26A
        .long 0x26B, 0x26C, 0x26D
        .long 0x26E, 0x26F
var_mtrr_msr:
        .long 0x200, 0x201, 0x202, 0x203
        .long 0x204, 0x205, 0x206, 0x207
        .long 0x208, 0x209, 0x20A, 0x20B
        .long 0x20C, 0x20D, 0x20E, 0x20F
        .long 0x000

# Reset vector.







SEGMENT_SIZE = 0x10000
RVECTOR = 0x00010
# Due to YET ANOTHER BUG in GNU bintools, you can NOT have a code16 here.
# I think we should leave it this way forever, as the bugs come and
# go -- and come again.
# .code16
# .section ".rom.text"
.section ".reset", "ax"
 .globl _resetjump
_resetjump:

# jmp _stage0
 .byte 0xe9
 .int _stage0 - ( . + 2 )






.byte 0

# Date? ID string? We might want to put something else in here.
.ascii "2008/04/04"

 # Checksum.
#.word 0
