1/**
2 * \file
3 * \brief
4 */
5
6/*
7 * Copyright (c) 2010, 2016, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#ifndef OFFSETS_ARCH_H
16#define OFFSETS_ARCH_H
17
18#include <target/x86_64/offsets_target.h>
19
20#define PADDR_SPACE_SIZE          X86_64_PADDR_SPACE_SIZE
21#define PADDR_SPACE_LIMIT         X86_64_PADDR_SPACE_LIMIT
22
23#define REAL_MODE_LINEAR_OFFSET   X86_64_REAL_MODE_LINEAR_OFFSET
24#define REAL_MODE_SEGMENT         X86_64_REAL_MODE_SEGMENT
25#define REAL_MODE_OFFSET          X86_64_REAL_MODE_OFFSET
26
27#define REAL_MODE_SEGMENT_TO_REAL_MODE_PAGE(seg)      X86_64_REAL_MODE_SEGMENT_TO_REAL_MODE_PAGE(seg)
28#define REAL_MODE_ADDR_TO_REAL_MODE_VECTOR(seg,off)   X86_64_REAL_MODE_ADDR_TO_REAL_MODE_VECTOR(seg,off)
29
30#ifndef __ASSEMBLER__
31
32/**
33 * Takes absolute physical address addr and returns corresponding
34 * "physical memory address space" address.
35 *
36 * \param addr  Absolute physical address
37 *
38 * \return Corresponding "physical memory address space" address.
39 */
40static inline lvaddr_t local_phys_to_mem(lpaddr_t addr)
41{
42    assert(addr < X86_64_PADDR_SPACE_LIMIT);
43    return (lvaddr_t)(addr + (lvaddr_t)X86_64_MEMORY_OFFSET);
44}
45
46/**
47 * Checks whether absolute local physical address `addr` is valid.
48 * \param addr Absolute local physical address
49 * \return True iff addr is a valid local physical address
50 */
51static inline bool local_phys_is_valid(lpaddr_t addr)
52{
53    return addr < X86_64_PADDR_SPACE_LIMIT;
54}
55
56/**
57 * Takes "physical memory address space" address and returns
58 * corresponding physical address.
59 *
60 * \param addr  Absolute physical address
61 *
62 * \return Corresponding "physical memory address space" address.
63 */
64static inline lpaddr_t mem_to_local_phys(lvaddr_t addr)
65{
66    assert(addr >= X86_64_MEMORY_OFFSET);
67    return (lpaddr_t)(addr - (lpaddr_t)X86_64_MEMORY_OFFSET);
68}
69
70static inline lpaddr_t gen_phys_to_local_phys(genpaddr_t addr)
71{
72    return (lpaddr_t)addr;
73}
74
75static inline genpaddr_t local_phys_to_gen_phys(lpaddr_t addr)
76{
77    return (genpaddr_t)addr;
78}
79
80/**
81 * Symbol: Start of kernel image. This symbol points to the start
82 * address of the kernel image.
83 */
84extern char _start_kernel;
85
86/**
87 * Symbol: End of kernel image. This symbol points to the end address
88 * of the kernel image.
89 */
90extern char _end_kernel;
91
92/**
93 * The size of the whole kernel image.
94 */
95#define SIZE_KERNEL_IMAGE       \
96    (size_t)(&_end_kernel - &_start_kernel)
97
98#endif // __ASSEMBLER__
99
100#endif // OFFSETS_ARCH_H
101