forked from cirosantilli/x86-bare-metal-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
segmentation.S
64 lines (49 loc) · 1.46 KB
/
segmentation.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* https://github.com/cirosantilli/x86-bare-metal-examples#protected-mode-segmentation */
#include "common.h"
BEGIN
CLEAR
STAGE2
PROTECTED_MODE
/* Sanity check 1: just print the output. */
VGA_PRINT_STRING $output
/* Sanity check 2: make a mov without any segment manipulation. */
mov message, %cl
mov %cl, output
VGA_PRINT_STRING $output
/* Now for the real action. */
mov $gdt_data, %edx
/* We are touching the 7th byte of the data entry. */
add $3, %edx
mov (%edx), %al
/* Cache it for later. */
mov %al, %bl
/* Set the first bit of the descriptor memory. */
xor $1, %al
mov %al, (%edx)
/* We must re-set ds because the segment descriptor is cached
* and this updates it:
* http://wiki.osdev.org/Descriptor_Cache
*/
mov $DATA_SEG, %ax
mov %ax, %ds
/* This is the only memory access we will make with
* the modified segment, to minimize the effect on our IO.
*/
mov message, %cl
/* Restore the old segment. */
/* TODO is this needed to take into account the new segmentation? */
dec %edx
mov %bl, (%edx)
mov %ax, %ds
/* TODO this sanity check is not printing "ab".
* It fails, so we're not restoring the old state properly.
* Maybe blows up because video memory going wrong?
*/
VGA_PRINT_STRING $message
mov %cl, output
VGA_PRINT_STRING $output
hlt
message:
.asciz "ab"
output:
.asciz "x"