From 5d643f8e9f384bf64236922509ed40e0f450fc1b Mon Sep 17 00:00:00 2001 From: Alexander Kuleshov Date: Fri, 4 May 2018 23:46:09 +0600 Subject: [PATCH] boot-1: clarify boot address Signed-off-by: Alexander Kuleshov --- Booting/linux-bootstrap-1.md | 4 +--- Booting/linux-bootstrap-3.md | 6 ++++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Booting/linux-bootstrap-1.md b/Booting/linux-bootstrap-1.md index 48e80d2..b05a76c 100644 --- a/Booting/linux-bootstrap-1.md +++ b/Booting/linux-bootstrap-1.md @@ -329,15 +329,13 @@ state.gs = state.fs = state.es = state.ds = state.ss = segment; state.cs = segment + 0x20; ``` -This means that segment registers will have the following values after kernel setup starts: +In my case, the kernel is loaded at `0x10000` address. This means that segment registers will have the following values after kernel setup starts: ``` gs = fs = es = ds = ss = 0x10000 cs = 0x10200 ``` -In my case, the kernel is loaded at `0x10000` address. - After the jump to `start_of_setup`, the kernel needs to do the following: * Make sure that all segment register values are equal diff --git a/Booting/linux-bootstrap-3.md b/Booting/linux-bootstrap-3.md index d19717c..8545137 100644 --- a/Booting/linux-bootstrap-3.md +++ b/Booting/linux-bootstrap-3.md @@ -509,7 +509,9 @@ It takes two parameters: Let's look inside `protected_mode_jump`. As I wrote above, you can find it in `arch/x86/boot/pmjump.S`. The first parameter will be in the `eax` register and the second one is in `edx`. -First of all, we put the address of `boot_params` in the `esi` register and the address of the code segment register `cs` (0x1000) in `bx`. After this, we shift `bx` by 4 bits and add it to the memory location labeled `2` (which is `bx << 4 + in_pm32`, the physical address to jump after transitioned to 32-bit mode) and jump to label `1`. Next we put the data segment and the task state segment in the `cx` and `di` registers with: +First of all, we put the address of `boot_params` in the `esi` register and the address of the code segment register `cs` in `bx`. After this, we shift `bx` by 4 bits and add it to the memory location labeled `2` (which is `(cs << 4) + in_pm32`, the physical address to jump after transitioned to 32-bit mode) and jump to label `1`. So after this `in_pm32` in label `2` will be overwritten with `(cs << 4) + in_pm32`. + +Next we put the data segment and the task state segment in the `cx` and `di` registers with: ```assembly movw $__BOOT_DS, %cx @@ -538,7 +540,7 @@ where: * `0x66` is the operand-size prefix which allows us to mix 16-bit and 32-bit code * `0xea` - is the jump opcode -* `in_pm32` is the segment offset +* `in_pm32` is the segment offset or `(cs << 4) + in_pm` * `__BOOT_CS` is the code segment we want to jump to. After this we are finally in protected mode: