annotate gsm-fw/gpf/osl/os_sem_ir.c @ 974:3f67d5bf96ef

doc: TFC139-breakin written, Compal-unlock updated
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Sun, 15 Nov 2015 03:47:19 +0000
parents d2b93cfe8e4c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
450
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This C module is a reconstruction based on the disassembly of
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * os_sem.obj in frame_na7_db_ir.lib from the Leonardo package.
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 */
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 /* set of included headers from COFF symtab: */
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdio.h>
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <string.h>
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include "gpfconf.h" /* FreeCalypso addition */
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include "../../nucleus/nucleus.h"
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "typedefs.h"
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "os.h"
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "gdi.h"
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 #include "os_types.h"
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 #include "os_glob.h"
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 extern T_OS_SEM_TABLE_ENTRY SemTable[];
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 extern unsigned os_time_to_tick_multiplier;
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 int
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 ReleaseSemaphoreCB(NU_SEMAPHORE *SemCB)
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 {
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 if (NU_Release_Semaphore(SemCB) == NU_SUCCESS)
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 return(OS_OK);
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 else
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 return(OS_ERROR);
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 }
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28
451
578ba9dfc369 os_sem_ir.c: os_ReleaseSemaphore() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 450
diff changeset
29 GLOBAL LONG
578ba9dfc369 os_sem_ir.c: os_ReleaseSemaphore() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 450
diff changeset
30 os_ReleaseSemaphore(OS_HANDLE TaskHandle, OS_HANDLE SemHandle)
578ba9dfc369 os_sem_ir.c: os_ReleaseSemaphore() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 450
diff changeset
31 {
578ba9dfc369 os_sem_ir.c: os_ReleaseSemaphore() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 450
diff changeset
32 if (NU_Release_Semaphore(&SemTable[SemHandle].SemCB) == NU_SUCCESS)
578ba9dfc369 os_sem_ir.c: os_ReleaseSemaphore() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 450
diff changeset
33 return(OS_OK);
578ba9dfc369 os_sem_ir.c: os_ReleaseSemaphore() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 450
diff changeset
34 else
578ba9dfc369 os_sem_ir.c: os_ReleaseSemaphore() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 450
diff changeset
35 return(OS_ERROR);
578ba9dfc369 os_sem_ir.c: os_ReleaseSemaphore() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 450
diff changeset
36 }
578ba9dfc369 os_sem_ir.c: os_ReleaseSemaphore() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 450
diff changeset
37
450
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 int
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 ObtainSemaphoreCB(NU_SEMAPHORE *SemCB, ULONG Timeout, USHORT wait_check)
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 {
452
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
41 UNSIGNED nu_timeout;
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
42 STATUS sts;
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
43 int ret;
450
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44
452
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
45 ret = OS_OK;
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
46 if (Timeout != OS_SUSPEND)
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
47 nu_timeout = TIME_TO_SYSTEM_TICKS(Timeout);
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
48 else if (wait_check == 1)
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
49 nu_timeout = 1;
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
50 else
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
51 nu_timeout = NU_SUSPEND;
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
52 for (;;) {
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
53 sts = NU_Obtain_Semaphore(SemCB, nu_timeout);
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
54 switch (sts) {
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
55 case NU_SUCCESS:
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
56 return(ret);
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
57 case NU_INVALID_SEMAPHORE:
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
58 return(OS_ERROR);
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
59 case NU_INVALID_SUSPEND:
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
60 nu_timeout = 0;
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
61 continue;
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
62 case NU_TIMEOUT:
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
63 case NU_UNAVAILABLE:
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
64 if (nu_timeout == 1 && wait_check == 1) {
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
65 nu_timeout = NU_SUSPEND;
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
66 ret = OS_WAITED;
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
67 continue;
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
68 }
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
69 return(OS_TIMEOUT);
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
70 default:
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
71 /*
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
72 * Disassembly reveals that the original code
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
73 * has an endless loop here, the equivalent
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
74 * of continue. My guess is that they simply
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
75 * forgot the default case, and so control
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
76 * falls onto the closing brace of the switch
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
77 * and then onto the closing brace of the for
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
78 * loop. But I prefer better error handling,
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
79 * hence the present addition. - Space Falcon
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
80 */
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
81 return(OS_ERROR);
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
82 }
d461c532c76d os_sem_ir.c: ObtainSemaphoreCB() done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 451
diff changeset
83 }
450
8768b9f28073 OSL: os_sem_ir.c started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 }
453
d2b93cfe8e4c OSL: os_sem_ir.c done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 452
diff changeset
85
d2b93cfe8e4c OSL: os_sem_ir.c done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 452
diff changeset
86 GLOBAL LONG
d2b93cfe8e4c OSL: os_sem_ir.c done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 452
diff changeset
87 os_ObtainSemaphore(OS_HANDLE TaskHandle, OS_HANDLE SemHandle, ULONG Timeout)
d2b93cfe8e4c OSL: os_sem_ir.c done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 452
diff changeset
88 {
d2b93cfe8e4c OSL: os_sem_ir.c done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 452
diff changeset
89 if (SemHandle > MaxSemaphores)
d2b93cfe8e4c OSL: os_sem_ir.c done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 452
diff changeset
90 return(OS_ERROR);
d2b93cfe8e4c OSL: os_sem_ir.c done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 452
diff changeset
91 return ObtainSemaphoreCB(&SemTable[SemHandle].SemCB, Timeout, 0);
d2b93cfe8e4c OSL: os_sem_ir.c done
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 452
diff changeset
92 }