head_32.S 18 KB

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