head_32.S 19 KB

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