GDT Tutorial: Difference between revisions
[unchecked revision] | [unchecked revision] |
Content deleted Content added
Revolution (talk | contribs) m →Basics: Typo |
Revolution (talk | contribs) →Reload Segment Registers: add long mode reloading code |
||
Line 207:
=== Reload Segment Registers ===
Whatever you do with the GDT has no effect on the CPU until you load selectors into segment registers.
==== Protected Mode ====
<source lang="asm">
reloadSegments:
; Reload CS register containing code selector:
JMP 0x08:.reload_CS ; 0x08
.reload_CS:
; Reload data segment registers:
MOV AX, 0x10 ; 0x10
MOV DS, AX
MOV ES, AX
Line 225 ⟶ 227:
An explanation of the above code can be found [http://stackoverflow.com/questions/23978486/far-jump-in-gdt-in-bootloader here].
==== Long Mode ====
In '''[[Long Mode]]''' the process of changing '''CS''' is not simple as far jumps cannot be used. Using a far return is recommended instead:
<source lang = "asm">
reloadSegments:
; Reload CS register:
PUSH 0x08 ; Push code segment to stack, 0x08 is a stand-in for your code segment
LEA RAX, [rel .reload_CS] ; Load address of .reload_CS into RAX
PUSH RAX ; Push this value to the stack
RETFQ ; Perform a far return, RETFQ or LRETQ depending on syntax
.reload_CS:
; Reload data segment registers
MOV AX, 0x10 ; 0x10 is a stand-in for your data segment
MOV DS, AX
MOV ES, AX
MOV FS, AX
MOV GS, AX
MOV SS, AX
RET
</source>
== The LDT ==
|