1 | #ifndef _SYSLINUX_MOVEBITS_H |
---|
2 | #define _SYSLINUX_MOVEBITS_H |
---|
3 | |
---|
4 | #include <inttypes.h> |
---|
5 | #include <stdio.h> |
---|
6 | #include <stdbool.h> |
---|
7 | |
---|
8 | typedef uint32_t addr_t; |
---|
9 | |
---|
10 | /* |
---|
11 | * A syslinux_movelist is a linked list of move operations. The ordering |
---|
12 | * is important, so no sorting requirement can be imposed. |
---|
13 | */ |
---|
14 | struct syslinux_movelist { |
---|
15 | addr_t dst; |
---|
16 | addr_t src; |
---|
17 | addr_t len; |
---|
18 | struct syslinux_movelist *next; |
---|
19 | }; |
---|
20 | |
---|
21 | /* |
---|
22 | * A syslinux_memmap is a sorted, linked list of memory regions, |
---|
23 | * guaranteed to satisfy the constraint that no adjacent zones have |
---|
24 | * the same type. Undefined memory ranges are represented with entries; |
---|
25 | * they have type SMT_UNDEFINED. |
---|
26 | * |
---|
27 | * Note that there is no length field. The length of a region is obtained |
---|
28 | * by looking at the start of the next entry in the chain. |
---|
29 | */ |
---|
30 | enum syslinux_memmap_types { |
---|
31 | SMT_ERROR = -2, /* Internal error token */ |
---|
32 | SMT_END = -1, /* End of list */ |
---|
33 | SMT_UNDEFINED = 0, /* Unknown range */ |
---|
34 | SMT_FREE = 1, /* Available memory */ |
---|
35 | SMT_RESERVED, /* Unusable memory */ |
---|
36 | SMT_ALLOC, /* Memory allocated by user */ |
---|
37 | SMT_ZERO, /* Memory that should be zeroed */ |
---|
38 | SMT_TERMINAL, /* Memory to be used as a last resort */ |
---|
39 | }; |
---|
40 | |
---|
41 | struct syslinux_memmap { |
---|
42 | addr_t start; |
---|
43 | enum syslinux_memmap_types type; |
---|
44 | struct syslinux_memmap *next; |
---|
45 | }; |
---|
46 | |
---|
47 | static inline bool valid_terminal_type(enum syslinux_memmap_types type) |
---|
48 | { |
---|
49 | return (type == SMT_FREE) || (type == SMT_TERMINAL); |
---|
50 | } |
---|
51 | |
---|
52 | /* |
---|
53 | * moves is computed from "fraglist" and "memmap". Areas that are |
---|
54 | * to be zeroed should be marked as such in the memmap, not in the |
---|
55 | * fraglist. |
---|
56 | */ |
---|
57 | |
---|
58 | int syslinux_compute_movelist(struct syslinux_movelist **movelist, |
---|
59 | struct syslinux_movelist *fraglist, |
---|
60 | struct syslinux_memmap *memmap); |
---|
61 | |
---|
62 | struct syslinux_memmap *syslinux_memory_map(void); |
---|
63 | void syslinux_free_movelist(struct syslinux_movelist *); |
---|
64 | int syslinux_add_movelist(struct syslinux_movelist **, |
---|
65 | addr_t dst, addr_t src, addr_t len); |
---|
66 | int syslinux_allocate_from_list(struct syslinux_movelist **freelist, |
---|
67 | addr_t dst, addr_t len); |
---|
68 | int syslinux_do_shuffle(struct syslinux_movelist *fraglist, |
---|
69 | struct syslinux_memmap *memmap, |
---|
70 | addr_t entry_point, addr_t entry_type, |
---|
71 | uint16_t bootflags); |
---|
72 | struct syslinux_memmap *syslinux_target_memmap(struct syslinux_movelist |
---|
73 | *fraglist, |
---|
74 | struct syslinux_memmap *memmap); |
---|
75 | |
---|
76 | /* Operatons on struct syslinux_memmap */ |
---|
77 | struct syslinux_memmap *syslinux_init_memmap(void); |
---|
78 | int syslinux_add_memmap(struct syslinux_memmap **list, |
---|
79 | addr_t start, addr_t len, |
---|
80 | enum syslinux_memmap_types type); |
---|
81 | enum syslinux_memmap_types syslinux_memmap_type(struct syslinux_memmap *list, |
---|
82 | addr_t start, addr_t len); |
---|
83 | int syslinux_memmap_largest(struct syslinux_memmap *list, |
---|
84 | enum syslinux_memmap_types type, |
---|
85 | addr_t * start, addr_t * len); |
---|
86 | int syslinux_memmap_highest(const struct syslinux_memmap *list, |
---|
87 | enum syslinux_memmap_types types, |
---|
88 | addr_t *start, addr_t len, |
---|
89 | addr_t ceiling, addr_t align); |
---|
90 | void syslinux_free_memmap(struct syslinux_memmap *list); |
---|
91 | struct syslinux_memmap *syslinux_dup_memmap(struct syslinux_memmap *list); |
---|
92 | int syslinux_memmap_find_type(struct syslinux_memmap *list, |
---|
93 | enum syslinux_memmap_types type, |
---|
94 | addr_t * start, addr_t * len, addr_t align); |
---|
95 | int syslinux_memmap_find(struct syslinux_memmap *mmap, |
---|
96 | addr_t *base, size_t size, |
---|
97 | bool relocate, size_t align, |
---|
98 | addr_t start_min, addr_t start_max, |
---|
99 | addr_t end_min, addr_t end_max); |
---|
100 | |
---|
101 | /* Debugging functions */ |
---|
102 | #ifdef DEBUG |
---|
103 | void syslinux_dump_movelist(struct syslinux_movelist *ml); |
---|
104 | void syslinux_dump_memmap(struct syslinux_memmap *memmap); |
---|
105 | #else |
---|
106 | #define syslinux_dump_movelist(x) ((void)0) |
---|
107 | #define syslinux_dump_memmap(x) ((void)0) |
---|
108 | #endif |
---|
109 | |
---|
110 | #endif /* _SYSLINUX_MOVEBITS_H */ |
---|