8000 Add more explanations to some opaque x86 instructions (#19) · rust-osdev/bootloader@faa33be · GitHub
[go: up one dir, main page]

Skip to content

Commit faa33be

Browse files
anirudhbphil-opp
authored andcommitted
Add more explanations to some opaque x86 instructions (#19)
1 parent bbca93c commit faa33be

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/boot.s

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ _start:
1212
mov fs, ax
1313
mov gs, ax
1414

15-
# TODO explain
15+
# clear the direction flag (e.g. go forward in memory when using
16+
# instructions like lodsb)
1617
cld
1718

1819

@@ -29,6 +30,7 @@ enable_a20:
2930
out 0x92, al
3031

3132
enter_protected_mode:
33+
# clear interrupts
3234
cli
3335
push ds
3436
push es
@@ -118,6 +120,9 @@ println:
118120
print:
119121
cld
120122
print_loop:
123+
# note: if direction flag is set (via std)
124+
# this will DECREMENT the ptr, effectively
125+
# reading/printing in reverse.
121126
lodsb al, BYTE PTR [esi]
122127
test al, al
123128
jz print_done

src/second_stage.s

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ load_next_kernel_block_from_disk:
5656
push ecx
5757
push esi
5858
mov ecx, 512 / 4
59+
# move with zero extension
60+
# because we are moving a word ptr
61+
# to esi, a 32-bit register.
5962
movzx esi, word ptr [dap_buffer_addr]
63+
# move from esi to edi ecx times.
6064
rep movsd [edi], [esi]
6165
pop esi
6266
pop ecx
@@ -256,7 +260,7 @@ gdt_64_pointer:
256260

257261
long_mode:
258262
# call load_elf with kernel start address, size, and memory map as arguments
259-
movabs rdi, 0x400000
263+
movabs rdi, 0x400000 # move absolute 64-bit to register
260264
mov rsi, _kib_kernel_size
261265
lea rdx, _memory_map
262266
movzx rcx, word ptr mmap_ent

0 commit comments

Comments
 (0)
0