annotate gsm-fw/services/ffs/rand.c @ 858:4c6e7ada647b

compressed trace decoder almost fully implemented
author Space Falcon <falcon@ivan.Harhan.ORG>
date Sat, 02 May 2015 08:08:26 +0000
parents 2beb88a3d528
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
219
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This version of rand() has been lifted from Ancient UNIX, and modified
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * to match the version used in TI's TCS211 GSM firmware, as revealed by
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 * disassembly of rand.obj in the rts16le_flash.lib binary library used
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 * by that semi-src package. TI's version (most likely from their compiler
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 * tools group, rather than the GSM fw group, but who knows) uses the
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 * same trivial implementation of rand() as the original Ancient UNIX libc,
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 * but with one change: TI's return value is right-shifted by 16 bits
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 * compared to what the Ancient UNIX rand() would have returned.
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 * The caller thus gets back only 15 pseudo-random bits rather than 31,
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 * but then the lower bits of the original rand() return value are
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 * known to be pretty bad.
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 *
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 * rand() is used by some FFS code in reclaim.c. If we don't provide our
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 * own version of rand() and let the linker pull the version from newlib,
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 * the link fails because the latter uses malloc. This ancient implementation
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 * of rand() is quite poor, but my plan is to look into possibly adopting
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 * some better PRNG after we get the basic TI GSM firmware reintegrated.
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 */
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 static long randx = 1;
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 srand(x)
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 unsigned x;
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 {
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 randx = x;
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 }
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 rand()
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 {
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 return ((randx = randx * 1103515245 + 12345) & 0x7fffffff) >> 16;
2beb88a3d528 gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 }