FreeCalypso > hg > fc-selenite
annotate src/gpf/osl/os_sem_ir.c @ 64:66920678cfe3
components/etm: etm_at.c is not needed
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 20 Jul 2018 00:00:00 +0000 |
parents | 8b2a9a374324 |
children |
rev | line source |
---|---|
6
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This C module is a reconstruction based on the disassembly of |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * os_sem.obj in frame_na7_db_ir.lib from the Leonardo package. |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 /* set of included headers from COFF symtab: */ |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include "nucleus.h" |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "typedefs.h" |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "os.h" |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "gdi.h" |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "os_types.h" |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include "os_glob.h" |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern T_OS_SEM_TABLE_ENTRY SemTable[]; |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 extern unsigned os_time_to_tick_multiplier; |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 int |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 ReleaseSemaphoreCB(NU_SEMAPHORE *SemCB) |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 { |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (NU_Release_Semaphore(SemCB) == NU_SUCCESS) |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 return(OS_OK); |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 else |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 return(OS_ERROR); |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 } |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 GLOBAL LONG |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 os_ReleaseSemaphore(OS_HANDLE TaskHandle, OS_HANDLE SemHandle) |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 { |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (NU_Release_Semaphore(&SemTable[SemHandle].SemCB) == NU_SUCCESS) |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 return(OS_OK); |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 else |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 return(OS_ERROR); |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 int |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 ObtainSemaphoreCB(NU_SEMAPHORE *SemCB, ULONG Timeout, USHORT wait_check) |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 { |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 UNSIGNED nu_timeout; |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 STATUS sts; |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 int ret; |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 ret = OS_OK; |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (Timeout != OS_SUSPEND) |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 nu_timeout = TIME_TO_SYSTEM_TICKS(Timeout); |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 else if (wait_check == 1) |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 nu_timeout = 1; |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 else |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 nu_timeout = NU_SUSPEND; |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 for (;;) { |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 sts = NU_Obtain_Semaphore(SemCB, nu_timeout); |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 switch (sts) { |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 case NU_SUCCESS: |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 return(ret); |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 case NU_INVALID_SEMAPHORE: |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 return(OS_ERROR); |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 case NU_INVALID_SUSPEND: |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 nu_timeout = 0; |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 continue; |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 case NU_TIMEOUT: |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 case NU_UNAVAILABLE: |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 if (nu_timeout == 1 && wait_check == 1) { |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 nu_timeout = NU_SUSPEND; |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 ret = OS_WAITED; |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 continue; |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 } |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 return(OS_TIMEOUT); |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 default: |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 /* |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 * Disassembly reveals that the original code |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 * has an endless loop here, the equivalent |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 * of continue. My guess is that they simply |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 * forgot the default case, and so control |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 * falls onto the closing brace of the switch |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 * and then onto the closing brace of the for |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 * loop. But I prefer better error handling, |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 * hence the present addition. - Space Falcon |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 */ |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 return(OS_ERROR); |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 } |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 } |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 GLOBAL LONG |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 os_ObtainSemaphore(OS_HANDLE TaskHandle, OS_HANDLE SemHandle, ULONG Timeout) |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 { |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 if (SemHandle > MaxSemaphores) |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 return(OS_ERROR); |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 return ObtainSemaphoreCB(&SemTable[SemHandle].SemCB, Timeout, 0); |
8b2a9a374324
src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 } |