[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-newbie
Subject:    How does Linux not pagefault when jumping to the decompressed bzImage in x86_64?
From:       Harm Smits <harmsmitsdev () gmail ! com>
Date:       2022-03-16 14:10:04
Message-ID: CAO64rh6iYkLMfPnykJJ9VqVK2HUP+=9e9RVd1j5b7OpLAMEfiA () mail ! gmail ! com
[Download RAW message or body]

Hello!

For the past few weeks I have been trying to figure out how Linux
boots in its entirety as I found it rather interesting. However, I
have now come to a point where I am nothing short of confused.

As we can see in the linking script (vmlinux.lds.S), it is offset to a
certain address, namely __START_KERNEL. This define resolves to
__START_KERNEL_map + __PHYSICAL_START. So the entire 'kernel image' is
(from as far as my understanding goes) shifted by __START_KERNEL_map,
which holds a value of 0xffffffff80000000.

Now, when decompression has finished, it dereferences the first few
bytes of bzImage to get the address of `startup_64`, and it jumps to
the defined address and resumes execution while still in physical
address space. But how can they execute code that is compiled to be
run at a completely different address space, without causing page
faults? When I attempt to do the same, writing to the descriptor of
the temporary GDT causes it to have an access violation at address
0xffffffff8141d0a0
(https://github.com/torvalds/linux/blob/56e337f2cf1326323844927a04e9dbce9a244835/arch/x86/kernel/head64.c#L616)


Any help or resources on this would be greatly appreciated.

-- 
Kind regards,
Harm Smits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic