This code in MINIX 3 copies boot monitor's (bootstrap) GDT to the Kernel space and switches over it. But I'm having a hard time understanding the code. In the code, _gdt
is the address of an array of descriptor tables declared in C (gdt[GDT_SIZE]
).
The structure gdt is as follows:
struct segdesc_s { /* segment descriptor for protected mode */
u16_t limit_low;
u16_t base_low;
u8_t base_middle;
u8_t access; /* |P|DL|1|X|E|R|A| */
u8_t granularity; /* |G|X|0|A|LIMT| */
u8_t base_high;
};
The size of the structure is 8 bytes. The macro GDT_SELECTOR
has the value 8
.
! Copy the monitor global descriptor table to the address space of kernel and
! switch over to it. Prot_init() can then update it with immediate effect.
sgdt (_gdt+GDT_SELECTOR) ! get the monitor gdtr
mov esi, (_gdt+GDT_SELECTOR+2) ! absolute address of GDT
mov ebx, _gdt ! address of kernel GDT
mov ecx, 8*8 ! copying eight descriptors
copygdt:
eseg movb al, (esi)
movb (ebx), al
inc esi
inc ebx
loop copygdt
The most confusing line is movb (ebx), al
. Please help.