Assembly Language & x86 Low-Level Systems Programming · درس

التقسيم وجدول الواصفات العام (GDT)

تعلّم كيفية عمل تقسيم x86 إلى جانب الترحيل، بما يشمل محددات المقاطع والواصفات وGDT، وكيف تهيئ نماذج الذاكرة المسطحة الوضع المحمي.

الدرس 4 من 413 خطوة

التقسيم وجدول الواصفات العام (GDT) درس مجاني في Assembly Language & x86 Low-Level Systems Programming على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Assembly Language & x86 Low-Level Systems Programming، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Assembly Language & x86 Low-Level Systems Programming 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

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 GDTR

Defining 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 high

Activating 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 selector

Selectors 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
  • lgdt loads the table; setting CR0.PE plus a far jump enters protected mode
  • The flat model neutralizes segmentation so paging does the work
البدء مجانًا

تعلم Assembly مع معلم ذكاء اصطناعي — مجانًا

اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.

الدورات
12
الدروس
48

الأسئلة الشائعة

هل درس «التقسيم وجدول الواصفات العام (GDT)» مجاني؟

نعم — نص درس «التقسيم وجدول الواصفات العام (GDT)» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Assembly Language & x86 Low-Level Systems Programming، انتقل إلى CoddyKit PRO. تتضمن دورة Assembly Language & x86 Low-Level Systems Programming 4 دروس في المجموع.

ماذا ستتعلم في «التقسيم وجدول الواصفات العام (GDT)»؟

تعلّم كيفية عمل تقسيم x86 إلى جانب الترحيل، بما يشمل محددات المقاطع والواصفات وGDT، وكيف تهيئ نماذج الذاكرة المسطحة الوضع المحمي. تتمرن على Assembly Language & x86 Low-Level Systems Programming مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Assembly Language & x86 Low-Level Systems Programming؟

لا تُشترط خبرة سابقة. Assembly Language & x86 Low-Level Systems Programming على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «التقسيم وجدول الواصفات العام (GDT)»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Assembly Language & x86 Low-Level Systems Programming هذا؟

نعم. كل درس في Assembly Language & x86 Low-Level Systems Programming يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. الت分页 ووحدة إدارة الذاكرة (MMU)
  2. حلقات الحماية والامتيازات
  3. أساسيات برامج مراقبة الأجهزة والافتراضية
  4. التقسيم وجدول الواصفات العام (GDT)
← العودة إلى Assembly Language & x86 Low-Level Systems Programming