7#ifndef ZEPHYR_INCLUDE_ARCH_X86_IA32_SEGMENTATION_H_
8#define ZEPHYR_INCLUDE_ARCH_X86_IA32_SEGMENTATION_H_
14#define __packed __attribute__((packed))
25#define SEG_TYPE_LDT 0x2
26#define SEG_TYPE_TASK_GATE 0x5
27#define SEG_TYPE_TSS 0x9
28#define SEG_TYPE_TSS_BUSY 0xB
29#define SEG_TYPE_CALL_GATE 0xC
30#define SEG_TYPE_IRQ_GATE 0xE
31#define SEG_TYPE_TRAP_GATE 0xF
37#define DT_NON_READABLE 0
40#define DT_NON_WRITABLE 0
42#define DT_EXPAND_DOWN 1
46#define DT_NONCONFORM 0
48#define DT_TYPE_SYSTEM 0
49#define DT_TYPE_CODEDATA 1
96#define SEG_SELECTOR(index, table, dpl) (index << 3 | table << 2 | dpl)
232#define DT_ZERO_ENTRY { { 0 } }
243#define _LIMIT_AND_BASE(base_p, limit_p, granularity_p) \
244 .base_low = (((uint32_t)base_p) & 0xFFFF), \
245 .base_mid = (((base_p) >> 16) & 0xFF), \
246 .base_hi = (((base_p) >> 24) & 0xFF), \
247 .limit_low = ((limit_p) & 0xFFFF), \
248 .limit_hi = (((limit_p) >> 16) & 0xF), \
249 .granularity = (granularity_p), \
254#define _SEGMENT_AND_OFFSET(segment_p, offset_p) \
255 .segment_selector = (segment_p), \
256 .offset_low = ((offset_p) & 0xFFFF), \
257 .offset_hi = ((offset_p) >> 16)
259#define _DESC_COMMON(dpl_p) \
263#define _SYS_DESC(type_p) \
267#define DT_CODE_SEG_ENTRY(base_p, limit_p, granularity_p, dpl_p, readable_p, \
270 _DESC_COMMON(dpl_p), \
271 _LIMIT_AND_BASE(base_p, limit_p, granularity_p), \
273 .rw = (readable_p), \
274 .cd = (conforming_p), \
276 .descriptor_type = 1 \
279#define DT_DATA_SEG_ENTRY(base_p, limit_p, granularity_p, dpl_p, writable_p, \
282 _DESC_COMMON(dpl_p), \
283 _LIMIT_AND_BASE(base_p, limit_p, granularity_p), \
285 .rw = (writable_p), \
286 .cd = (direction_p), \
288 .descriptor_type = 1 \
291#define DT_LDT_ENTRY(base_p, limit_p, granularity_p, dpl_p) \
293 _DESC_COMMON(dpl_p), \
294 _LIMIT_AND_BASE(base_p, limit_p, granularity_p), \
295 _SYS_DESC(SEG_TYPE_LDT) \
298#define DT_TSS_ENTRY(base_p, limit_p, granularity_p, dpl_p) \
300 _DESC_COMMON(dpl_p), \
301 _LIMIT_AND_BASE(base_p, limit_p, granularity_p), \
302 _SYS_DESC(SEG_TYPE_TSS) \
308#define DT_TSS_STD_ENTRY(base_p, dpl_p) \
309 DT_TSS_ENTRY(base_p, sizeof(struct task_state_segment), DT_GRAN_BYTE, \
312#define DT_TASK_GATE_ENTRY(segment_p, dpl_p) \
314 _DESC_COMMON(dpl_p), \
315 _SYS_DESC(SEG_TYPE_TASK_GATE), \
316 .segment_selector = (segment_p) \
319#define DT_IRQ_GATE_ENTRY(segment_p, offset_p, dpl_p) \
321 _DESC_COMMON(dpl_p), \
322 _SEGMENT_AND_OFFSET(segment_p, offset_p), \
323 _SYS_DESC(SEG_TYPE_IRQ_GATE), \
327#define DT_TRAP_GATE_ENTRY(segment_p, offset_p, dpl_p) \
329 _DESC_COMMON(dpl_p), \
330 _SEGMENT_AND_OFFSET(segment_p, offset_p), \
331 _SYS_DESC(SEG_TYPE_TRAP_GATE), \
335#define DT_CALL_GATE_ENTRY(segment_p, offset_p, dpl_p, param_count_p) \
337 _DESC_COMMON(dpl_p), \
338 _SEGMENT_AND_OFFSET(segment_p, offset_p), \
339 _SYS_DESC(SEG_TYPE_TRAP_GATE), \
340 .reserved_or_param = (param_count_p), \
344#define DTE_BASE(dt_entry) ((dt_entry)->base_low | \
345 ((dt_entry)->base_mid << 16) | \
346 ((dt_entry)->base_hi << 24))
348#define DTE_LIMIT(dt_entry) ((dt_entry)->limit_low | \
349 ((dt_entry)->limit_hi << 16))
351#define DTE_OFFSET(dt_entry) ((dt_entry)->offset_low | \
352 ((dt_entry)->offset_hi << 16))
354#define DT_INIT(entries) { sizeof(entries) - 1, &entries[0] }
397 z_sd_set_seg_offset(sd, seg_selector, offset);
409static inline void _set_tss(
uint16_t sel)
411 __asm__ __volatile__ (
"ltr %0" ::
"r" (sel));
420static inline uint16_t _get_tss(
void)
424 __asm__ __volatile__ (
"str %0" :
"=r" (sel));
436 __asm__ __volatile__ (
"sgdt %0" :
"=m" (*gdt));
447 __asm__ __volatile__ (
"sidt %0" :
"=m" (*idt));
456static inline uint16_t _get_ldt(
void)
460 __asm__ __volatile__ (
"sldt %0" :
"=m" (ret));
470static inline void _set_ldt(
uint16_t ldt)
472 __asm__ __volatile__ (
"lldt %0" ::
"m" (ldt));
486 __asm__ __volatile__ (
"lgdt %0" ::
"m" (*gdt));
497 __asm__ __volatile__ (
"lidt %0" ::
"m" (*idt));
510 __asm__ __volatile__ (
"mov %%cs, %0" :
"=r" (cs));
524 __asm__ __volatile__ (
"mov %%ds, %0" :
"=r" (ds));
#define SEG_TYPE_IRQ_GATE
Definition segmentation.h:30
#define DT_TYPE_SYSTEM
Definition segmentation.h:48
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Definition segmentation.h:224
void * offset
Far pointer offset, unused when invoking a task.
Definition segmentation.h:226
uint16_t sel
Far pointer segment/gate selector.
Definition segmentation.h:228
Definition segmentation.h:215
uint16_t size
Definition segmentation.h:216
struct segment_descriptor * entries
Definition segmentation.h:217
Definition segmentation.h:107
uint8_t always_0_0
Definition segmentation.h:144
uint16_t reserved_task_gate_2
Definition segmentation.h:190
uint16_t base_low
Definition segmentation.h:127
uint8_t cd
Definition segmentation.h:158
uint8_t reserved_task_gate_1
Definition segmentation.h:136
uint8_t base_hi
Definition segmentation.h:205
uint8_t db
Definition segmentation.h:202
uint8_t executable
Definition segmentation.h:160
uint8_t rw
Definition segmentation.h:156
uint8_t avl
Definition segmentation.h:197
uint8_t present
Definition segmentation.h:168
uint8_t reserved_or_param
Definition segmentation.h:141
uint16_t offset_hi
Definition segmentation.h:187
uint8_t type
Definition segmentation.h:174
uint8_t descriptor_type
Definition segmentation.h:165
uint8_t base_mid
Definition segmentation.h:133
uint8_t flags_l
Definition segmentation.h:200
uint8_t accessed
Definition segmentation.h:153
uint16_t offset_low
Definition segmentation.h:118
uint16_t limit_low
Definition segmentation.h:112
uint8_t use_other_union
Definition segmentation.h:180
uint16_t reserved_task_gate_0
Definition segmentation.h:115
uint8_t limit_hi
Definition segmentation.h:194
uint16_t segment_selector
Definition segmentation.h:124
uint8_t granularity
Definition segmentation.h:203
uint8_t dpl
Definition segmentation.h:167
Definition segmentation.h:54
uint16_t ss
Definition segmentation.h:81
uint16_t reserved_9
Definition segmentation.h:86
uint16_t cs
Definition segmentation.h:79
uint16_t reserved_12
Definition segmentation.h:92
uint32_t ebp
Definition segmentation.h:74
uint32_t esp2
Definition segmentation.h:63
uint16_t ss1
Definition segmentation.h:61
uint32_t esi
Definition segmentation.h:75
uint16_t reserved_10
Definition segmentation.h:88
uint32_t edi
Definition segmentation.h:76
uint16_t reserved_4
Definition segmentation.h:65
uint32_t edx
Definition segmentation.h:71
uint32_t ecx
Definition segmentation.h:70
uint32_t cr3
Definition segmentation.h:66
uint16_t iomap
Definition segmentation.h:93
uint16_t reserved_3
Definition segmentation.h:62
uint16_t backlink
Definition segmentation.h:55
uint16_t es
Definition segmentation.h:77
uint16_t ss0
Definition segmentation.h:58
uint32_t ebx
Definition segmentation.h:72
uint16_t fs
Definition segmentation.h:85
uint16_t reserved_2
Definition segmentation.h:59
uint32_t esp1
Definition segmentation.h:60
uint32_t eip
Definition segmentation.h:67
uint16_t reserved_8
Definition segmentation.h:84
uint32_t eflags
Definition segmentation.h:68
uint16_t ldt_ss
Definition segmentation.h:89
uint16_t ds
Definition segmentation.h:83
uint16_t gs
Definition segmentation.h:87
uint16_t ss2
Definition segmentation.h:64
uint32_t eax
Definition segmentation.h:69
uint16_t reserved_5
Definition segmentation.h:78
uint16_t reserved_1
Definition segmentation.h:56
uint16_t reserved_6
Definition segmentation.h:80
uint8_t t
Definition segmentation.h:91
uint16_t reserved_7
Definition segmentation.h:82
uint32_t esp0
Definition segmentation.h:57
uint16_t reserved_11
Definition segmentation.h:90
uint32_t esp
Definition segmentation.h:73