Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch-handbook/boot: add a space between the next word and the previous stop #320

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions documentation/content/en/books/arch-handbook/boot/_index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ The next block is responsible for the relocation and subsequent jump to the relo

[.programlisting]
....
movw %sp,%si # Source
movw %sp,%si # Source
movw $start,%di # Destination
movw $0x100,%cx # Word count
rep # Relocate
Expand All @@ -283,7 +283,8 @@ As [.filename]#boot0# is loaded by the BIOS to address `0x7C00`, it copies itsel
The source address, `0x7c00`, is copied to register `%si`.
The destination address, `0x600`, to register `%di`.
The number of words to copy, `256` (the program's size = 512 bytes), is copied to register `%cx`.
Next, the `rep` instruction repeats the instruction that follows, that is, `movsw`, the number of times dictated by the `%cx` register.The `movsw` instruction copies the word pointed to by `%si` to the address pointed to by `%di`.
Next, the `rep` instruction repeats the instruction that follows, that is, `movsw`, the number of times dictated by the `%cx` register.
The `movsw` instruction copies the word pointed to by `%si` to the address pointed to by `%di`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is

This is repeated another 255 times.
On each repetition, both the source and destination registers, `%si` and `%di`, are incremented by one.
Thus, upon completion of the 256-word (512-byte) copy, `%di` has the value `0x600`+`512`= `0x800`, and `%si` has the value `0x7c00`+`512`= `0x7e00`; we have thus completed the code _relocation_.
Expand All @@ -296,7 +297,8 @@ Now, `stosw` is executed 8 times.
This instruction copies a `0` value to the address pointed to by the destination register (`%di`, which is `0x800`), and increments it.
This is repeated another 7 times, so `%di` ends up with value `0x810`.
Effectively, this clears the address range `0x800`-`0x80f`.
This range is used as a (fake) partition table for writing the MBR back to disk.Finally, the sector field for the CHS addressing of this fake partition is given the value 1 and a jump is made to the main function from the relocated code.
This range is used as a (fake) partition table for writing the MBR back to disk.
Finally, the sector field for the CHS addressing of this fake partition is given the value 1 and a jump is made to the main function from the relocated code.
Note that until this jump to the relocated code, any reference to an absolute address was avoided.

The following code block tests whether the drive number provided by the BIOS should be used, or the one stored in [.filename]#boot0#.
Expand Down