Skip to content

Commit

Permalink
Add more explanations to some opaque x86 instructions (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhb authored and phil-opp committed Jul 15, 2018
1 parent bbca93c commit faa33be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/boot.s
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ _start:
mov fs, ax
mov gs, ax

# TODO explain
# clear the direction flag (e.g. go forward in memory when using
# instructions like lodsb)
cld


Expand All @@ -29,6 +30,7 @@ enable_a20:
out 0x92, al

enter_protected_mode:
# clear interrupts
cli
push ds
push es
Expand Down Expand Up @@ -118,6 +120,9 @@ println:
print:
cld
print_loop:
# note: if direction flag is set (via std)
# this will DECREMENT the ptr, effectively
# reading/printing in reverse.
lodsb al, BYTE PTR [esi]
test al, al
jz print_done
Expand Down
6 changes: 5 additions & 1 deletion src/second_stage.s
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ load_next_kernel_block_from_disk:
push ecx
push esi
mov ecx, 512 / 4
# move with zero extension
# because we are moving a word ptr
# to esi, a 32-bit register.
movzx esi, word ptr [dap_buffer_addr]
# move from esi to edi ecx times.
rep movsd [edi], [esi]
pop esi
pop ecx
Expand Down Expand Up @@ -256,7 +260,7 @@ gdt_64_pointer:

long_mode:
# call load_elf with kernel start address, size, and memory map as arguments
movabs rdi, 0x400000
movabs rdi, 0x400000 # move absolute 64-bit to register
mov rsi, _kib_kernel_size
lea rdx, _memory_map
movzx rcx, word ptr mmap_ent
Expand Down

0 comments on commit faa33be

Please sign in to comment.