Segmentação e a tabela de descritores globais (GDT)
Aprenda como funciona a segmentação do x86 em conjunto com a paginação: seletores de segmento, descritores, a GDT e como os modelos de memória plana preparam o caminho para o modo protegido.
Segmentação e a tabela de descritores globais (GDT) é uma aula grátis de Assembly Language & x86 Low-Level Systems Programming no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Assembly Language & x86 Low-Level Systems Programming, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Assembly Language & x86 Low-Level Systems Programming inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
What Is Segmentation?
Segmentation divides memory into variable-sized regions called segments, each with a base address, limit, and access rights. It predates paging and is the first translation step in x86 address generation.
Real Mode Segments
In 16-bit real mode, a physical address is computed as segment * 16 + offset. This gave access to 1 MB using 16-bit registers but offered no protection at all.
Protected Mode Selectors
In protected mode a segment register no longer holds a base directly. It holds a selector — an index into a descriptor table plus a privilege level and table indicator bit.
The Segment Descriptor
Each descriptor is 8 bytes and encodes:
- Base (32-bit start address)
- Limit (size of the segment)
- Type (code, data, system)
- DPL (descriptor privilege level 0-3)
- Flags (granularity, default size)
The Global Descriptor Table
The GDT is an array of these descriptors in memory. The CPU finds it through the GDTR register, which holds the table base and limit. Entry 0 is always the null descriptor.
Loading the GDT
You point the CPU at your GDT with the lgdt instruction, which reads a 6-byte pseudo-descriptor (limit + base).
gdt_descriptor:
dw gdt_end - gdt_start - 1 ; limit
dd gdt_start ; base
lgdt [gdt_descriptor] ; load GDTRDefining a Flat Code Segment
Modern OSes use a flat model: base 0 and a 4 GB limit, so segmentation becomes a no-op and paging does the real work. Here is a typical code descriptor.
gdt_code:
dw 0xFFFF ; limit low
dw 0x0000 ; base low
db 0x00 ; base mid
db 10011010b ; present, ring 0, code, readable
db 11001111b ; granularity 4K, 32-bit, limit high
db 0x00 ; base highActivating Protected Mode
You enter protected mode by setting bit 0 (PE) of control register CR0, then performing a far jump to flush the prefetch queue and load CS with a protected-mode selector.
mov eax, cr0
or eax, 1 ; set PE bit
mov cr0, eax
jmp 0x08:pmode ; far jump, 0x08 = code selectorSelectors in Practice
A selector like 0x08 breaks down as: index 1 (byte offset 8 / 8), table indicator 0 (GDT), requested privilege level 0. After the jump, data segment registers are loaded with the data selector (often 0x10).
Segmentation vs Paging Today
In long (64-bit) mode segmentation is largely disabled: base and limit are ignored for most segments. Protection and translation are handled by paging. Segmentation survives mainly for FS/GS base pointers used for thread-local storage.
Why It Still Matters
Even though the flat model neutralizes segmentation, every protected-mode and long-mode OS must set up a valid GDT to boot. Understanding selectors and descriptors is essential for kernel bring-up and exception handling.
Quick Check
Test your segmentation knowledge.
Recap
You learned x86 segmentation:
- A selector indexes a descriptor in the GDT
- Descriptors hold base, limit, type, and privilege level
lgdtloads the table; setting CR0.PE plus a far jump enters protected mode- The flat model neutralizes segmentation so paging does the work
Aprenda Assembly com um tutor de IA — grátis
Escreva e execute código real no seu navegador, obtenha ajuda instantânea de um tutor de IA 24/7 e continue de onde parou na web ou no app.
- Cursos
- 12
- Aulas
- 48
Perguntas Frequentes
A aula “Segmentação e a tabela de descritores globais (GDT)” é grátis?
Sim — o texto completo de “Segmentação e a tabela de descritores globais (GDT)” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Assembly Language & x86 Low-Level Systems Programming, atualize para CoddyKit PRO. O curso de Assembly Language & x86 Low-Level Systems Programming inclui 4 aulas no total.
O que vou aprender em “Segmentação e a tabela de descritores globais (GDT)”?
Aprenda como funciona a segmentação do x86 em conjunto com a paginação: seletores de segmento, descritores, a GDT e como os modelos de memória plana preparam o caminho para o modo protegido. Você pratica Assembly Language & x86 Low-Level Systems Programming com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Assembly Language & x86 Low-Level Systems Programming?
Nenhuma experiência prévia é necessária. Assembly Language & x86 Low-Level Systems Programming no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “Segmentação e a tabela de descritores globais (GDT)”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Assembly Language & x86 Low-Level Systems Programming?
Sim. Cada aula de Assembly Language & x86 Low-Level Systems Programming inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Paginação e Unidade de Gerenciamento de Memória (MMU)
- Anéis de Proteção e Privilégios
- Hipervisores e Fundamentos da Virtualização
- Segmentação e a tabela de descritores globais (GDT)