segments.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * segments.h
  3. *
  4. * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _SEGMENTS_H_
  20. #define _SEGMENTS_H_
  21. #include <common.h>
  22. #define GDT_MAX_ENTRIES 8
  23. #pragma pack(push, 1)
  24. typedef struct
  25. {
  26. dword_t limit : 16;
  27. dword_t base : 24;
  28. dword_t accessed : 1;
  29. dword_t readwrite : 1;
  30. dword_t dirconf : 1;
  31. dword_t executable : 1;
  32. dword_t standard : 1;
  33. dword_t rpl : 2;
  34. dword_t present : 1;
  35. dword_t limit_high : 4;
  36. dword_t always_zero : 2;
  37. dword_t size : 1;
  38. dword_t granularity : 1;
  39. dword_t base_high : 8;
  40. } gdt_descriptor_t;
  41. #pragma pack(pop)
  42. typedef struct
  43. {
  44. dword_t link;
  45. dword_t esp0;
  46. dword_t ss0;
  47. dword_t esp1;
  48. dword_t ss1;
  49. dword_t esp2;
  50. dword_t ss2;
  51. dword_t cr3;
  52. dword_t eip;
  53. dword_t eflags;
  54. dword_t eax;
  55. dword_t ecx;
  56. dword_t edx;
  57. dword_t ebx;
  58. dword_t esp;
  59. dword_t ebp;
  60. dword_t esi;
  61. dword_t edi;
  62. dword_t es;
  63. dword_t cs;
  64. dword_t ss;
  65. dword_t ds;
  66. dword_t fs;
  67. dword_t gs;
  68. dword_t ldtr;
  69. dword_t iopb;
  70. } tss_entry_t;
  71. void segments_init(void);
  72. dword_t get_kernel_esp(void);
  73. void set_kernel_esp(dword_t esp);
  74. word_t get_kernel_code_selector(void);
  75. word_t get_kernel_data_selector(void);
  76. word_t get_user_code_selector(void);
  77. word_t get_user_data_selector(void);
  78. word_t gdt_create_segment(dword_t base, dword_t limit, bool_t executable, byte_t priv_level, bool_t readwrite, bool_t dirconf, bool_t large);
  79. word_t gdt_create_tss(tss_entry_t *base, dword_t limit);
  80. #endif