aboutsummaryrefslogtreecommitdiff
path: root/memory.h
blob: f6ece42071c39ad693ba3c36d854d31540a2d5ce (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef MEMORY_H
#define MEMORY_H

#include <stddef.h>

// These macros were heavily used b4 I moved all the address
// computation to the linker script. Now I'm just keeping them
// in case they're needed for something else :)
#define POWER_OF_2(EXP) (((size_t) 1) << EXP)

#define ALIGN_POWER_OF_2(ADDR, EXP)				\
  (((ADDR - 1) & ~(POWER_OF_2(EXP) - 1)) + POWER_OF_2(EXP))

#define SECTION_SIZE POWER_OF_2(20)

#define ALIGN_SECTION(ADDR) ALIGN_POWER_OF_2(ADDR, 20)


// memory layout

#define INTERRUPT_VECTOR_TABLE_START ((uint32_t) 0x0)

// all those symbols are defined in the linker script
extern const char __end;
extern const char __start;
extern const char _translation_table_start;
extern const char _translation_table_end;
extern const char _stack_start;
extern const char _stack_top;
extern const char _unprivileged_memory_start;
extern const char _unprivileged_memory_end;

#define KERNEL_START ((size_t) &__start) // this is 0x0
#define KERNEL_END   ((size_t) &__end)

// first 2^14 aligned address after the kernel
#define TRANSLATION_TABLE_BASE ((size_t) &_translation_table_start)
#define TRANSLATION_TABLE_END  ((size_t) &_translation_table_end)

// first section after the translation table is left unused;
// the next section is used as the stack
#define STACK_START ((size_t) &_stack_start)
#define STACK_END   ((size_t) &_stack_top)

#define PRIVILEGED_MEMORY_END STACK_END

#define UNPRIVILEGED_MEMORY_START				\
  ((size_t) &_unprivileged_memory_start)  // equal to STACK_END
#define UNPRIVILEGED_MEMORY_END			\
  ((size_t) &_unprivileged_memory_end)

#define PL0_SECTION_NUMBER ((size_t) 0xaaa)

#define VIRTUAL_PL0_MEMORY_START (PL0_SECTION_NUMBER << 20)
#define VIRTUAL_PL0_MEMORY_END			\
  (VIRTUAL_PL0_MEMORY_START + SECTION_SIZE)

#endif // MEMORY_H