head_32.S 18 KB

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