/arch/i386/kernel/sysenter.c

https://bitbucket.org/evzijst/gittest · C · 65 lines · 42 code · 12 blank · 11 comment · 1 complexity · bc213c217721410d95fb153afc8f17fb MD5 · raw file

  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 *info)
  21. {
  22. int cpu = get_cpu();
  23. struct tss_struct *tss = &per_cpu(init_tss, cpu);
  24. tss->ss1 = __KERNEL_CS;
  25. tss->esp1 = sizeof(struct tss_struct) + (unsigned long) tss;
  26. wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0);
  27. wrmsr(MSR_IA32_SYSENTER_ESP, tss->esp1, 0);
  28. wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long) sysenter_entry, 0);
  29. put_cpu();
  30. }
  31. /*
  32. * These symbols are defined by vsyscall.o to mark the bounds
  33. * of the ELF DSO images included therein.
  34. */
  35. extern const char vsyscall_int80_start, vsyscall_int80_end;
  36. extern const char vsyscall_sysenter_start, vsyscall_sysenter_end;
  37. static int __init sysenter_setup(void)
  38. {
  39. void *page = (void *)get_zeroed_page(GFP_ATOMIC);
  40. __set_fixmap(FIX_VSYSCALL, __pa(page), PAGE_READONLY_EXEC);
  41. if (!boot_cpu_has(X86_FEATURE_SEP)) {
  42. memcpy(page,
  43. &vsyscall_int80_start,
  44. &vsyscall_int80_end - &vsyscall_int80_start);
  45. return 0;
  46. }
  47. memcpy(page,
  48. &vsyscall_sysenter_start,
  49. &vsyscall_sysenter_end - &vsyscall_sysenter_start);
  50. on_each_cpu(enable_sep_cpu, NULL, 1, 1);
  51. return 0;
  52. }
  53. __initcall(sysenter_setup);