FreeCalypso > hg > freecalypso-citrine
comparison gpf/osl/os_mem_ir.c @ 0:75a11d740a02
initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 09 Jun 2016 00:02:41 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:75a11d740a02 |
---|---|
1 /* | |
2 * This C module is a reconstruction based on the disassembly of | |
3 * os_mem.obj in frame_na7_db_ir.lib from the Leonardo package. | |
4 */ | |
5 | |
6 /* set of included headers from COFF symtab: */ | |
7 #include <stdio.h> | |
8 #include <string.h> | |
9 #include "gpfconf.h" /* FreeCalypso addition */ | |
10 #include "../../nucleus/nucleus.h" | |
11 #include "typedefs.h" | |
12 #include "os.h" | |
13 #include "gdi.h" | |
14 #include "os_types.h" | |
15 #include "os_glob.h" | |
16 | |
17 extern T_OS_PART_GRP_TABLE_ENTRY PartGrpTable[]; | |
18 extern T_OS_POOL_BORDER PoolBorder[]; | |
19 | |
20 GLOBAL LONG | |
21 os_is_valid_partition(T_VOID_STRUCT *Buffer) | |
22 { | |
23 int i; | |
24 | |
25 for (i = 0; i <= MaxPoolGroups; i++) { | |
26 if (PoolBorder[i].End == 0) | |
27 return(OS_ERROR); | |
28 if ((char *)Buffer < PoolBorder[i].Start) | |
29 continue; | |
30 if ((char *)Buffer >= PoolBorder[i].End) | |
31 continue; | |
32 return(OS_OK); | |
33 } | |
34 return(OS_ERROR); | |
35 } | |
36 | |
37 GLOBAL LONG | |
38 os_PartitionCheck(ULONG *ptr) | |
39 { | |
40 PM_HEADER *phdr; | |
41 PM_PCB *pool; | |
42 | |
43 phdr = (PM_HEADER *)(ptr - 2); | |
44 if (phdr->pm_next_available) | |
45 return(OS_PARTITION_FREE); | |
46 pool = phdr->pm_partition_pool; | |
47 if (ptr[(pool->pm_partition_size - 4) >> 2] == GUARD_PATTERN) | |
48 return(OS_OK); | |
49 else | |
50 return(OS_PARTITION_GUARD_PATTERN_DESTROYED); | |
51 } | |
52 | |
53 GLOBAL LONG | |
54 os_DeallocatePartition(OS_HANDLE TaskHandle, T_VOID_STRUCT *Buffer) | |
55 { | |
56 if (os_is_valid_partition(Buffer) != OS_OK) | |
57 return(OS_ERROR); | |
58 if (NU_Deallocate_Partition(Buffer) != NU_SUCCESS) | |
59 return(OS_ERROR); | |
60 return(OS_OK); | |
61 } | |
62 | |
63 GLOBAL LONG | |
64 os_AllocatePartition(OS_HANDLE TaskHandle, T_VOID_STRUCT **Buffer, ULONG Size, | |
65 ULONG Suspend, OS_HANDLE GroupHandle) | |
66 { | |
67 T_OS_PART_POOL *pool, *requested_pool; | |
68 ULONG nu_suspend; | |
69 STATUS sts; | |
70 int ret; | |
71 | |
72 for (pool = PartGrpTable[GroupHandle].grp_head; pool; | |
73 pool = pool->next) | |
74 if (Size <= pool->size) | |
75 break; | |
76 if (!pool) | |
77 return(OS_ERROR); | |
78 requested_pool = pool; | |
79 ret = OS_OK; | |
80 nu_suspend = NU_NO_SUSPEND; | |
81 try_alloc: | |
82 sts = NU_Allocate_Partition(&pool->pcb, (VOID **) Buffer, nu_suspend); | |
83 switch (sts) { | |
84 case NU_SUCCESS: | |
85 return(ret); | |
86 case NU_TIMEOUT: | |
87 case NU_INVALID_SUSPEND: | |
88 *Buffer = 0; | |
89 return(OS_TIMEOUT); | |
90 case NU_NO_PARTITION: | |
91 pool = pool->next; | |
92 if (pool) { | |
93 ret = OS_ALLOCATED_BIGGER; | |
94 goto try_alloc; | |
95 } | |
96 pool = requested_pool; | |
97 if (Suspend) { | |
98 nu_suspend = Suspend; | |
99 ret = OS_WAITED; | |
100 goto try_alloc; | |
101 } | |
102 return(OS_TIMEOUT); | |
103 default: | |
104 *Buffer = 0; | |
105 return(OS_ERROR); | |
106 } | |
107 } |