3 #include <stdio.h> // temporary
10 struct pool_head core_table;
13 struct block_pool core_block_pool;
14 #endif /* INDIRECT_CORE */
16 static void core_move(struct pool_item *item, int new_base) {
19 struct process *process;
20 struct process_calc calc;
21 int in_core_para, para_base;
22 #else /* INDIRECT_CORE */
24 #endif /* INDIRECT_CORE */
27 blocks = item->limit - base;
28 printf("core_move [%d,%d) to [%d,%d)\n", base, base + blocks, new_base, new_base + blocks);
29 assert(new_base <= base || new_base >= base + blocks);
34 base << BLOCK_PARAS_SHIFT,
35 new_base << BLOCK_PARAS_SHIFT,
36 blocks << BLOCK_PARAS_SHIFT
39 // figure out how much of item is valid
40 process = (struct process *)(
41 (char *)item - offsetof(struct process, core_item)
43 process_calc(process, &calc);
44 in_core_para = calc.in_core_block << BLOCK_PARAS_SHIFT;
45 if (in_core_para < process->para_base)
46 in_core_para = process->para_base;
47 else if (in_core_para > process->para_limit)
48 in_core_para = process->para_limit;
50 // copy valid part by abstract routine
51 para_base = (calc.core_origin << BLOCK_PARAS_SHIFT) + process->para_base;
54 para_base + ((new_base - base) << BLOCK_PARAS_SHIFT),
55 in_core_para - process->para_base
58 #else /* INDIRECT_CORE */
59 for (i = 0; i < blocks; ++i) {
60 core_table_mem[new_base + i] = core_table_mem[base + i];
61 core_table_mem[base + i] = 0x55555555;
63 #endif /* INDIRECT_CORE */
66 static void core_move_up(struct pool_item *item, int new_limit) {
69 struct process *process;
70 struct process_calc calc;
71 int in_core_para, para_limit;
72 #else /* INDIRECT_CORE */
74 #endif /* INDIRECT_CORE */
77 blocks = limit - item->base;
78 printf("core_move_up [%d,%d) to [%d,%d)\n", limit - blocks, limit, new_limit - blocks, new_limit);
79 assert(new_limit >= limit || new_limit <= limit - blocks);
84 limit << BLOCK_PARAS_SHIFT,
85 new_limit << BLOCK_PARAS_SHIFT,
86 blocks << BLOCK_PARAS_SHIFT
89 // figure out how much of item is valid
90 process = (struct process *)(
91 (char *)item - offsetof(struct process, core_item)
93 process_calc(process, &calc);
94 in_core_para = calc.in_core_block << BLOCK_PARAS_SHIFT;
95 if (in_core_para < process->para_base)
96 in_core_para = process->para_base;
97 else if (in_core_para > process->para_limit)
98 in_core_para = process->para_limit;
100 // copy valid part by abstract routine
101 para_limit = (calc.core_origin << BLOCK_PARAS_SHIFT) + in_core_para;
104 para_limit + ((new_limit - limit) << BLOCK_PARAS_SHIFT),
105 in_core_para - process->para_base
108 #else /* INDIRECT_CORE */
110 for (i = -1; i >= blocks; --i) {
111 core_table_mem[new_limit + i] = core_table_mem[limit + i];
112 core_table_mem[limit + i] = 0x55555555;
114 #endif /* INDIRECT_CORE */
117 #ifndef INDIRECT_CORE
118 void core_init(int n_blocks)
119 #else /* INDIRECT_CORE */
120 void core_init(int n_blocks, int table_size)
121 #endif /* INDIRECT_CORE */
126 #ifndef INDIRECT_CORE
128 #else /* INDIRECT_CORE */
130 #endif /* INDIRECT_CORE */
136 core_table_mem = malloc(table_size * sizeof(int));
137 rassert(core_table_mem);
138 memset(core_table_mem, 0x55, table_size * sizeof(int));
140 block_pool_init(&core_block_pool, n_blocks);
141 #endif /* INDIRECT_CORE */