1/**
2 * \file
3 * \brief
4 */
5
6/*
7 * Copyright (c) 2010, 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, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#ifndef OFFSETS_ARCH_H
16#define OFFSETS_ARCH_H
17
18#include <target/k1om/offsets_target.h>
19
20#define PADDR_SPACE_SIZE          K1OM_PADDR_SPACE_SIZE
21#define PADDR_SPACE_LIMIT         K1OM_PADDR_SPACE_LIMIT
22
23#define REAL_MODE_LINEAR_OFFSET   K1OM_REAL_MODE_LINEAR_OFFSET
24#define REAL_MODE_SEGMENT         K1OM_REAL_MODE_SEGMENT
25#define REAL_MODE_OFFSET          K1OM_REAL_MODE_OFFSET
26
27#define REAL_MODE_SEGMENT_TO_REAL_MODE_PAGE(seg)      K1OM_REAL_MODE_SEGMENT_TO_REAL_MODE_PAGE(seg)
28#define REAL_MODE_ADDR_TO_REAL_MODE_VECTOR(seg,off)   K1OM_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 < K1OM_PADDR_SPACE_LIMIT);
43    return (lvaddr_t)(addr + (lvaddr_t)K1OM_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 < K1OM_PADDR_SPACE_LIMIT;
54}
55/**
56 * Takes "physical memory address space" address and returns
57 * corresponding physical address.
58 *
59 * \param addr  Absolute physical address
60 *
61 * \return Corresponding "physical memory address space" address.
62 */
63static inline lpaddr_t mem_to_local_phys(lvaddr_t addr)
64{
65    assert(addr >= K1OM_MEMORY_OFFSET);
66    return (lpaddr_t)(addr - (lpaddr_t)K1OM_MEMORY_OFFSET);
67}
68
69static inline lpaddr_t gen_phys_to_local_phys(genpaddr_t addr)
70{
71    return (lpaddr_t)addr;
72}
73
74static inline genpaddr_t local_phys_to_gen_phys(lpaddr_t addr)
75{
76    return (genpaddr_t)addr;
77}
78
79/**
80 * Symbol: Start of kernel image. This symbol points to the start
81 * address of the kernel image.
82 */
83extern char _start_kernel;
84
85/**
86 * Symbol: End of kernel image. This symbol points to the end address
87 * of the kernel image.
88 */
89extern char _end_kernel;
90
91extern char _end_kernel_text;
92
93/**
94 * The size of the whole kernel image.
95 */
96#define SIZE_KERNEL_IMAGE       \
97    (size_t)(&_end_kernel - &_start_kernel)
98
99#endif // __ASSEMBLER__
100
101#endif // OFFSETS_ARCH_H
102