1 // Post memory manager (PMM) calls
3 // Copyright (C) 2009-2013 Kevin O'Connor <kevin@koconnor.net>
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
7 #include "biosvar.h" // FUNC16
8 #include "config.h" // CONFIG_*
9 #include "malloc.h" // _malloc
10 #include "output.h" // dprintf
11 #include "std/pmm.h" // PMM_SIGNATURE
12 #include "string.h" // checksum
13 #include "util.h" // pmm_init
14 #include "x86.h" // __ffs
16 extern struct pmmheader PMMHEADER;
19 struct pmmheader PMMHEADER __aligned(16) VARFSEG = {
20 .signature = PMM_SIGNATURE,
22 .length = sizeof(PMMHEADER),
28 handle_pmm00(u16 *args)
30 u32 length = *(u32*)&args[1], handle = *(u32*)&args[3];
32 dprintf(3, "pmm00: length=%x handle=%x flags=%x\n"
33 , length, handle, flags);
34 struct zone_s *lowzone = &ZoneTmpLow, *highzone = &ZoneTmpHigh;
36 // Permanent memory request.
41 // Memory size request
47 return malloc_getspace(lowzone);
49 return malloc_getspace(highzone);
51 u32 spacelow = malloc_getspace(lowzone);
52 u32 spacehigh = malloc_getspace(highzone);
53 if (spacelow > spacehigh)
59 u32 size = length * 16;
62 u32 align = MALLOC_MIN_ALIGN;
64 align = 1<<__ffs(size);
65 if (align < MALLOC_MIN_ALIGN)
66 align = MALLOC_MIN_ALIGN;
74 data = malloc_palloc(lowzone, size, align);
77 data = malloc_palloc(highzone, size, align);
80 data = malloc_palloc(lowzone, size, align);
82 data = malloc_palloc(highzone, size, align);
85 if (data && handle != MALLOC_DEFAULT_HANDLE)
86 malloc_sethandle(data, handle);
92 handle_pmm01(u16 *args)
94 u32 handle = *(u32*)&args[1];
95 dprintf(3, "pmm01: handle=%x\n", handle);
96 if (handle == MALLOC_DEFAULT_HANDLE)
98 return malloc_findhandle(handle);
103 handle_pmm02(u16 *args)
105 u32 buffer = *(u32*)&args[1];
106 dprintf(3, "pmm02: buffer=%x\n", buffer);
107 int ret = malloc_pfree(buffer);
115 handle_pmmXX(u16 *args)
117 return PMM_FUNCTION_NOT_SUPPORTED;
121 handle_pmm(u16 *args)
125 return PMM_FUNCTION_NOT_SUPPORTED;
128 dprintf(DEBUG_HDL_pmm, "pmm call arg1=%x\n", arg1);
132 case 0x00: ret = handle_pmm00(args); break;
133 case 0x01: ret = handle_pmm01(args); break;
134 case 0x02: ret = handle_pmm02(args); break;
135 default: ret = handle_pmmXX(args); break;
147 dprintf(3, "init PMM\n");
149 PMMHEADER.entry = FUNC16(entry_pmm);
150 PMMHEADER.checksum -= checksum(&PMMHEADER, sizeof(PMMHEADER));
159 dprintf(3, "finalize PMM\n");
161 PMMHEADER.signature = 0;
162 PMMHEADER.entry.segoff = 0;