Skip to contentSkip to conversation

i386 Ldt cleanups 2

PATCH In review Zachary Amsden 1 participant 1 message Nov 8, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 18/21 i386 Ldt cleanups 2

Add an acessor function to get a pointer to an LDT descriptor. Add one for the GDT too, while we are here, and a function to tell the difference.

Turns out on some GCC versions, converting to char * and back gives better code output than gdt[seg >> 3]. Lets keep that trick in the header file so the C-code can be clean.

Not used yet, but soon.

include/asm-i386/desc.h +18 -1
Index: linux-2.6.14-zach-work/include/asm-i386/desc.h
===================================================================
@@ -30,7 +30,24 @@ static inline struct desc_struct *get_cp
 {
 	return ((struct desc_struct *)cpu_gdt_descr[cpu].address);
 }
-  
+
+static inline int segment_from_ldt(unsigned int segment)
+{
+	return segment & LDT_SEGMENT;
+}
+
+static inline struct desc_struct *get_gdt_desc(int cpu, unsigned int segment)
+{
+	char *gdt = (char *)get_cpu_gdt_table(cpu);
+	return (struct desc_struct *)&gdt[segment & ~7];
+}
+
+static inline struct desc_struct *get_ldt_desc(mm_context_t *ctx, unsigned int segment)
+{
+	char *ldt = (char *)ctx->ldt;
+	return (struct desc_struct *)&ldt[segment & ~7];
+}
+
 #define load_TR_desc() __asm__ __volatile__("ltr %w0"::"q" (GDT_ENTRY_TSS*8))
 #define load_LDT_desc() __asm__ __volatile__("lldt %w0"::"q" (GDT_ENTRY_LDT*8))