6 #include <syslinux/memscan.h>
9 struct free_arena_header __core_malloc_head
[NHEAP
];
11 //static __hugebss char main_heap[128 << 10];
12 extern char __lowmem_heap
[];
13 extern char free_high_memory
[];
15 #define E820_MEM_MAX 0xfff00000 /* 4 GB - 1 MB */
16 int scan_highmem_area(void *data
, addr_t start
, addr_t len
,
17 enum syslinux_memmap_types type
)
19 struct free_arena_header
*fp
;
23 dprintf("start = %x, len = %x, type = %d", start
, len
, type
);
25 if (start
< 0x100000 || start
> E820_MEM_MAX
29 if (start
< __com32
.cs_memsize
) {
30 len
-= __com32
.cs_memsize
- start
;
31 start
= __com32
.cs_memsize
;
33 if (len
> E820_MEM_MAX
- start
)
34 len
= E820_MEM_MAX
- start
;
36 if (len
>= 2 * sizeof(struct arena_header
)) {
37 fp
= (struct free_arena_header
*)start
;
38 fp
->a
.attrs
= ARENA_TYPE_USED
| (HEAP_MAIN
<< ARENA_HEAP_POS
);
40 fp
->a
.magic
= ARENA_MAGIC
;
42 ARENA_SIZE_SET(fp
->a
.attrs
, len
);
43 dprintf("will inject a block start:0x%x size 0x%x", start
, len
);
44 __inject_free_block(fp
);
47 __com32
.cs_memsize
= start
+ len
; /* update the HighMemSize */
52 static void mpool_dump(enum heap heap
)
54 struct free_arena_header
*head
= &__core_malloc_head
[heap
];
55 struct free_arena_header
*fp
;
56 int size
, type
, i
= 0;
61 size
= ARENA_SIZE_GET(fp
->a
.attrs
);
62 type
= ARENA_TYPE_GET(fp
->a
.attrs
);
65 printf("area[%d]: start = 0x%08x, end = 0x%08x, type = %d\n",
66 i
++, start
, end
, type
);
72 uint16_t *bios_free_mem
;
75 struct free_arena_header
*fp
;
80 /* Initialize the head nodes */
81 fp
= &__core_malloc_head
[0];
82 for (i
= 0 ; i
< NHEAP
; i
++) {
83 fp
->a
.next
= fp
->a
.prev
= fp
->next_free
= fp
->prev_free
= fp
;
84 fp
->a
.attrs
= ARENA_TYPE_HEAD
| (i
<< ARENA_HEAP_POS
);
85 fp
->a
.tag
= MALLOC_HEAD
;
89 //dprintf("__lowmem_heap = 0x%p bios_free = 0x%p",
90 // __lowmem_heap, *bios_free_mem);
92 /* Initialize the lowmem heap */
93 fp
= (struct free_arena_header
*)__lowmem_heap
;
94 fp
->a
.attrs
= ARENA_TYPE_USED
| (HEAP_LOWMEM
<< ARENA_HEAP_POS
);
95 ARENA_SIZE_SET(fp
->a
.attrs
, (*bios_free_mem
<< 10) - (uintptr_t)fp
);
97 fp
->a
.magic
= ARENA_MAGIC
;
99 __inject_free_block(fp
);
101 /* Initialize the main heap */
102 __com32
.cs_memsize
= (size_t)free_high_memory
;
103 syslinux_scan_memory(scan_highmem_area
, NULL
);