head_32.S 18 KB

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