desc_64.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Written 2000 by Andi Kleen */
  2. #ifndef __ARCH_DESC_H
  3. #define __ARCH_DESC_H
  4. #include <linux/threads.h>
  5. #include <asm/ldt.h>
  6. #ifndef __ASSEMBLY__
  7. #include <linux/string.h>
  8. #include <asm/segment.h>
  9. static inline void _set_gate(int gate, unsigned type, unsigned long func,
  10. unsigned dpl, unsigned ist)
  11. {
  12. gate_desc s;
  13. s.offset_low = PTR_LOW(func);
  14. s.segment = __KERNEL_CS;
  15. s.ist = ist;
  16. s.p = 1;
  17. s.dpl = dpl;
  18. s.zero0 = 0;
  19. s.zero1 = 0;
  20. s.type = type;
  21. s.offset_middle = PTR_MIDDLE(func);
  22. s.offset_high = PTR_HIGH(func);
  23. /*
  24. * does not need to be atomic because it is only done once at
  25. * setup time
  26. */
  27. write_idt_entry(idt_table, gate, &s);
  28. }
  29. static inline void set_intr_gate(int nr, void *func)
  30. {
  31. BUG_ON((unsigned)nr > 0xFF);
  32. _set_gate(nr, GATE_INTERRUPT, (unsigned long) func, 0, 0);
  33. }
  34. static inline void set_intr_gate_ist(int nr, void *func, unsigned ist)
  35. {
  36. BUG_ON((unsigned)nr > 0xFF);
  37. _set_gate(nr, GATE_INTERRUPT, (unsigned long) func, 0, ist);
  38. }
  39. static inline void set_system_gate(int nr, void *func)
  40. {
  41. BUG_ON((unsigned)nr > 0xFF);
  42. _set_gate(nr, GATE_INTERRUPT, (unsigned long) func, 3, 0);
  43. }
  44. static inline void set_system_gate_ist(int nr, void *func, unsigned ist)
  45. {
  46. _set_gate(nr, GATE_INTERRUPT, (unsigned long) func, 3, ist);
  47. }
  48. static inline void set_tss_desc(unsigned cpu, void *addr)
  49. {
  50. struct desc_struct *d = get_cpu_gdt_table(cpu);
  51. tss_desc tss;
  52. /*
  53. * sizeof(unsigned long) coming from an extra "long" at the end
  54. * of the iobitmap. See tss_struct definition in processor.h
  55. *
  56. * -1? seg base+limit should be pointing to the address of the
  57. * last valid byte
  58. */
  59. set_tssldt_descriptor(&tss,
  60. (unsigned long)addr, DESC_TSS,
  61. IO_BITMAP_OFFSET + IO_BITMAP_BYTES + sizeof(unsigned long) - 1);
  62. write_gdt_entry(d, GDT_ENTRY_TSS, &tss, DESC_TSS);
  63. }
  64. #endif /* !__ASSEMBLY__ */
  65. #endif