Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Copyright (C) 1991, 1992  Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Enhanced CPU detection and feature setting code by Mike Jagdis
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  and Martin Mares, November 1997.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) .text
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/threads.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/linkage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/segment.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/page_types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/pgtable_types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <asm/thread_info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <asm/asm-offsets.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/processor-flags.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <asm/msr-index.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/cpufeatures.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <asm/percpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <asm/nops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <asm/bootparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <asm/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <asm/pgtable_32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) /* Physical address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define pa(X) ((X) - __PAGE_OFFSET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * References to members of the new_cpu_data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define X86		new_cpu_data+CPUINFO_x86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define X86_VENDOR	new_cpu_data+CPUINFO_x86_vendor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define X86_MODEL	new_cpu_data+CPUINFO_x86_model
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define X86_STEPPING	new_cpu_data+CPUINFO_x86_stepping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define X86_HARD_MATH	new_cpu_data+CPUINFO_hard_math
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define X86_CPUID	new_cpu_data+CPUINFO_cpuid_level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define X86_CAPABILITY	new_cpu_data+CPUINFO_x86_capability
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define X86_VENDOR_ID	new_cpu_data+CPUINFO_x86_vendor_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define SIZEOF_PTREGS 17*4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * Worst-case size of the kernel mapping we need to make:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * a relocatable kernel can live anywhere in lowmem, so we need to be able
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * to map all of lowmem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) KERNEL_PAGES = LOWMEM_PAGES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) RESERVE_BRK(pagetables, INIT_MAP_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * 32-bit kernel entrypoint; only used by the boot CPU.  On entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * %esi points to the real-mode code as a 32-bit pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * CS and DS must be 4 GB flat segments, but we don't depend on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * any particular GDT layout, because we load our own as soon as we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * can.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) __HEAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) SYM_CODE_START(startup_32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	movl pa(initial_stack),%ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * Set segments to known values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	lgdt pa(boot_gdt_descr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	movl $(__BOOT_DS),%eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	movl %eax,%ds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	movl %eax,%es
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	movl %eax,%fs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	movl %eax,%gs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	movl %eax,%ss
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	leal -__PAGE_OFFSET(%ecx),%esp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  * Clear BSS first so that there are no surprises...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	cld
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	xorl %eax,%eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	movl $pa(__bss_start),%edi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	movl $pa(__bss_stop),%ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	subl %edi,%ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	shrl $2,%ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	rep ; stosl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * Copy bootup parameters out of the way.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * Note: %esi still has the pointer to the real-mode data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * With the kexec as boot loader, parameter segment might be loaded beyond
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * kernel image and might not even be addressable by early boot page tables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * (kexec on panic case). Hence copy out the parameters before initializing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * page tables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	movl $pa(boot_params),%edi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	movl $(PARAM_SIZE/4),%ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	cld
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	rep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	movsl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	movl pa(boot_params) + NEW_CL_POINTER,%esi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	andl %esi,%esi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	jz 1f			# No command line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	movl $pa(boot_command_line),%edi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	movl $(COMMAND_LINE_SIZE/4),%ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	rep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	movsl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #ifdef CONFIG_OLPC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	/* save OFW's pgdir table for later use when calling into OFW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	movl %cr3, %eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	movl %eax, pa(olpc_ofw_pgd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #ifdef CONFIG_MICROCODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	/* Early load ucode on BSP. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	call load_ucode_bsp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	/* Create early pagetables. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	call  mk_early_pgtbl_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	/* Do early initialization of the fixmap area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #ifdef  CONFIG_X86_PAE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #define KPMDS (((-__PAGE_OFFSET) >> 30) & 3) /* Number of kernel PMDs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	movl %eax,pa(initial_page_table+0xffc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	jmp .Ldefault_entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) SYM_CODE_END(startup_32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #ifdef CONFIG_HOTPLUG_CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  * Boot CPU0 entry point. It's called from play_dead(). Everything has been set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * up already except stack. We just set up stack here. Then call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * start_secondary().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) SYM_FUNC_START(start_cpu0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	movl initial_stack, %ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	movl %ecx, %esp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	call *(initial_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 1:	jmp 1b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) SYM_FUNC_END(start_cpu0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  * Non-boot CPU entry point; entered from trampoline.S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  * We can't lgdt here, because lgdt itself uses a data segment, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  * we know the trampoline has already loaded the boot_gdt for us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  * If cpu hotplug is not supported then this code can go in init section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  * which will be freed later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) SYM_FUNC_START(startup_32_smp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	cld
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	movl $(__BOOT_DS),%eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	movl %eax,%ds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	movl %eax,%es
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	movl %eax,%fs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	movl %eax,%gs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	movl pa(initial_stack),%ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	movl %eax,%ss
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	leal -__PAGE_OFFSET(%ecx),%esp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) #ifdef CONFIG_MICROCODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	/* Early load ucode on AP. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	call load_ucode_ap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) .Ldefault_entry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	movl $(CR0_STATE & ~X86_CR0_PG),%eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	movl %eax,%cr0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * We want to start out with EFLAGS unambiguously cleared. Some BIOSes leave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  * bits like NT set. This would confuse the debugger if this code is traced. So
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * initialize them properly now before switching to protected mode. That means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  * DF in particular (even though we have cleared it earlier after copying the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  * command line) because GCC expects it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	pushl $0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	popfl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  * New page tables may be in 4Mbyte page mode and may be using the global pages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * NOTE! If we are on a 486 we may have no cr4 at all! Specifically, cr4 exists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * if and only if CPUID exists and has flags other than the FPU flag set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	movl $-1,pa(X86_CPUID)		# preset CPUID level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	movl $X86_EFLAGS_ID,%ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	pushl %ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	popfl				# set EFLAGS=ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	pushfl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	popl %eax			# get EFLAGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	testl $X86_EFLAGS_ID,%eax	# did EFLAGS.ID remained set?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	jz .Lenable_paging		# hw disallowed setting of ID bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 					# which means no CPUID and no CR4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	xorl %eax,%eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	cpuid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	movl %eax,pa(X86_CPUID)		# save largest std CPUID function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	movl $1,%eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	cpuid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	andl $~1,%edx			# Ignore CPUID.FPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	jz .Lenable_paging		# No flags or only CPUID.FPU = no CR4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	movl pa(mmu_cr4_features),%eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	movl %eax,%cr4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	testb $X86_CR4_PAE, %al		# check if PAE is enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	jz .Lenable_paging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	/* Check if extended functions are implemented */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	movl $0x80000000, %eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	cpuid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	/* Value must be in the range 0x80000001 to 0x8000ffff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	subl $0x80000001, %eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	cmpl $(0x8000ffff-0x80000001), %eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	ja .Lenable_paging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	/* Clear bogus XD_DISABLE bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	call verify_cpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	mov $0x80000001, %eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	cpuid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	/* Execute Disable bit supported? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	btl $(X86_FEATURE_NX & 31), %edx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	jnc .Lenable_paging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	/* Setup EFER (Extended Feature Enable Register) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	movl $MSR_EFER, %ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	rdmsr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	btsl $_EFER_NX, %eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	/* Make changes effective */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	wrmsr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) .Lenable_paging:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  * Enable paging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	movl $pa(initial_page_table), %eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	movl %eax,%cr3		/* set the page table pointer.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	movl $CR0_STATE,%eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	movl %eax,%cr0		/* ..and set paging (PG) bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	ljmp $__BOOT_CS,$1f	/* Clear prefetch and normalize %eip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	/* Shift the stack pointer to a virtual address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	addl $__PAGE_OFFSET, %esp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  * start system 32-bit setup. We need to re-do some of the things done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  * in 16-bit mode for the "real" operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	movl setup_once_ref,%eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	andl %eax,%eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	jz 1f				# Did we do this already?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	call *%eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)  * Check if it is 486
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	movb $4,X86			# at least 486
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	cmpl $-1,X86_CPUID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	je .Lis486
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	/* get vendor info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	xorl %eax,%eax			# call CPUID with 0 -> return vendor ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	cpuid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	movl %eax,X86_CPUID		# save CPUID level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	movl %ebx,X86_VENDOR_ID		# lo 4 chars
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	movl %edx,X86_VENDOR_ID+4	# next 4 chars
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	movl %ecx,X86_VENDOR_ID+8	# last 4 chars
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	orl %eax,%eax			# do we have processor info as well?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	je .Lis486
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	movl $1,%eax		# Use the CPUID instruction to get CPU type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	cpuid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	movb %al,%cl		# save reg for future use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	andb $0x0f,%ah		# mask processor family
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	movb %ah,X86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	andb $0xf0,%al		# mask model
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	shrb $4,%al
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	movb %al,X86_MODEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	andb $0x0f,%cl		# mask mask revision
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	movb %cl,X86_STEPPING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	movl %edx,X86_CAPABILITY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) .Lis486:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	movl $0x50022,%ecx	# set AM, WP, NE and MP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	movl %cr0,%eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	andl $0x80000011,%eax	# Save PG,PE,ET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	orl %ecx,%eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	movl %eax,%cr0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	lgdt early_gdt_descr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	ljmp $(__KERNEL_CS),$1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 1:	movl $(__KERNEL_DS),%eax	# reload all the segment registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	movl %eax,%ss			# after changing gdt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	movl $(__USER_DS),%eax		# DS/ES contains default USER segment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	movl %eax,%ds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	movl %eax,%es
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	movl $(__KERNEL_PERCPU), %eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	movl %eax,%fs			# set this cpu's percpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	movl $(__KERNEL_STACK_CANARY),%eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	movl %eax,%gs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	xorl %eax,%eax			# Clear LDT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	lldt %ax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	call *(initial_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 1:	jmp 1b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) SYM_FUNC_END(startup_32_smp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) #include "verify_cpu.S"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  *  setup_once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  *  The setup work we only want to run on the BSP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)  *  Warning: %esi is live across this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) __INIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) setup_once:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) #ifdef CONFIG_STACKPROTECTOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	 * Configure the stack canary. The linker can't handle this by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	 * relocation.  Manually set base address in stack canary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	 * segment descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	movl $gdt_page,%eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	movl $stack_canary,%ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	shrl $16, %ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	andl $0,setup_once_ref	/* Once is enough, thanks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	ret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) SYM_FUNC_START(early_idt_handler_array)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	# 36(%esp) %eflags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	# 32(%esp) %cs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	# 28(%esp) %eip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	# 24(%rsp) error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	i = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	.rept NUM_EXCEPTION_VECTORS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	.if ((EXCEPTION_ERRCODE_MASK >> i) & 1) == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	pushl $0		# Dummy error code, to make stack frame uniform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	.endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	pushl $i		# 20(%esp) Vector number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	jmp early_idt_handler_common
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	i = i + 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	.fill early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	.endr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) SYM_FUNC_END(early_idt_handler_array)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) SYM_CODE_START_LOCAL(early_idt_handler_common)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	 * The stack is the hardware frame, an error code or zero, and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	 * vector number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	cld
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	incl %ss:early_recursion_flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	/* The vector number is in pt_regs->gs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	cld
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	pushl	%fs		/* pt_regs->fs (__fsh varies by model) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	pushl	%es		/* pt_regs->es (__esh varies by model) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	pushl	%ds		/* pt_regs->ds (__dsh varies by model) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	pushl	%eax		/* pt_regs->ax */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	pushl	%ebp		/* pt_regs->bp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	pushl	%edi		/* pt_regs->di */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	pushl	%esi		/* pt_regs->si */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	pushl	%edx		/* pt_regs->dx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	pushl	%ecx		/* pt_regs->cx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	pushl	%ebx		/* pt_regs->bx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	/* Fix up DS and ES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	movl	$(__KERNEL_DS), %ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	movl	%ecx, %ds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	movl	%ecx, %es
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	/* Load the vector number into EDX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	movl	PT_GS(%esp), %edx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	/* Load GS into pt_regs->gs (and maybe clobber __gsh) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	movw	%gs, PT_GS(%esp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	movl	%esp, %eax	/* args are pt_regs (EAX), trapnr (EDX) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	call	early_fixup_exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	popl	%ebx		/* pt_regs->bx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	popl	%ecx		/* pt_regs->cx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	popl	%edx		/* pt_regs->dx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	popl	%esi		/* pt_regs->si */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	popl	%edi		/* pt_regs->di */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	popl	%ebp		/* pt_regs->bp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	popl	%eax		/* pt_regs->ax */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	popl	%ds		/* pt_regs->ds (always ignores __dsh) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	popl	%es		/* pt_regs->es (always ignores __esh) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	popl	%fs		/* pt_regs->fs (always ignores __fsh) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	popl	%gs		/* pt_regs->gs (always ignores __gsh) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	decl	%ss:early_recursion_flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	addl	$4, %esp	/* pop pt_regs->orig_ax */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	iret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) SYM_CODE_END(early_idt_handler_common)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) /* This is the default interrupt "handler" :-) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) SYM_FUNC_START(early_ignore_irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	cld
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) #ifdef CONFIG_PRINTK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	pushl %eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	pushl %ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	pushl %edx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	pushl %es
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	pushl %ds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	movl $(__KERNEL_DS),%eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	movl %eax,%ds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	movl %eax,%es
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	cmpl $2,early_recursion_flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	je hlt_loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	incl early_recursion_flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	pushl 16(%esp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	pushl 24(%esp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	pushl 32(%esp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	pushl 40(%esp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	pushl $int_msg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	call printk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	call dump_stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	addl $(5*4),%esp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	popl %ds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	popl %es
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	popl %edx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	popl %ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	popl %eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	iret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) hlt_loop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	hlt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	jmp hlt_loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) SYM_FUNC_END(early_ignore_irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) __INITDATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	.align 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) SYM_DATA(early_recursion_flag, .long 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) __REFDATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	.align 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) SYM_DATA(initial_code,		.long i386_start_kernel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) SYM_DATA(setup_once_ref,	.long setup_once)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) #ifdef CONFIG_PAGE_TABLE_ISOLATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) #define	PGD_ALIGN	(2 * PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) #define PTI_USER_PGD_FILL	1024
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) #define	PGD_ALIGN	(PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) #define PTI_USER_PGD_FILL	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)  * BSS section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) __PAGE_ALIGNED_BSS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	.align PGD_ALIGN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) #ifdef CONFIG_X86_PAE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) .globl initial_pg_pmd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) initial_pg_pmd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	.fill 1024*KPMDS,4,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) .globl initial_page_table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) initial_page_table:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	.fill 1024,4,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	.align PGD_ALIGN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) initial_pg_fixmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	.fill 1024,4,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) .globl swapper_pg_dir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	.align PGD_ALIGN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) swapper_pg_dir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	.fill 1024,4,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	.fill PTI_USER_PGD_FILL,4,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) .globl empty_zero_page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) empty_zero_page:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	.fill 4096,1,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) EXPORT_SYMBOL(empty_zero_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)  * This starts the data section.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) #ifdef CONFIG_X86_PAE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) __PAGE_ALIGNED_DATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	/* Page-aligned for the benefit of paravirt? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	.align PGD_ALIGN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) SYM_DATA_START(initial_page_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	.long	pa(initial_pg_pmd+PGD_IDENT_ATTR),0	/* low identity map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) # if KPMDS == 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	.long	pa(initial_pg_pmd+PGD_IDENT_ATTR),0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	.long	pa(initial_pg_pmd+PGD_IDENT_ATTR+0x1000),0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	.long	pa(initial_pg_pmd+PGD_IDENT_ATTR+0x2000),0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) # elif KPMDS == 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	.long	0,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	.long	pa(initial_pg_pmd+PGD_IDENT_ATTR),0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	.long	pa(initial_pg_pmd+PGD_IDENT_ATTR+0x1000),0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) # elif KPMDS == 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	.long	0,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	.long	0,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	.long	pa(initial_pg_pmd+PGD_IDENT_ATTR),0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) # else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) #  error "Kernel PMDs should be 1, 2 or 3"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) # endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	.align PAGE_SIZE		/* needs to be page-sized too */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) #ifdef CONFIG_PAGE_TABLE_ISOLATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	 * PTI needs another page so sync_initial_pagetable() works correctly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	 * and does not scribble over the data which is placed behind the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	 * actual initial_page_table. See clone_pgd_range().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	.fill 1024, 4, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) SYM_DATA_END(initial_page_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) .data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) .balign 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)  * The SIZEOF_PTREGS gap is a convention which helps the in-kernel unwinder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)  * reliably detect the end of the stack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) SYM_DATA(initial_stack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		.long init_thread_union + THREAD_SIZE -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 		SIZEOF_PTREGS - TOP_OF_KERNEL_STACK_PADDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) __INITRODATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) int_msg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	.asciz "Unknown interrupt or fault at: %p %p %p\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) #include "../../x86/xen/xen-head.S"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)  * The IDT and GDT 'descriptors' are a strange 48-bit object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)  * only used by the lidt and lgdt instructions. They are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)  * like usual segment descriptors - they consist of a 16-bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)  * segment size, and 32-bit linear address value:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	.data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	ALIGN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) # early boot GDT descriptor (must use 1:1 address mapping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	.word 0				# 32 bit align gdt_desc.address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) SYM_DATA_START_LOCAL(boot_gdt_descr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	.word __BOOT_DS+7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	.long boot_gdt - __PAGE_OFFSET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) SYM_DATA_END(boot_gdt_descr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) # boot GDT descriptor (later on used by CPU#0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	.word 0				# 32 bit align gdt_desc.address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) SYM_DATA_START(early_gdt_descr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	.word GDT_ENTRIES*8-1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	.long gdt_page			/* Overwritten for secondary CPUs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) SYM_DATA_END(early_gdt_descr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)  * The boot_gdt must mirror the equivalent in setup.S and is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)  * used only for booting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	.align L1_CACHE_BYTES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) SYM_DATA_START(boot_gdt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	.fill GDT_ENTRY_BOOT_CS,8,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	.quad 0x00cf9a000000ffff	/* kernel 4GB code at 0x00000000 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	.quad 0x00cf92000000ffff	/* kernel 4GB data at 0x00000000 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) SYM_DATA_END(boot_gdt)