Questions tagged [gdt]

The Global Descriptor Table or GDT is a data structure used by Intel x86-family processors

Starting with the 80286 in order to define the characteristics of the various memory areas used during program execution, including the base address, the size and access privileges like executability and writability. These memory areas are called segments in Intel terminology.

The GDT can hold things other than segment descriptors as well. Every 8-byte entry in the GDT is a descriptor, but these can be Task State Segment (or TSS) descriptors, Local Descriptor Table (LDT) descriptors, or Call Gate descriptors. The last one, Call Gates, are particularly important for transferring control between x86 privilege levels although this mechanism is not used on most modern operating systems.

Loading a selector into a segment register automatically reads the GDT or the LDT and stores the properties of the segment inside the processor itself. Subsequent modifications to the GDT or LDT will not be effective unless the segment register is reloaded.

enter image description here

GDT in 64-bit

The GDT is still present in 64-bit mode; a GDT must be defined, but is generally never changed or used for segmentation. The size of the register has been extended from 48 to 80 bits, and 64-bit selectors are always "flat"

102 questions
3
votes
2 answers

What role does A20 line plays in Protected mode?

I am going through the protected mode part of x86. I just learnt about GDT. Before, I have studied that to get into Protected mode( ie : Using all 32bit address line) A20 gate must be enabled. So, the code to enable A20 must be in 16bit right? …
Panther Coder
  • 1,058
  • 1
  • 16
  • 43
3
votes
0 answers

Why x86 processor need a NULL descriptor in GDT?

I am writing my own OS on i386, then it comes to Global Descriptor Table setting, I am puzzling at NULL descriptor. In INTEL 80386 PROGRAMMER'S REFERENCE MANUAL 1986 , NULL_DES DESC <> ; NULL descriptor is the only mention about NULL…
3
votes
0 answers

Global Descriptor Table and Local Descriptor Table relationship?

Protected-Mode Memory Management I was going through segmentationof this link. Both LDT are GDT are independent or dependent on each other ? (TI bit (which is part of the selector) to decide which descriptor table should be used (the GDT or the…
sourav punoriyar
  • 830
  • 8
  • 18
3
votes
0 answers

Why do ES and DS zero out eventually on 64 bit kernel when set to TLS selectors?

The 32-bit program below calls set_thread_area(2) to create an entry in GDT, which is meant to be used for TLS. Typically the resulting selector is put into FS or GS and successfully used. But if it is put into DS or ES, running on a 64-bit kernel,…
Ruslan
  • 18,162
  • 8
  • 67
  • 136
2
votes
1 answer

Changing segments to Ring3(user) from Ring0(kernel) results in segmentation fault

I am writing a toy operating system. I am trying to implement memory protection for an operating system. All I want to do is create protection for the kernel from user space programs. I want to do this purely with segmentation and not paging. Here…
2
votes
0 answers

implementing GDT in C

I am learning to write an OS, and was trying to update GDT in kernel code, therefore i defined some structs in C typedef unsigned int u32; typedef int s32; typedef unsigned short u16; typedef short s16; typedef unsigned char …
hfie A
  • 21
  • 2
2
votes
1 answer

Is there a convention for how Global Descriptor Table entries should be laid out?

Is there an agreed upon convention for operating systems specifying what each table index should describe? For example, on Windows systems (as described here), entry 4 describes 32 bit usermode code (RPL = 3), and entry 6 describes 64 bit usermode…
Omar Darwish
  • 1,536
  • 2
  • 15
  • 23
2
votes
1 answer

GDT segment reload failed

I'm writing a little kernel in c for x86 platform, but I'm having trouble to load the gdt and reload the segment selectors. I am using bochs to test my kernel. The issue is, when I load the GDT but don't reload the segment selectors, I can stop my…
Fymyte
  • 31
  • 4
2
votes
1 answer

Why in xv6 there's sizeof(gdt)-1 in gdtdesc

In bootasm.S .p2align 2 # force 4 byte alignment gdt: SEG_NULLASM # null seg SEG_ASM(STA_X|STA_R, 0x0, 0xffffffff) # code seg SEG_ASM(STA_W, 0x0, 0xffffffff) # data…
rapiz
  • 117
  • 11
2
votes
1 answer

Implementing User Mode and Kernel Mode Switching in 64 bit UEFI OS

I am writing a 64 Bit UEFI OS ( GNU-EFI - Bootloader ). I am wondered about User Mode and Kernel Mode in OS, I have to Implement User Mode and Kernel Mode in My OS, I found some on the Internet but It won't works for me ( I thinks it is because of…
2
votes
0 answers

Rust gnu-asm, far jump in real mode

.intel_syntax noprefix smp_trampoline: # clear the direction flag (e.g. go forward in memory when using # instructions like lodsb) cld # disable interrupts cli # zero data segment xor ax, ax mov ds, ax # Set the…
Qubasa
  • 183
  • 8
2
votes
1 answer

What is the modern usage of the global descriptor table(GTD)?

After a long read, I am really confused. From what I read: Modern OS does not use segments at all. The GDT is used to define a segment in the memory (including constraints). The page table has a supervisor bit that indicates if the current…
Moshe Levy
  • 174
  • 9
2
votes
0 answers

Boot sector stuck in "Booting from hard disk" loop in Qemu after switching to 32bit protected mode

Running my code with qemu, right after calling switch_to_32_pm, Qemu starts going crazy and constantly clearing the screen & displaying 'Booting from hard disk'. (I must add that I can't run with -curses for some reason (-curses: curses or iconv…
2
votes
0 answers

Why loading GDT in the following way works

I'm writing my own kernel and used this code to override global descriptor table set by bootloader. This is done in 32 bit protected mode. flush_gdt: lgdt [gdtr] jmp 0x08:complete_flush complete_flush: mov ax, 0x10 mov ds, ax …
jason
  • 45
  • 1
  • 7
2
votes
1 answer

What does the "D" stand for in 386's "D bit"?

In the article on the GDT the OSDev wiki describes the flag that is used as D bit for CS descriptors as follows: Sz: Size bit. If 0 the selector defines 16 bit protected mode. If 1 it defines 32 bit protected mode. You can have both 16 bit and 32…
ecm
  • 2,583
  • 4
  • 21
  • 29