annotate src/gpf2/osl/os_mem_ir.c @ 487:91e8dac34ada

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