sysenter.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * linux/arch/i386/kernel/sysenter.c
  3. *
  4. * (C) Copyright 2002 Linus Torvalds
  5. *
  6. * This file contains the needed initializations to support sysenter.
  7. */
  8. #include <linux/init.h>
  9. #include <linux/smp.h>
  10. #include <linux/thread_info.h>
  11. #include <linux/sched.h>
  12. #include <linux/gfp.h>
  13. #include <linux/string.h>
  14. #include <linux/elf.h>
  15. #include <asm/cpufeature.h>
  16. #include <asm/msr.h>
  17. #include <asm/pgtable.h>
  18. #include <asm/unistd.h>
  19. extern asmlinkage void sysenter_entry(void);
  20. void enable_sep_cpu(void)
  21. {
  22. int cpu = get_cpu();
  23. struct tss_struct *tss = &per_cpu(init_tss, cpu);
  24. if (!boot_cpu_has(X86_FEATURE_SEP)) {
  25. put_cpu();
  26. return;
  27. }
  28. tss->ss1 = __KERNEL_CS;
  29. tss->esp1 = sizeof(struct tss_struct) + (unsigned long) tss;
  30. wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0);
  31. wrmsr(MSR_IA32_SYSENTER_ESP, tss->esp1, 0);
  32. wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long) sysenter_entry, 0);
  33. put_cpu();
  34. }
  35. /*
  36. * These symbols are defined by vsyscall.o to mark the bounds
  37. * of the ELF DSO images included therein.
  38. */
  39. extern const char vsyscall_int80_start, vsyscall_int80_end;
  40. extern const char vsyscall_sysenter_start, vsyscall_sysenter_end;
  41. int __init sysenter_setup(void)
  42. {
  43. void *page = (void *)get_zeroed_page(GFP_ATOMIC);
  44. __set_fixmap(FIX_VSYSCALL, __pa(page), PAGE_READONLY_EXEC);
  45. if (!boot_cpu_has(X86_FEATURE_SEP)) {
  46. memcpy(page,
  47. &vsyscall_int80_start,
  48. &vsyscall_int80_end - &vsyscall_int80_start);
  49. return 0;
  50. }
  51. memcpy(page,
  52. &vsyscall_sysenter_start,
  53. &vsyscall_sysenter_end - &vsyscall_sysenter_start);
  54. return 0;
  55. }