1 // Internal dynamic memory allocations.
2 //
3 // Copyright (C) 2009-2013 Kevin O'Connor <kevin@koconnor.net>
4 //
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
6
7 #include "biosvar.h" // GET_BDA
8 #include "config.h" // BUILD_BIOS_ADDR
9 #include "e820map.h" // struct e820entry
10 #include "list.h" // hlist_node
11 #include "malloc.h" // _malloc
12 #include "memmap.h" // PAGE_SIZE
13 #include "output.h" // dprintf
14 #include "stacks.h" // wait_preempt
15 #include "std/optionrom.h" // OPTION_ROM_ALIGN
16 #include "string.h" // memset
17
18 static unsigned long stackptr;
19
20 /****************************************************************
21 * tracked memory allocations
22 ****************************************************************/
23
24 // Allocate physical memory from the given zone and track it as a PMM allocation
25 unsigned long
malloc_palloc(struct zone_s * zone,u32 size,u32 align)26 malloc_palloc(struct zone_s *zone, u32 size, u32 align)
27 {
28 unsigned long data;
29
30 ASSERT32FLAT();
31 if (!size)
32 return 0;
33
34 stackptr = (stackptr + align-1) & ~(align-1);
35 data = stackptr;
36 stackptr += size;
37
38 dprintf(8, "size=%d align=%d ret=0x%lx\n" , size, align, data);
39
40 return data;
41 }
42
43 // Allocate virtual memory from the given zone
44 void * __malloc
parisc_malloc(u32 size,u32 align)45 parisc_malloc(u32 size, u32 align)
46 {
47 return (void*) malloc_palloc(NULL, size, align);
48 }
49
50 // Free a data block allocated with phys_alloc
51 int
malloc_pfree(u32 data)52 malloc_pfree(u32 data)
53 {
54 return 0;
55 }
56
57 void
free(void * data)58 free(void *data)
59 {
60 }
61
62
63
64 /****************************************************************
65 * Setup
66 ****************************************************************/
67
68 void
malloc_preinit(void)69 malloc_preinit(void)
70 {
71 ASSERT32FLAT();
72 dprintf(3, "malloc preinit\n");
73 extern u8 _ebss;
74 stackptr = (unsigned long) &_ebss;
75 }
76
77 u32 LegacyRamSize VARFSEG;
78
79 void
malloc_init(void)80 malloc_init(void)
81 {
82 ASSERT32FLAT();
83 dprintf(3, "malloc init\n");
84 }
85
86 void
malloc_prepboot(void)87 malloc_prepboot(void)
88 {
89 ASSERT32FLAT();
90 dprintf(3, "malloc finalize\n");
91 }
92