Skip to content

Commit

Permalink
Use mul instead of imul
Browse files Browse the repository at this point in the history
See #21
  • Loading branch information
phil-opp committed Oct 31, 2015
1 parent 44a8f72 commit 7cfa96b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions _posts/2015-08-25-entering-longmode.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ setup_page_tables:
.map_p2_table:
; map ecx-th P2 entry to a huge page that starts at address 2MiB*ecx
mov eax, 0x200000 ; 2MiB
imul eax, ecx ; start address of ecx-th page
mul ecx ; start address of ecx-th page
or eax, 0b10000011 ; present + writable + huge
mov [p2_table + ecx * 8], eax ; map ecx-th entry
Expand All @@ -281,7 +281,7 @@ setup_page_tables:
```
Maybe I first explain how an assembly loop works. We use the `ecx` register as a counter variable, just like `i` in a for loop. After mapping the `ecx-th` entry, we increase `ecx` by one and jump to `.map_p2_table` again if it's still smaller 512.

To map a P2 entry we first calculate the start address of its page in `eax`: The `ecx-th` entry needs to be mapped to `ecx * 2MiB`. Then we set the `present`, `writable`, and `huge page` bits and write it to the P2 entry. The address of the `ecx-th` entry in P2 is `p2_table + ecx * 8`, because each entry is 8 bytes large.
To map a P2 entry we first calculate the start address of its page in `eax`: The `ecx-th` entry needs to be mapped to `ecx * 2MiB`. We use the `mul` operation for that, which multiplies `eax` with the given register and stores the result in `eax`. Then we set the `present`, `writable`, and `huge page` bits and write it to the P2 entry. The address of the `ecx-th` entry in P2 is `p2_table + ecx * 8`, because each entry is 8 bytes large.

Now the first gigabyte of our kernel is identity mapped and thus accessible through the same physical and virtual addresses.

Expand Down

0 comments on commit 7cfa96b

Please sign in to comment.