]> git.buserror.net Git - polintos/scott/priv.git/blob - kernel/include/arch-x64/addrs.h
minor doc updates
[polintos/scott/priv.git] / kernel / include / arch-x64 / addrs.h
1 #ifndef _ARCH_ADDRS_H
2 #define _ARCH_ADDRS_H
3
4 #define KERNEL_START  0xffffffff80000000
5 #define PHYSMEM_START 0xffff800000000000
6
7 #ifdef __cplusplus
8 #include <kern/types.h>
9
10 // GCC can't currently handle full 64-bit code relocations
11 // on x64, so the code is mapped separately from the
12 // all-of-RAM mapping.  This means that there are two different
13 // kernel-virtual addresses for some physical addresses.
14
15 namespace Arch {
16         static inline ulong kvirt_to_phys(void *addr)
17         {
18                 ulong ret = reinterpret_cast<ulong>(addr);
19         
20                 if (ret > KERNEL_START)
21                         return ret - KERNEL_START;
22                 else
23                         return ret - PHYSMEM_START;
24         }
25
26         static inline void *phys_to_kvirt(ulong addr)
27         {
28                 return reinterpret_cast<void *>(addr + PHYSMEM_START);
29         }
30         
31         namespace Priv {
32                 static const ulong max_ktext_map = 4 * 1024 * 1024;
33         
34                 static inline void *phys_to_ktext(ulong addr)
35                 {
36                         return reinterpret_cast<void *>(addr + KERNEL_START);
37                 }
38         }
39 };
40
41 #endif
42 #endif