Chameleon

Chameleon Commit Details

Date:2012-05-21 15:18:17 (11 years 11 months ago)
Author:armel cadet-petit
Commit:1972
Parents: 1971
Message:please see the changelog...
Changes:
D/branches/cparm/i386/libsaio/utstring.h
D/branches/cparm/i386/libsaio/arc4random.c
D/branches/cparm/i386/libsa/rand.c
D/branches/cparm/i386/libsaio/utlist.h
D/branches/cparm/i386/libsaio/internal_modules.h
A/branches/cparm/i386/util/utstring.h
A/branches/cparm/i386/libsaio/time.c
A/branches/cparm/i386/util/smbios-fbsd.c
A/branches/cparm/i386/util/utlist.h
A/branches/cparm/i386/util/random-fbsd.c
A/branches/cparm/i386/libsaio/rtc.c
A/branches/cparm/i386/util/rand-fbsd.c
A/branches/cparm/i386/libsaio/arc4random-fbsd.c
A/branches/cparm/i386/libsaio/lib.c
M/branches/cparm/i386/libsaio/bootstruct.h
M/branches/cparm/i386/modules/HibernateEnabler/graphic_utils.c
M/branches/cparm/i386/libsaio/stringTable.c
M/branches/cparm/i386/libsaio/load.c
M/branches/cparm/i386/modules/HibernateEnabler/resume.c
M/branches/cparm/i386/libsaio/convert.c
M/branches/cparm/i386/libsaio/platform.c
M/branches/cparm/i386/util/amlsgn.m
M/branches/cparm/i386/libsaio/platform.h
M/branches/cparm/i386/libsaio/disk.c
M/branches/cparm/i386/libsaio/device_inject.c
M/branches/cparm/i386/libsaio/Makefile
M/branches/cparm/i386/libsaio/utarray.h
M/branches/cparm/i386/libsaio/device_inject.h
M/branches/cparm/i386/libsaio/xml.c
M/branches/cparm/i386/libsaio/CoreHash.h
M/branches/cparm/i386/libsaio/uterror.c
M/branches/cparm/i386/libsaio/console.c
M/branches/cparm/i386/boot2/graphics.c
M/branches/cparm/i386/libsa/Makefile
M/branches/cparm/i386/libsaio/xml.h
M/branches/cparm/CHANGES
M/branches/cparm/i386/libsaio/vbe.c
M/branches/cparm/i386/modules/NetbookInstaller/NBI.c
M/branches/cparm/i386/libsaio/hfs.c
M/branches/cparm/i386/libsaio/vbe.h
M/branches/cparm/i386/MakeInc.dir
M/branches/cparm/xcode3_sym.zip
M/branches/cparm/i386/libsaio/libsaio.h
M/branches/cparm/i386/libsaio/fake_efi.c
M/branches/cparm/i386/libsaio/misc.c
M/branches/cparm/i386/libsa/zalloc.c
M/branches/cparm/i386/libsaio/ufs.c
M/branches/cparm/i386/modules/RamDiskLoader/ramdisk.c
M/branches/cparm/i386/boot2/boot.c
M/branches/cparm/i386/libsa/libsa.h
M/branches/cparm/i386/libsaio/modules.c
M/branches/cparm/i386/modules/Keymapper/Keylayout.c
M/branches/cparm/i386/boot2/boot.h
M/branches/cparm/i386/libsaio/modules.h
M/branches/cparm/i386/libsa/string.c
M/branches/cparm/i386/modules/SMBiosGetters/mysmbios.c
M/branches/cparm/i386/libsaio/sl.h
M/branches/cparm/i386/libsaio/allocate.c
M/branches/cparm/Chameleon.xcodeproj/project.pbxproj
M/branches/cparm/i386/libsaio/msdos.c
M/branches/cparm/i386/modules/RamDiskLoader/RamDiskLoader.c
M/branches/cparm/i386/modules/Memory/Makefile
M/branches/cparm/i386/modules/SMBiosPatcher/smbios_patcher.c
M/branches/cparm/i386/libsaio/saio_internal.h
M/branches/cparm/i386/boot2/options.c
M/branches/cparm/i386/libsaio/uthash.h
M/branches/cparm/i386/modules/GUI/GUI_module.c
M/branches/cparm/i386/modules/ACPICodec/acpi_codec.c
M/branches/cparm/i386/modules/Memory/README
M/branches/cparm/i386/libsaio/intel_acpi.h
M/branches/cparm/i386/libsaio/sys.c
M/branches/cparm/i386/boot2/drivers.c
M/branches/cparm/i386/modules/Makefile
M/branches/cparm/i386/libsaio/saio_types.h
M/branches/cparm/i386/boot2/drivers.h
M/branches/cparm/i386/libsaio/cpu.c
M/branches/cparm/i386/modules/GUI/gui.c
M/branches/cparm/i386/boot2/Makefile
M/branches/cparm/i386/libsa/strtol.c
M/branches/cparm/i386/libsaio/stack_protector.c
M/branches/cparm/i386/modules/GUI/graphic_utils.c
M/branches/cparm/i386/libsaio/bootstruct.c
M/branches/cparm/TODO

File differences

branches/cparm/TODO
11
22
33
4
54
5
6
7
8
9
610
711
8
12
913
1014
1115
12
13
1416
1517
1618
1719
18
19
20
20
2121
2222
2323
TODO List for Chameleon Boot Loader
====================================
- update cpu_intel_amd
- split nvidia, gma and ati code into separate modules
- move device_inject, winfs, bsdfs, ext2fs, befs, and the command lspci, memory, more and video into modules
- Implement a pool allocator, so each module will run and allocate memory in there own pool, de-alloc all allocated memory by the module,
will be done simply by destroying the pool
- Implement snprintf to avoid buffer overflow in some case
- implement cpu topology
- Backport cconfig from the trunk
- move winfs, bsdfs, ext2fs, befs and lspci into modules
- update cpu_intel_amd
- Implement a Host like in bits to avoid some return issues
- update project with corehash
- Implement a pool allocator, so each module will run and allocate memory in there own pool, de-alloc all allocated memory by the module,
will be done simply by destroying the pool
- Try to sync our prf() with the apple/mach __doprnt() (in Xnu/osfmk/kern/printf.c) to normalize the formating in our printf, sprintf, etc ..., and facilitate bug fixes
- Implement snprintf to avoid buffer overflow in some case
- It seems that nvram variables must be set thru efiRuntimeServices->SetVariable(...),
NOTE: It seems that nvram variables must be set thru efiRuntimeServices->SetVariable(...),
then, the /options node is filled by kernel depending on the Runtime Services.
If true, this requires a more complete EFI implementation (perhaps in a module, or a kext).
branches/cparm/Chameleon.xcodeproj/project.pbxproj
213213
214214
215215
216
217216
218217
219218
......
261260
262261
263262
264
265263
266264
267265
......
388386
389387
390388
391
392389
393390
394391
395392
396
397393
398394
399395
......
452448
453449
454450
455
456451
457452
453
454
455
456
457
458
458459
459460
460461
461462
462
463
464463
465464
466465
......
954953
955954
956955
957
958956
959957
960958
......
966964
967965
968966
967
968
969
970
969971
970972
971973
972974
973975
974976
975
976977
977978
978979
......
10151016
10161017
10171018
1018
10191019
10201020
10211021
......
10611061
10621062
10631063
1064
1065
10661064
10671065
10681066
......
12591257
12601258
12611259
1262
1260
12631261
12641262
12651263
12661264
1267
1265
12681266
12691267
12701268
AB43B2E514C37E520018D529 /* prf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = prf.c; sourceTree = "<group>"; };
AB43B2E614C37E520018D529 /* printf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = printf.c; sourceTree = "<group>"; };
AB43B2E714C37E520018D529 /* qsort.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = qsort.c; sourceTree = "<group>"; };
AB43B2E814C37E520018D529 /* rand.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = rand.c; sourceTree = "<group>"; };
AB43B2E914C37E520018D529 /* setjmp.s */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = setjmp.s; sourceTree = "<group>"; };
AB43B2EA14C37E520018D529 /* string.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = string.c; sourceTree = "<group>"; };
AB43B2EB14C37E520018D529 /* strtol.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = strtol.c; sourceTree = "<group>"; };
AB43B31714C37E520018D529 /* hfs_CaseTables.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = hfs_CaseTables.h; sourceTree = "<group>"; };
AB43B31814C37E520018D529 /* hfs_compare.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = hfs_compare.c; sourceTree = "<group>"; };
AB43B31914C37E520018D529 /* intel_acpi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = intel_acpi.h; sourceTree = "<group>"; };
AB43B31A14C37E520018D529 /* internal_modules.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = internal_modules.h; sourceTree = "<group>"; };
AB43B31B14C37E520018D529 /* io_inline.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = io_inline.h; sourceTree = "<group>"; };
AB43B31C14C37E520018D529 /* libsaio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = libsaio.h; sourceTree = "<group>"; };
AB43B31D14C37E520018D529 /* load.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = load.c; sourceTree = "<group>"; };
AB43B3A214C37E520018D529 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
AB43B3A414C37E520018D529 /* dram_controllers.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dram_controllers.c; sourceTree = "<group>"; };
AB43B3A514C37E520018D529 /* dram_controllers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dram_controllers.h; sourceTree = "<group>"; };
AB43B3A614C37E520018D529 /* GPL_V2_LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = GPL_V2_LICENSE; sourceTree = "<group>"; };
AB43B3A714C37E520018D529 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
AB43B3A814C37E520018D529 /* mem.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mem.c; sourceTree = "<group>"; };
AB43B3A914C37E520018D529 /* mem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mem.h; sourceTree = "<group>"; };
AB43B3AA14C37E520018D529 /* Memory.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Memory.c; sourceTree = "<group>"; };
AB43B3AB14C37E520018D529 /* MEMTEST86_LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MEMTEST86_LICENSE; sourceTree = "<group>"; };
AB43B3AC14C37E520018D529 /* memvendors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = memvendors.h; sourceTree = "<group>"; };
AB43B3AD14C37E520018D529 /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
AB43B3AE14C37E520018D529 /* spd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = spd.c; sourceTree = "<group>"; };
AB43B3F214C383120018D529 /* udivdi3.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = udivdi3.c; sourceTree = "<group>"; };
AB43B3F314C383120018D529 /* umoddi3.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = umoddi3.c; sourceTree = "<group>"; };
AB43B3F814C384040018D529 /* stack_protector.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = stack_protector.c; sourceTree = "<group>"; };
AB43B42A14C3A8080018D529 /* arc4random.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = arc4random.c; sourceTree = "<group>"; };
AB79217514F38CF200F5EB39 /* bootXnu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bootXnu.h; sourceTree = "<group>"; };
AB79219214F3919E00F5EB39 /* ModuleHelp.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ModuleHelp.txt; sourceTree = "<group>"; };
ABA0C7BF1568190C003440AF /* arc4random-fbsd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "arc4random-fbsd.c"; sourceTree = "<group>"; };
ABA0C7C01568190C003440AF /* lib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lib.c; sourceTree = "<group>"; };
ABA0C7C11568190C003440AF /* rtc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = rtc.c; sourceTree = "<group>"; };
ABA0C7C21568190C003440AF /* time.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = time.c; sourceTree = "<group>"; };
ABAC08601568835800C89CC3 /* GPL_V2_LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPL_V2_LICENSE; sourceTree = "<group>"; };
ABAC08611568836C00C89CC3 /* MEMTEST86_LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = MEMTEST86_LICENSE; sourceTree = "<group>"; };
ABB4CE7D151E39740053B64E /* lzss.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lzss.c; sourceTree = "<group>"; };
ABD521F114F9197900B62550 /* utarray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = utarray.h; sourceTree = "<group>"; };
ABD521F214F9197900B62550 /* uthash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = uthash.h; sourceTree = "<group>"; };
ABD521F314F9197900B62550 /* uterror.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = uterror.c; sourceTree = "<group>"; };
ABD521F414F9197900B62550 /* utlist.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = utlist.h; sourceTree = "<group>"; };
ABD521F514F9197900B62550 /* utstring.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = utstring.h; sourceTree = "<group>"; };
ABD9A1FC150F706A008DA465 /* CoreHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoreHash.h; sourceTree = "<group>"; };
ABD9A1FF150F80C4008DA465 /* CoreHash.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = CoreHash.c; sourceTree = "<group>"; };
ABE5FF4E14F9495500447F78 /* modules.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = modules.c; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.c; };
AB43B2E514C37E520018D529 /* prf.c */,
AB43B2E614C37E520018D529 /* printf.c */,
AB43B2E714C37E520018D529 /* qsort.c */,
AB43B2E814C37E520018D529 /* rand.c */,
AB43B2E914C37E520018D529 /* setjmp.s */,
AB43B2EA14C37E520018D529 /* string.c */,
AB43B2EB14C37E520018D529 /* strtol.c */,
AB43B2ED14C37E520018D529 /* libsaio */ = {
isa = PBXGroup;
children = (
ABA0C7BF1568190C003440AF /* arc4random-fbsd.c */,
ABA0C7C01568190C003440AF /* lib.c */,
ABA0C7C11568190C003440AF /* rtc.c */,
ABA0C7C21568190C003440AF /* time.c */,
ABB4CE7D151E39740053B64E /* lzss.c */,
AB43B2EE14C37E520018D529 /* acpi.h */,
AB43B2EF14C37E520018D529 /* acpi_tools.c */,
AB43B2F014C37E520018D529 /* acpi_tools.h */,
AB43B2F114C37E520018D529 /* allocate.c */,
AB43B2F214C37E520018D529 /* apic.h */,
AB43B42A14C3A8080018D529 /* arc4random.c */,
AB43B2F314C37E520018D529 /* asm.s */,
AB43B2F414C37E520018D529 /* befs.c */,
AB43B2F514C37E520018D529 /* befs.h */,
AB43B31714C37E520018D529 /* hfs_CaseTables.h */,
AB43B31814C37E520018D529 /* hfs_compare.c */,
AB43B31914C37E520018D529 /* intel_acpi.h */,
AB43B31A14C37E520018D529 /* internal_modules.h */,
AB43B31B14C37E520018D529 /* io_inline.h */,
AB43B31C14C37E520018D529 /* libsaio.h */,
AB43B31D14C37E520018D529 /* load.c */,
ABD521F114F9197900B62550 /* utarray.h */,
ABD521F214F9197900B62550 /* uthash.h */,
ABD521F314F9197900B62550 /* uterror.c */,
ABD521F414F9197900B62550 /* utlist.h */,
ABD521F514F9197900B62550 /* utstring.h */,
AB43B34114C37E520018D529 /* vbe.c */,
AB43B34214C37E520018D529 /* vbe.h */,
AB43B34314C37E520018D529 /* xml.c */,
children = (
AB43B3A414C37E520018D529 /* dram_controllers.c */,
AB43B3A514C37E520018D529 /* dram_controllers.h */,
AB43B3A614C37E520018D529 /* GPL_V2_LICENSE */,
ABAC08601568835800C89CC3 /* GPL_V2_LICENSE */,
AB43B3A714C37E520018D529 /* Makefile */,
AB43B3A814C37E520018D529 /* mem.c */,
AB43B3A914C37E520018D529 /* mem.h */,
AB43B3AA14C37E520018D529 /* Memory.c */,
AB43B3AB14C37E520018D529 /* MEMTEST86_LICENSE */,
ABAC08611568836C00C89CC3 /* MEMTEST86_LICENSE */,
AB43B3AC14C37E520018D529 /* memvendors.h */,
AB43B3AD14C37E520018D529 /* README */,
AB43B3AE14C37E520018D529 /* spd.c */,
branches/cparm/CHANGES
1
2
3
4
5
6
7
8
9
10
111
212
313
- security and stability fixes
- Improved Xcode4.3+ and clang compatibility
- Fixed a bug in device_inject.c
- Updated uthash, utarrey, etc ... to v1.9.6
- Replaced arc4random by the freebsd version (found in darwin's libc)
(also Removed others random generators since the pseudo-random generator now work perfectly )
- Implemented gettimeofday taken from libpayload
- finaly back to safe_malloc
- Sync'd the cpu legacy method to the trunk
- Implemented the Runtime Bundles Modules
- Updated nvidia and ati device id
- Small security fixes
branches/cparm/i386/libsaio/arc4random.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#include "libsaio.h"
/*
* License for L15_Swap, L15_InitState, L_SCHEDULE, L15_KSA, L15_Discard, L15, L15_Byte
*
* Copyright (c) 2004, 2005, 2006 Robin J Carey. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification, immediately at the beginning of the file.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $DragonFly: src/sys/kern/kern_nrandom.c,v 1.7 2008/08/01 04:42:30 dillon Exp $
*/
/*
* IMPORTANT NOTE: LByteType must be exactly 8-bits in size or this software
* will not function correctly.
*/
typedef unsigned char LByteType;
#define L15_STATE_SIZE 256
static LByteType L15_x, L15_y;
static LByteType L15_start_x;
static LByteType L15_state[L15_STATE_SIZE];
/*
* PRIVATE FUNCS:
*/
static void L15(const LByteType * const key, const size_t keyLen);
static void L15_Swap(const LByteType pos1, const LByteType pos2);
static void L15_InitState(void);
static void L15_KSA(const LByteType * const key,
const size_t keyLen);
static void L15_Discard(const LByteType numCalls);
/*
* PUBLIC INTERFACE:
*/
static LByteType L15_Byte(void);
static __inline void
L15_Swap(const LByteType pos1, const LByteType pos2)
{
const LByteType save1 = L15_state[pos1];
L15_state[pos1] = L15_state[pos2];
L15_state[pos2] = save1;
}
static void
L15_InitState (void)
{
size_t i;
for (i = 0; i < L15_STATE_SIZE; ++i)
L15_state[i] = i;
}
#define L_SCHEDULE(xx) \
\
for (i = 0; i < L15_STATE_SIZE; ++i) { \
L15_Swap(i, (stateIndex += (L15_state[i] + (xx)))); \
}
static void
L15_KSA (const LByteType * const key, const size_t keyLen)
{
size_t i, keyIndex;
LByteType stateIndex = 0;
L_SCHEDULE(keyLen);
for (keyIndex = 0; keyIndex < keyLen; ++keyIndex) {
L_SCHEDULE(key[keyIndex]);
}
}
static void
L15_Discard(const LByteType numCalls)
{
LByteType i;
for (i = 0; i < numCalls; ++i) {
(void)L15_Byte();
}
}
/*
* PUBLIC INTERFACE:
*/
static void
L15(const LByteType * const key, const size_t keyLen)
{
L15_x = L15_start_x = 0;
L15_y = L15_STATE_SIZE - 1;
L15_InitState();
L15_KSA(key, keyLen);
L15_Discard(L15_Byte());
}
static LByteType
L15_Byte(void)
{
LByteType z;
L15_Swap(L15_state[L15_x], L15_y);
z = (L15_state [L15_x++] + L15_state[L15_y--]);
if (L15_x == L15_start_x) {
--L15_y;
}
return (L15_state[z]);
}
/*-
* THE BEER-WARE LICENSE
*
* <dan@FreeBSD.ORG> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you
* think this stuff is worth it, you can buy me a beer in return.
*
* Dan Moschuk
*
* $FreeBSD: src/sys/libkern/arc4random.c,v 1.3.2.2 2001/09/17 07:06:50 silby Exp $
*/
#defineARC4_MAXRUNS 16384
#defineARC4_RESEED_SECONDS 300 * 18
#defineARC4_KEYBYTES 32 /* 256 bit key */
static u_int8_t arc4_i, arc4_j;
static int arc4_initialized = 0;
static int arc4_numruns = 0;
static u_int8_t arc4_sbox[256];
static u_int32_t arc4_tv_nextreseed;
static u_int8_t arc4_randbyte(void);
static __inline void
arc4_swap(u_int8_t *a, u_int8_t *b)
{
u_int8_t c;
c = *a;
*a = *b;
*b = c;
}
/*
* Stir our S-box.
*/
static void
arc4_randomstir (void)
{
u_int8_t key[256];
int r, n;
/*
* XXX read_random() returns unsafe numbers if the entropy
* device is not loaded -- MarkM.
*/
{
for (r = 0; r < ARC4_KEYBYTES; ++r)
((u_char *)key)[r] = L15_Byte();
}
/* If r == 0 || -1, just use what was on the stack. */
if (r > 0)
{
for (n = r; n < sizeof(key); n++)
key[n] = key[n % r];
}
for (n = 0; n < 256; n++)
{
arc4_j = (arc4_j + arc4_sbox[n] + key[n]) % 256;
arc4_swap(&arc4_sbox[n], &arc4_sbox[arc4_j]);
}
arc4_i = arc4_j = 0;
/* Reset for next reseed cycle. */
arc4_tv_nextreseed = time18();
arc4_tv_nextreseed += ARC4_RESEED_SECONDS;
arc4_numruns = 0;
}
/*
* Initialize our S-box to its beginning defaults.
*/
void
arc4_init(void)
{
int n;
u_int32_t now = time18();
L15((const LByteType *)&now, sizeof(u_int32_t));
arc4_i = arc4_j = 0;
for (n = 0; n < 256; n++)
arc4_sbox[n] = (u_int8_t) n;
arc4_randomstir();
arc4_initialized = 1;
/*
* Throw away the first N words of output, as suggested in the
* paper "Weaknesses in the Key Scheduling Algorithm of RC4"
* by Fluher, Mantin, and Shamir. (N = 256 in our case.)
*/
for (n = 0; n < 256*4; n++)
arc4_randbyte();
}
/*
* Generate a random byte.
*/
static u_int8_t
arc4_randbyte(void)
{
u_int8_t arc4_t;
arc4_i = (arc4_i + 1) % 256;
arc4_j = (arc4_j + arc4_sbox[arc4_i]) % 256;
arc4_swap(&arc4_sbox[arc4_i], &arc4_sbox[arc4_j]);
arc4_t = (arc4_sbox[arc4_i] + arc4_sbox[arc4_j]) % 256;
return arc4_sbox[arc4_t];
}
void
arc4rand(void *ptr, u_int len, int reseed)
{
u_char *p;
u_int32_t tv_now;
/* Initialize array if needed. */
if (!arc4_initialized)
arc4_init();
tv_now = time18();
if (reseed ||
(arc4_numruns > ARC4_MAXRUNS) ||
(tv_now > arc4_tv_nextreseed))
arc4_randomstir();
arc4_numruns += len;
p = ptr;
while (len--)
*p++ = arc4_randbyte();
}
uint32_t
arc4random(void)
{
uint32_t ret;
arc4rand(&ret, sizeof ret, 0);
return ret;
}
branches/cparm/i386/libsaio/internal_modules.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifndef __INTERNAL_MODULES_H
#define __INTERNAL_MODULES_H
static inline void load_all_internal_modules()
{
// HOW TO: the procedure is quite simple but not automatic yet,
// to embed a module just drag/copy the content your module folder (*.c,*.h, etc...), but DO NOT COPY THE MAKEFILE.
// into libsaio folder, edit the libsaio makefile to build the files that you just added,
// and add here some code to start the module,
// ex. :
//extern void ACPICodec_start();
//ACPICodec_start();
//extern void SMBiosGetters_start();
//SMBiosGetters_start();
//extern void GUI_start();
//GUI_start();
// Done !!!
}
#endif /* __INTERNAL_MODULES_H */
branches/cparm/i386/libsaio/utstring.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
Copyright (c) 2008-2011, Troy D. Hanson http://uthash.sourceforge.net
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* a dynamic string implementation using macros
* see http://uthash.sourceforge.net/utstring
*/
#ifndef UTSTRING_H
#define UTSTRING_H
#define UTSTRING_VERSION 1.9.4
#ifdef __GNUC__
#define _UNUSED_ __attribute__ ((__unused__))
#else
#define _UNUSED_
#endif
#include "libsaio.h"
#define oom() longjmp(h_buf_error,-1)
typedef struct {
char *d;
size_t n; /* allocd size */
size_t i; /* index of first unused byte */
} UT_string;
#define utstring_reserve(s,amt) \
do { \
if (((s)->n - (s)->i) < (size_t)(amt)) { \
(s)->d = (char*)realloc((s)->d, (s)->n + amt); \
if ((s)->d == NULL) oom(); \
(s)->n += amt; \
} \
} while(0)
#define utstring_init(s) \
do { \
(s)->n = 0; (s)->i = 0; (s)->d = NULL; \
utstring_reserve(s,100); \
(s)->d[0] = '\0'; \
} while(0)
#define utstring_done(s) \
do { \
if ((s)->d != NULL) free((s)->d); \
(s)->n = 0; \
} while(0)
#define utstring_free(s) \
do { \
utstring_done(s); \
free(s); \
} while(0)
#if 0
#define utstring_new(s) \
do { \
s = (UT_string*)calloc(sizeof(UT_string),1); \
if (!s) oom(); \
utstring_init(s); \
} while(0)
#else
#define utstring_new(s) \
do { \
s = (UT_string*)malloc(sizeof(UT_string)); \
if (!s) oom(); \
utstring_init(s); \
} while(0)
#endif
#define utstring_renew(s) \
do { \
if (s) { \
utstring_clear(s); \
} else { \
utstring_new(s); \
} \
} while(0)
#define utstring_clear(s) \
do { \
(s)->i = 0; \
(s)->d[0] = '\0'; \
} while(0)
#define utstring_bincpy(s,b,l) \
do { \
utstring_reserve((s),(l)+1); \
if (l) memcpy(&(s)->d[(s)->i], b, l); \
(s)->i += l; \
(s)->d[(s)->i]='\0'; \
} while(0)
#define utstring_concat(dst,src) \
do { \
utstring_reserve(dst,(src->i)+1); \
if (src->i) memcpy(&(dst)->d[(dst)->i], src->d, src->i); \
dst->i += src->i; \
dst->d[dst->i]='\0'; \
} while(0)
#define utstring_len(s) ((unsigned)((s)->i))
#define utstring_body(s) ((s)->d)
_UNUSED_ static void utstring_printf_va(UT_string *s, const char *fmt, va_list ap) {
int n;
va_list cp;
while (1) {
#ifdef _WIN32
cp = ap;
#else
va_copy(cp, ap);
#endif
n = vsnprintf (&s->d[s->i], s->n-s->i, fmt, cp);
va_end(cp);
if ((n > -1) && (n < (int)(s->n-s->i))) {
s->i += n;
return;
}
/* Else try again with more space. */
if (n > -1) utstring_reserve(s,n+1); /* exact */
else utstring_reserve(s,(s->n)*2); /* 2x */
}
}
_UNUSED_ static void utstring_printf(UT_string *s, const char *fmt, ...) {
va_list ap;
va_start(ap,fmt);
utstring_printf_va(s,fmt,ap);
va_end(ap);
}
#endif /* UTSTRING_H */
branches/cparm/i386/libsaio/utlist.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
/*
Copyright (c) 2007-2011, Troy D. Hanson http://uthash.sourceforge.net
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UTLIST_H
#define UTLIST_H
#define UTLIST_VERSION 1.9.4
#include <assert.h>
/*
* This file contains macros to manipulate singly and doubly-linked lists.
*
* 1. LL_ macros: singly-linked lists.
* 2. DL_ macros: doubly-linked lists.
* 3. CDL_ macros: circular doubly-linked lists.
*
* To use singly-linked lists, your structure must have a "next" pointer.
* To use doubly-linked lists, your structure must "prev" and "next" pointers.
* Either way, the pointer to the head of the list must be initialized to NULL.
*
* ----------------.EXAMPLE -------------------------
* struct item {
* int id;
* struct item *prev, *next;
* }
*
* struct item *list = NULL:
*
* int main() {
* struct item *item;
* ... allocate and populate item ...
* DL_APPEND(list, item);
* }
* --------------------------------------------------
*
* For doubly-linked lists, the append and delete macros are O(1)
* For singly-linked lists, append and delete are O(n) but prepend is O(1)
* The sort macro is O(n log(n)) for all types of single/double/circular lists.
*/
/* These macros use decltype or the earlier __typeof GNU extension.
As decltype is only available in newer compilers (VS2010 or gcc 4.3+
when compiling c++ code), this code uses whatever method is needed
or, for VS2008 where neither is available, uses casting workarounds. */
#ifdef _MSC_VER /* MS compiler */
#if _MSC_VER >= 1600 && defined(__cplusplus) /* VS2010 or newer in C++ mode */
#define LDECLTYPE(x) decltype(x)
#else /* VS2008 or older (or VS2010 in C mode) */
#define NO_DECLTYPE
#define LDECLTYPE(x) char*
#endif
#else /* GNU, Sun and other compilers */
#define LDECLTYPE(x) __typeof(x)
#endif
/* for VS2008 we use some workarounds to get around the lack of decltype,
* namely, we always reassign our tmp variable to the list head if we need
* to dereference its prev/next pointers, and save/restore the real head.*/
#ifdef NO_DECLTYPE
#define _SV(elt,list) _tmp = (char*)(list); {char **_alias = (char**)&(list); *_alias = (elt); }
#define _NEXT(elt,list) ((char*)((list)->next))
#define _NEXTASGN(elt,list,to) { char **_alias = (char**)&((list)->next); *_alias=(char*)(to); }
#define _PREV(elt,list) ((char*)((list)->prev))
#define _PREVASGN(elt,list,to) { char **_alias = (char**)&((list)->prev); *_alias=(char*)(to); }
#define _RS(list) { char **_alias = (char**)&(list); *_alias=_tmp; }
#define _CASTASGN(a,b) { char **_alias = (char**)&(a); *_alias=(char*)(b); }
#else
#define _SV(elt,list)
#define _NEXT(elt,list) ((elt)->next)
#define _NEXTASGN(elt,list,to) ((elt)->next)=(to)
#define _PREV(elt,list) ((elt)->prev)
#define _PREVASGN(elt,list,to) ((elt)->prev)=(to)
#define _RS(list)
#define _CASTASGN(a,b) (a)=(b)
#endif
/******************************************************************************
* The sort macro is an adaptation of Simon Tatham's O(n log(n)) mergesort *
* Unwieldy variable names used here to avoid shadowing passed-in variables. *
*****************************************************************************/
#define LL_SORT(list, cmp) \
do { \
LDECLTYPE(list) _ls_p; \
LDECLTYPE(list) _ls_q; \
LDECLTYPE(list) _ls_e; \
LDECLTYPE(list) _ls_tail; \
LDECLTYPE(list) _ls_oldhead; \
LDECLTYPE(list) _tmp; \
int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \
if (list) { \
_ls_insize = 1; \
_ls_looping = 1; \
while (_ls_looping) { \
_CASTASGN(_ls_p,list); \
_CASTASGN(_ls_oldhead,list); \
list = NULL; \
_ls_tail = NULL; \
_ls_nmerges = 0; \
while (_ls_p) { \
_ls_nmerges++; \
_ls_q = _ls_p; \
_ls_psize = 0; \
for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \
_ls_psize++; \
_SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); \
if (!_ls_q) break; \
} \
_ls_qsize = _ls_insize; \
while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \
if (_ls_psize == 0) { \
_ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
} else if (_ls_qsize == 0 || !_ls_q) { \
_ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
} else if (cmp(_ls_p,_ls_q) <= 0) { \
_ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
} else { \
_ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
} \
if (_ls_tail) { \
_SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e); _RS(list); \
} else { \
_CASTASGN(list,_ls_e); \
} \
_ls_tail = _ls_e; \
} \
_ls_p = _ls_q; \
} \
_SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,NULL); _RS(list); \
if (_ls_nmerges <= 1) { \
_ls_looping=0; \
} \
_ls_insize *= 2; \
} \
} else _tmp=NULL; /* quiet gcc unused variable warning */ \
} while (0)
#define DL_SORT(list, cmp) \
do { \
LDECLTYPE(list) _ls_p; \
LDECLTYPE(list) _ls_q; \
LDECLTYPE(list) _ls_e; \
LDECLTYPE(list) _ls_tail; \
LDECLTYPE(list) _ls_oldhead; \
LDECLTYPE(list) _tmp; \
int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \
if (list) { \
_ls_insize = 1; \
_ls_looping = 1; \
while (_ls_looping) { \
_CASTASGN(_ls_p,list); \
_CASTASGN(_ls_oldhead,list); \
list = NULL; \
_ls_tail = NULL; \
_ls_nmerges = 0; \
while (_ls_p) { \
_ls_nmerges++; \
_ls_q = _ls_p; \
_ls_psize = 0; \
for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \
_ls_psize++; \
_SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); \
if (!_ls_q) break; \
} \
_ls_qsize = _ls_insize; \
while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \
if (_ls_psize == 0) { \
_ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
} else if (_ls_qsize == 0 || !_ls_q) { \
_ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
} else if (cmp(_ls_p,_ls_q) <= 0) { \
_ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
} else { \
_ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
} \
if (_ls_tail) { \
_SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e); _RS(list); \
} else { \
_CASTASGN(list,_ls_e); \
} \
_SV(_ls_e,list); _PREVASGN(_ls_e,list,_ls_tail); _RS(list); \
_ls_tail = _ls_e; \
} \
_ls_p = _ls_q; \
} \
_CASTASGN(list->prev, _ls_tail); \
_SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,NULL); _RS(list); \
if (_ls_nmerges <= 1) { \
_ls_looping=0; \
} \
_ls_insize *= 2; \
} \
} else _tmp=NULL; /* quiet gcc unused variable warning */ \
} while (0)
#define CDL_SORT(list, cmp) \
do { \
LDECLTYPE(list) _ls_p; \
LDECLTYPE(list) _ls_q; \
LDECLTYPE(list) _ls_e; \
LDECLTYPE(list) _ls_tail; \
LDECLTYPE(list) _ls_oldhead; \
LDECLTYPE(list) _tmp; \
LDECLTYPE(list) _tmp2; \
int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \
if (list) { \
_ls_insize = 1; \
_ls_looping = 1; \
while (_ls_looping) { \
_CASTASGN(_ls_p,list); \
_CASTASGN(_ls_oldhead,list); \
list = NULL; \
_ls_tail = NULL; \
_ls_nmerges = 0; \
while (_ls_p) { \
_ls_nmerges++; \
_ls_q = _ls_p; \
_ls_psize = 0; \
for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \
_ls_psize++; \
_SV(_ls_q,list); \
if (_NEXT(_ls_q,list) == _ls_oldhead) { \
_ls_q = NULL; \
} else { \
_ls_q = _NEXT(_ls_q,list); \
} \
_RS(list); \
if (!_ls_q) break; \
} \
_ls_qsize = _ls_insize; \
while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \
if (_ls_psize == 0) { \
_ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
if (_ls_q == _ls_oldhead) { _ls_q = NULL; } \
} else if (_ls_qsize == 0 || !_ls_q) { \
_ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
if (_ls_p == _ls_oldhead) { _ls_p = NULL; } \
} else if (cmp(_ls_p,_ls_q) <= 0) { \
_ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
if (_ls_p == _ls_oldhead) { _ls_p = NULL; } \
} else { \
_ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
if (_ls_q == _ls_oldhead) { _ls_q = NULL; } \
} \
if (_ls_tail) { \
_SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e); _RS(list); \
} else { \
_CASTASGN(list,_ls_e); \
} \
_SV(_ls_e,list); _PREVASGN(_ls_e,list,_ls_tail); _RS(list); \
_ls_tail = _ls_e; \
} \
_ls_p = _ls_q; \
} \
_CASTASGN(list->prev,_ls_tail); \
_CASTASGN(_tmp2,list); \
_SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_tmp2); _RS(list); \
if (_ls_nmerges <= 1) { \
_ls_looping=0; \
} \
_ls_insize *= 2; \
} \
} else _tmp=NULL; /* quiet gcc unused variable warning */ \
} while (0)
/******************************************************************************
* singly linked list macros (non-circular) *
*****************************************************************************/
#define LL_PREPEND(head,add) \
do { \
(add)->next = head; \
head = add; \
} while (0)
#define LL_CONCAT(head1,head2) \
do { \
LDECLTYPE(head1) _tmp; \
if (head1) { \
_tmp = head1; \
while (_tmp->next) { _tmp = _tmp->next; } \
_tmp->next=(head2); \
} else { \
(head1)=(head2); \
} \
} while (0)
#define LL_APPEND(head,add) \
do { \
LDECLTYPE(head) _tmp; \
(add)->next=NULL; \
if (head) { \
_tmp = head; \
while (_tmp->next) { _tmp = _tmp->next; } \
_tmp->next=(add); \
} else { \
(head)=(add); \
} \
} while (0)
#define LL_DELETE(head,del) \
do { \
LDECLTYPE(head) _tmp; \
if ((head) == (del)) { \
(head)=(head)->next; \
} else { \
_tmp = head; \
while (_tmp->next && (_tmp->next != (del))) { \
_tmp = _tmp->next; \
} \
if (_tmp->next) { \
_tmp->next = ((del)->next); \
} \
} \
} while (0)
/* Here are VS2008 replacements for LL_APPEND and LL_DELETE */
#define LL_APPEND_VS2008(head,add) \
do { \
if (head) { \
(add)->next = head; /* use add->next as a temp variable */ \
while ((add)->next->next) { (add)->next = (add)->next->next; } \
(add)->next->next=(add); \
} else { \
(head)=(add); \
} \
(add)->next=NULL; \
} while (0)
#define LL_DELETE_VS2008(head,del) \
do { \
if ((head) == (del)) { \
(head)=(head)->next; \
} else { \
char *_tmp = (char*)(head); \
while (head->next && (head->next != (del))) { \
head = head->next; \
} \
if (head->next) { \
head->next = ((del)->next); \
} \
{ \
char **_head_alias = (char**)&(head); \
*_head_alias = _tmp; \
} \
} \
} while (0)
#ifdef NO_DECLTYPE
#undef LL_APPEND
#define LL_APPEND LL_APPEND_VS2008
#undef LL_DELETE
#define LL_DELETE LL_DELETE_VS2008
#undef LL_CONCAT /* no LL_CONCAT_VS2008 */
#undef DL_CONCAT /* no DL_CONCAT_VS2008 */
#endif
/* end VS2008 replacements */
#define LL_FOREACH(head,el) \
for(el=head;el;el=el->next)
#define LL_FOREACH_SAFE(head,el,tmp) \
for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp)
#define LL_SEARCH_SCALAR(head,out,field,val) \
do { \
LL_FOREACH(head,out) { \
if ((out)->field == (val)) break; \
} \
} while(0)
#define LL_SEARCH(head,out,elt,cmp) \
do { \
LL_FOREACH(head,out) { \
if ((cmp(out,elt))==0) break; \
} \
} while(0)
/******************************************************************************
* doubly linked list macros (non-circular) *
*****************************************************************************/
#define DL_PREPEND(head,add) \
do { \
(add)->next = head; \
if (head) { \
(add)->prev = (head)->prev; \
(head)->prev = (add); \
} else { \
(add)->prev = (add); \
} \
(head) = (add); \
} while (0)
#define DL_APPEND(head,add) \
do { \
if (head) { \
(add)->prev = (head)->prev; \
(head)->prev->next = (add); \
(head)->prev = (add); \
(add)->next = NULL; \
} else { \
(head)=(add); \
(head)->prev = (head); \
(head)->next = NULL; \
} \
} while (0);
#define DL_CONCAT(head1,head2) \
do { \
LDECLTYPE(head1) _tmp; \
if (head2) { \
if (head1) { \
_tmp = (head2)->prev; \
(head2)->prev = (head1)->prev; \
(head1)->prev->next = (head2); \
(head1)->prev = _tmp; \
} else { \
(head1)=(head2); \
} \
} \
} while (0);
#define DL_DELETE(head,del) \
do { \
assert((del)->prev != NULL); \
if ((del)->prev == (del)) { \
(head)=NULL; \
} else if ((del)==(head)) { \
(del)->next->prev = (del)->prev; \
(head) = (del)->next; \
} else { \
(del)->prev->next = (del)->next; \
if ((del)->next) { \
(del)->next->prev = (del)->prev; \
} else { \
(head)->prev = (del)->prev; \
} \
} \
} while (0);
#define DL_FOREACH(head,el) \
for(el=head;el;el=el->next)
/* this version is safe for deleting the elements during iteration */
#define DL_FOREACH_SAFE(head,el,tmp) \
for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp)
/* these are identical to their singly-linked list counterparts */
#define DL_SEARCH_SCALAR LL_SEARCH_SCALAR
#define DL_SEARCH LL_SEARCH
/******************************************************************************
* circular doubly linked list macros *
*****************************************************************************/
#define CDL_PREPEND(head,add) \
do { \
if (head) { \
(add)->prev = (head)->prev; \
(add)->next = (head); \
(head)->prev = (add); \
(add)->prev->next = (add); \
} else { \
(add)->prev = (add); \
(add)->next = (add); \
} \
(head)=(add); \
} while (0)
#define CDL_DELETE(head,del) \
do { \
if ( ((head)==(del)) && ((head)->next == (head))) { \
(head) = 0L; \
} else { \
(del)->next->prev = (del)->prev; \
(del)->prev->next = (del)->next; \
if ((del) == (head)) (head)=(del)->next; \
} \
} while (0);
#define CDL_FOREACH(head,el) \
for(el=head;el;el=(el->next==head ? 0L : el->next))
#define CDL_FOREACH_SAFE(head,el,tmp1,tmp2) \
for((el)=(head), ((tmp1)=(head)?((head)->prev):NULL); \
(el) && ((tmp2)=(el)->next, 1); \
((el) = (((el)==(tmp1)) ? 0L : (tmp2))))
#define CDL_SEARCH_SCALAR(head,out,field,val) \
do { \
CDL_FOREACH(head,out) { \
if ((out)->field == (val)) break; \
} \
} while(0)
#define CDL_SEARCH(head,out,elt,cmp) \
do { \
CDL_FOREACH(head,out) { \
if ((cmp(out,elt))==0) break; \
} \
} while(0)
#endif /* UTLIST_H */
branches/cparm/i386/libsaio/xml.c
3939
4040
4141
42
42
4343
4444
4545
else if (dict == DEFAULT_HELPER_CONFIG_DICT) \
dict = bootInfo->helperConfig.dictionary ;
string_ref *ref_strings = NULL;
static string_ref *ref_strings = NULL;
/// TODO: remove below
static char* buffer_start = NULL;
branches/cparm/i386/libsaio/uterror.c
99
1010
1111
12
12
1313
1414
1515
#include "libsaio.h"
jmp_buf h_buf_error;
jmp_buf uterror;
void init_ut_fnc(void)
{
branches/cparm/i386/libsaio/console.c
4848
4949
5050
51
52
53
54
55
5651
5752
5853
5954
60
61
55
56
57
58
59
60
6261
6362
6463
......
7877
7978
8079
81
82
80
81
8382
83
84
8485
8586
86
87
88
87
88
89
8990
9091
9192
9293
93
94
9495
9596
9697
97
98
9899
99100
100101
101
102
102103
103104
104105
105
106
106107
107108
108
109109
110110
111111
112112
113113
114
114
115115
116116
117
117
118118
119119
120120
121
121
122122
123123
124124
125
125
126126
127127
128128
129129
130
130
131131
132132
133133
134134
135
135
136136
137
137138
138139
139140
......
191192
192193
193194
194
195
195196
196197
197
198
198199
199
200
200201
201202
202
203
203204
204205
205206
......
212213
213214
214215
215
216
216217
217218
218219
......
221222
222223
223224
224
225
225226
226227
227
228
228229
229
230
230231
231232
232
233
233234
234235
235236
......
240241
241242
242243
243
244
245
246
247
244248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
245265
246
247
248
266
267
268
249269
250270
251271
#include "bootstruct.h"
#include "platform.h"
//extern intvprf(const char * fmt, va_list ap);
bool gVerboseMode;
bool gErrors;
/* Kabyl: BooterLog */
#define BOOTER_LOG_SIZE (128 * 1024)
#define SAFE_LOG_SIZE 134
char *msgbuf = 0;
char *cursor = 0;
struct LOG {
char *buf;
char *cursor;
};
typedef struct LOG LOG;
static LOG booterlog;
struct putc_info {
char * str;
void initBooterLog(void)
{
msgbuf = malloc(BOOTER_LOG_SIZE);
if (!msgbuf) {
booterlog.buf = malloc(BOOTER_LOG_SIZE);
if (!booterlog.buf) {
printf("Couldn't allocate buffer for booter log\n");
booterlog.cursor = 0;
booterlog.buf = 0;
return;
}
bzero(msgbuf, BOOTER_LOG_SIZE);
cursor = msgbuf;
bzero(booterlog.buf, BOOTER_LOG_SIZE);
booterlog.cursor = booterlog.buf;
}
char *getConsoleMsg(void)
{
return msgbuf;
return booterlog.buf;
}
char *getConsoleCursor(void)
{
return cursor;
return booterlog.buf;
}
void setConsoleMsg(char *p)
{
msgbuf = p;
booterlog.buf = p;
}
void setConsoleCursor(char *p)
{
cursor = p;
booterlog.cursor = p;
}
void msglog(const char * fmt, ...)
{
va_list ap;
struct putc_info pi;
if (!msgbuf)
if (!booterlog.buf)
return;
if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
if (((booterlog.cursor - booterlog.buf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
return;
va_start(ap, fmt);
pi.str = cursor;
pi.str = booterlog.cursor;
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
va_end(ap);
cursor += strlen((char *)cursor);
booterlog.cursor += strlen((char *)booterlog.cursor);
}
void setupBooterLog(void)
{
if (!msgbuf)
if (!booterlog.buf)
return;
Node *node = DT__FindNode("/", false);
if (node)
DT__AddProperty(node, "boot-log", strlen((char *)msgbuf) + 1, msgbuf);
DT__AddProperty(node, "boot-log", strlen((char *)booterlog.buf) + 1, booterlog.buf);
}
/* Kabyl: !BooterLog */
/* Kabyl: BooterLog */
struct putc_info pi;
if (!msgbuf)
if (!booterlog.buf)
return 0;
if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
if (((booterlog.cursor - booterlog.buf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
return 0;
pi.str = cursor;
pi.str = booterlog.cursor;
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
cursor += strlen((char *)cursor);
booterlog.cursor += strlen((char *)booterlog.cursor);
}
va_end(ap);
va_list ap;
va_start(ap, fmt);
if (gVerboseMode)
if (get_env(envgVerboseMode))
{
prf(fmt, ap, putchar, 0);
}
/* Kabyl: BooterLog */
struct putc_info pi;
if (!msgbuf)
if (!booterlog.buf)
return 0;
if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
if (((booterlog.cursor - booterlog.buf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
return 0;
pi.str = cursor;
pi.str = booterlog.cursor;
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
cursor += strlen((char *)cursor);
booterlog.cursor += strlen((char *)booterlog.cursor);
}
va_end(ap);
int error(const char * fmt, ...)
{
va_list ap;
gErrors = true;
struct putc_info pi;
int len;
char *str = NULL;
va_start(ap, fmt);
len = prf(fmt, ap, 0, 0);
if (len > 0)
{
str = newEmptyStringWithLength(len);
if (str != NULL)
{
pi.last_str = 0;
pi.str = str;
prf(fmt, ap, sputc, &pi);
*pi.str = '\0';
}
}
va_end(ap);
prf(fmt, ap, putchar, 0);
va_end(ap);
set_env_copy(envConsoleErr, str, len);
free(str);
return(0);
}
branches/cparm/i386/libsaio/xml.h
4747
4848
4949
50
51
5250
5351
5452
......
8381
8482
8583
84
8685
8786
8887
};
typedef struct string_ref string_ref;
extern string_ref* ref_strings;
#define kXMLTagPList "plist "
#define kXMLTagDict "dict"
#define kXMLTagKey "key"
#define kPropNSPrincipalClass ("NSPrincipalClass")
#define kPropIOClass ("IOClass")
#define kPropIOProviderClass ("IOProviderClass")
#define kPropOSBundleWorkspace ("OSBundleWorkspace")
#define DEFAULT_BOOT_CONFIG_DICT (TagPtr)0
#define DEFAULT_SYSTEM_CONFIG_DICT (TagPtr)1
branches/cparm/i386/libsaio/bootstruct.c
4343
4444
4545
46
46
4747
4848
4949
......
110110
111111
112112
113
113
114114
115115
116116
117117
118118
119
120
119121
120
121122
122123
123124
/* ... */
PrivateBootInfo_t *bootInfo = NULL;
Node *gMemoryMapNode = NULL;
//Node *gMemoryMapNode = NULL;
static char platformName[64];
static MemoryRange memoryMap[kMemoryMapCountMax];
}
}
gMemoryMapNode = DT__FindNode("/chosen/memory-map", true);
Node *gMemoryMapNode = DT__FindNode("/chosen/memory-map", true);
set_env(envConvMem, convmem);
set_env(envExtMem, extmem);
set_env(envMemoryMap, (uint32_t)memoryMap);
set_env(envMemoryMapCnt, memoryMapCount);
set_env(envMemoryMapNode, (uint32_t)gMemoryMapNode);
init_done = 1;
}
branches/cparm/i386/libsaio/vbe.c
7676
7777
7878
79
80
7981
8082
81
83
8284
8385
8486
......
9395
9496
9597
96
9798
9899
99100
}
#endif
#if UNUSED
int getEDID( void * edidBlock, UInt8 block)
{
bzero(&bb, sizeof(bb));
bzero(&bb, sizeof(biosBuf_t));
bb.intno = 0x10;
bb.eax.rr = funcGetEDID;
bb.ebx.r.l= 0x01;
#if UNUSED
/*
* Default GTF parameter values.
*/
branches/cparm/i386/libsaio/bootstruct.h
4141
4242
4343
44
44
4545
4646
4747
extern boot_args_107 *bootArgs107;
extern boot_args_108 *bootArgs108;
extern Node *gMemoryMapNode;
//extern Node *gMemoryMapNode;
#define VGA_TEXT_MODE 0
branches/cparm/i386/libsaio/hfs.c
3131
3232
3333
34
3435
3536
3637
......
7677
7778
7879
79
80
81
8280
8381
8482
......
261259
262260
263261
264
262
263
265264
266265
267266
......
304303
305304
306305
307
306
308307
309308
310
311
309
310
312311
313312
314313
#include <hfs/hfs_format.h>
#include "hfs.h"
#include "platform.h"
#define kBlockSize (0x200)
#endif /* !__i386__ */
unsigned long HFSLoadVerbose = 1;
static long ReadFile(void *file, uint64_t *length, void *base, uint64_t offset);
static long GetCatalogEntryInfo(void *entry, long *flags, long *time,
FinderInfo *finderInfo, long *infoValid);
long HFSLoadFile(CICell ih, char * filePath)
{
return HFSReadFile(ih, filePath, (void *)gFSLoadAddress, 0, 0);
//return HFSReadFile(ih, filePath, (void *)gFSLoadAddress, 0, 0);
return HFSReadFile(ih, filePath, (void *)(uint32_t)get_env(envgFSLoadAddress), 0, 0);
}
long HFSReadFile(CICell ih, char * filePath, void *base, uint64_t offset, uint64_t length)
getDeviceDescription(ih, devStr);
if (HFSLoadVerbose) {
if (get_env(envHFSLoadVerbose)) {
verbose("Read HFS%s file: [%s/%s] %d bytes.\n",
(gIsHFSPlus ? "+" : ""), devStr, filePath, (uint32_t)length);
} else if (HFSLoadVerbose == 0) {
HFSLoadVerbose = 1;
} else if (get_env(envHFSLoadVerbose) == 0) {
safe_set_env(envHFSLoadVerbose, 1);
}
return length;
branches/cparm/i386/libsaio/vbe.h
230230
231231
232232
233
233
234234
235235
236236
......
243243
244244
245245
246
246
247247
248
248
249249
250250
251251
* CRTC information block passed to function 4F02
* to override default refresh rate.
*/
#pragma pack(1)
//#pragma pack(1)
typedef struct {
unsigned short HTotal;
unsigned long PixelClock; /* in Hz */
unsigned short RefreshRate; /* units of 0.01 Hz */
unsigned char Reserved[40];
} VBECRTCInfoBlock;
} __attribute__((packed)) VBECRTCInfoBlock;
#pragma pack()
//#pragma pack()
/*
* Defined flags for 'Flags' field in VBECRTCInfoBlock.
branches/cparm/i386/libsaio/allocate.c
2626
2727
2828
29
2930
3031
3132
......
4849
4950
5051
51
52
5253
5354
5455
#include "saio_internal.h"
#include "bootstruct.h"
#include "device_tree.h"
#include "platform.h"
static long gImageLastKernelAddr;
buffer[0] = start;
buffer[1] = length;
DT__AddProperty(gMemoryMapNode, nameBuf, 2 * sizeof(uint32_t), (char *)buffer);
DT__AddProperty((Node*)(uint32_t)get_env(envMemoryMapNode), nameBuf, 2 * sizeof(uint32_t), (char *)buffer);
return 0;
}
branches/cparm/i386/libsaio/libsaio.h
3131
3232
3333
34
3534
3635
3736
#include "io_inline.h"
#include "saio_types.h"
#include "saio_internal.h"
#include "internal_modules.h"
#include "uthash.h"
#endif /* !__LIBSAIO_LIBSAIO_H */
branches/cparm/i386/libsaio/Makefile
1414
1515
1616
17
17
1818
1919
2020
......
3131
3232
3333
34
34
3535
3636
3737
......
3939
4040
4141
42
42
4343
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
5944
6045
6146
CFLAGS= $(RC_CFLAGS) $(OPTIM) $(MORECPP) -arch i386 -g -Wmost -fno-stack-protector \
-D__ARCHITECTURE__=\"i386\" -DSAIO_INTERNAL_USER \
-DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \
-fno-builtin -static $(OMIT_FRAME_POINTER_CFLAG) -march=pentium4 -msse2 -msoft-float -ffreestanding -mpreferred-stack-boundary=2 -fno-align-functions -mfpmath=sse
-fno-builtin -static $(OMIT_FRAME_POINTER_CFLAG) -march=pentium4 -msse2 -msoft-float -Qunused-arguments -ffreestanding -DBOOT_CORE -mpreferred-stack-boundary=2 -fno-align-functions -mfpmath=sse
DEFINES=
CONFIG = hd
VPATH = $(OBJROOT):$(SYMROOT)
SAIO_OBJS = table.o asm.o bios.o biosfn.o arc4random.o \
SAIO_OBJS = table.o asm.o bios.o biosfn.o arc4random-fbsd.o \
disk.o sys.o cache.o bootstruct.o \
stringTable.o load.o pci.o allocate.o misc.o \
vbe.o hfs.o hfs_compare.o \
cpu.o platform.o \
fake_efi.o \
device_inject.o pci_root.o \
convert.o acpi_tools.o smbios.o uterror.o lzss.o
convert.o acpi_tools.o smbios.o uterror.o lzss.o lib.o rtc.o time.o
# example for AcpiCodec
#SAIO_OBJS += acpi_codec.o acpicode.o ACPICodec.o acpidecode.o
# example for AcpiPatcher
#SAIO_OBJS += aml_generator.o acpi_patcher.o AcpiPatcher.o
# example for GE
#SAIO_OBJS += nvidia.o ati.o gma.o GraphicsEnabler.o
# example for SMBiosGetters
#SAIO_OBJS += mysmbios.o smbios_decode.o smbios_getters.o SMBiosGetters.o
# example for GUI
#SAIO_OBJS += graphic_utils.o gui.o picopng.o GUI_module.o
# Options enabled by default:
#CFLAGS += -DNO_WIN_SUPPORT # -7744 bytes
SAIO_OBJS += ntfs.o msdos.o exfat.o
branches/cparm/i386/libsaio/ufs.c
194194
195195
196196
197
197
198
199
198200
199201
200202
long UFSLoadFile( CICell ih, char * filePath )
{
return UFSReadFile(ih, filePath, (void *)gFSLoadAddress, 0, 0);
//return UFSReadFile(ih, filePath, (void *)gFSLoadAddress, 0, 0);
return UFSReadFile(ih, filePath, (void *)(uint32_t)get_env(envgFSLoadAddress), 0, 0);
}
long UFSReadFile( CICell ih, char * filePath, void * base, uint64_t offset, uint64_t length )
branches/cparm/i386/libsaio/time.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* This file is part of the libpayload project.
*
* Copyright (C) 2008 Advanced Micro Devices, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/**
* @file libc/time.c
* General time functions
*/
#include "libsaio.h"
#include "cpu.h"
#include "platform.h"
static uint32_t cpu_khz;
static struct {
uint64_t ticks;
time_t secs;
suseconds_t usecs;
} private_clock;
#define TICKS_PER_SEC (cpu_khz * 1000)
#define TICKS_PER_USEC (cpu_khz / 1000)
static void update_clock(void)
{
uint64_t delta = rdtsc64() - private_clock.ticks;
int secs;
private_clock.ticks += delta;
secs = (int) (delta / TICKS_PER_SEC);
private_clock.secs += secs;
delta -= (secs * TICKS_PER_SEC);
private_clock.usecs += (int) (delta / TICKS_PER_USEC);
if (private_clock.usecs > 1000000) {
private_clock.usecs -= 1000000;
private_clock.secs++;
}
}
static unsigned int day_of_year(int mon, int day, int year)
{
static uint8_t mdays[12] = { 31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31 };
int i, ret = 0;
for(i = 0; i < mon; i++) {
ret += mdays[i];
if (i == 1 && (year % 4))
ret++;
}
return (ret + day);
}
static void gettimeofday_init(void)
{
int days, delta;
struct tm tm;
rtc_read_clock(&tm);
private_clock.ticks = rdtsc64();
/* Calculate the number of days in the year so far */
days = day_of_year(tm.tm_mon, tm.tm_mday, tm.tm_year + 1900);
delta = tm.tm_year - 70;
days += (delta * 365);
/* Figure leap years */
if (delta > 2)
days += (delta - 2) / 4;
private_clock.secs = (days * 86400) + (tm.tm_hour * 3600) +
(tm.tm_min * 60) + tm.tm_sec;
}
/**
* Return the current time broken into a timeval structure.
*
* @param tv A pointer to a timeval structure.
* @param tz Added for compatability - not used.
* @return 0 for success (this function cannot return non-zero currently).
*
* WARNING : In this implemetation gettimeofday() WILL NOT WORK until the cpu is initialized.
*/
int gettimeofday(struct timeval *tv, void *tz)
{
cpu_khz = (uint32_t)(get_env(envCPUFreq) / 1000);
if (!(cpu_khz>0)) {
return 1;
}
/*
* Call the gtod init when we need it - this keeps the code from
* being included in the binary if we don't need it.
*/
if (!private_clock.ticks)
gettimeofday_init();
update_clock();
tv->tv_sec = private_clock.secs;
tv->tv_usec = private_clock.usecs;
return 0;
}
branches/cparm/i386/libsaio/modules.c
179179
180180
181181
182
182
183
184
185
183186
184
185
186
187
188
189
190
191
192
193
187194
195
196
197
198
199
188200
201
202
203
204
205
189206
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
237232
238
239
240
241
242
243
244233
245234
246235
......
13561345
13571346
13581347
1359
1348
13601349
13611350
13621351
......
14361425
14371426
14381427
1428
14391429
14401430
14411431
......
16691659
16701660
16711661
1672
1662
16731663
16741664
16751665
if (is_system_loaded() != EFI_SUCCESS) return;
struct dirstuff* moduleDir = opendir("/Extra/modules/");
long ret, length, flags, time, bundleType;
long long index;
long result = -1;
const char * name;
void (*module_start)(void);
while(readdir(moduleDir, (const char**)&name, &flags, &time) >= 0)
{
if ((strcmp("Symbols.dylib",name)) == 0) continue; // if we found Symbols.dylib, just skip it
DBG("FileLoadBundles in %s\n",dirSpec);
index = 0;
while (1) {
ret = GetDirEntry("/Extra/modules/", &index, &name, &flags, &time);
if (ret == -1) break;
// Make sure this is not a directory.
if ((flags & kFileTypeMask) == kFileTypeDirectory) continue;
if ((strcmp("Symbols.dylib",name)) == 0) continue; // if we found Symbols.dylib, just skip it
if (is_dylib_loaded(name) == EFI_SUCCESS) continue;
// Make sure this is a kext.
length = strlen(name);
if (strcmp(name + length - 6, ".dylib")) continue;
int len = strlen(name);
int ext_size = sizeof("dylib");
if (len >= ext_size)
{
if(strcmp(&name[len - ext_size], ".dylib") == 0)
{
char *tmp = newStringWithFormat("/Extra/modules/%s",name);
if (!tmp) {
continue;
}
char *dylib_name = newString(name);
if (!dylib_name) {
free(tmp);
continue;
}
msglog("* Attempting to load module: %s\n", tmp);
module_start = (void*)load_module(dylib_name,tmp);
if(module_start && ( module_start != (void*)0xFFFFFFFF))
{
add_dylib(name);
module_start();
}
else
{
// failed to load or already loaded
free(tmp);
free(dylib_name);
}
}
#if DEBUG_MODULES
else
{
DBG("Ignoring %s\n", name);
}
#endif
}
#if DEBUG_MODULES
else
{
DBG("Ignoring %s\n", name);
}
#endif
}
char *tmp = newStringWithFormat( "/Extra/modules/%s",name);
if (!tmp) {
continue;
}
char *dylib_name = newString(name);
if (!dylib_name) {
free(tmp);
continue;
}
msglog("* Attempting to load module: %s\n", tmp);
module_start = (void*)load_module(dylib_name,tmp);
if(module_start && ( module_start != (void*)0xFFFFFFFF))
{
add_dylib(name);
module_start();
}
else
{
// failed to load or already loaded
free(tmp);
free(dylib_name);
}
}
if (moduleDir)
{
closedir(moduleDir);
}
#if DEBUG_MODULES
print_symbol_list();
#endif
char* binary = (char*)addr;
if(addr != 0xFFFFFFFF)
{
UInt32* jumpPointer = malloc(sizeof(UInt32*));
UInt32* jumpPointer = malloc(sizeof(UInt32));
if (!jumpPointer) {
return EFI_OUT_OF_RESOURCES;
}
long willLoad;
TagPtr dict;
TagPtr personalities;
//pool_t workspace;
char *plistAddr;
long plistLength;
char *executablePath;
ret = ParseXML(buffer, &module);
if (ret != 0 ) { printf("Unable to read plist of %s",name); break; }
if (!module) break; // Should never happen but it will make the compiler happy
if (!module) {ret = -1;break;} // Should never happen but it will make the compiler happy
// Allocate memory for the driver path and the plist.
branches/cparm/i386/libsaio/modules.h
5959
6060
6161
62
63
64
6562
6663
6764
#define SYS_CLASS "SYMS"
#define SYSLIB_CLASS "SYS_LIB"
#define BundleHighPriority "high"
#define BundleNormalPriority "normal"
#define BundleLowPriority "low"
/*
* Modules Interface
* execute_hook
branches/cparm/i386/libsaio/device_inject.c
129129
130130
131131
132
132
133133
134134
135135
......
148148
149149
150150
151
151
152152
153153
154154
......
189189
190190
191191
192
192
193193
194194
195195
196196
197197
198
198199
199
200
201
202
203
204
205
200
201
202
206203
207204
208205
......
297294
298295
299296
297
298
300299
301300
302
303
301
302
304303
305304
306
307
308
309
310
305
306
307
308
309
311310
312311
313
312
314313
315
316
317
318
319
314
315
316
317
318
320319
321320
322321
323
324
325
322
323
324
326325
327326
328
329
327
328
330329
331330
332331
......
344343
345344
346345
346
347
348
347349
348350
349
351
350352
351
353
352354
353
354
355
356
355357
356
357
358
359
358360
359361
360362
numpaths = 0;
break;
}
device->pci_dev_path[numpaths].device =ascii_hex_to_int(buff);
device->pci_dev_path[numpaths].device =(uint8_t)strtoul(buff, NULL, 16);
x += 3; // 0x
curr = x;
numpaths = 0;
break;
}
device->pci_dev_path[numpaths].function = ascii_hex_to_int(buff); // TODO: find dev from char *path
device->pci_dev_path[numpaths].function = (uint8_t)strtoul(buff, NULL, 16); // TODO: find dev from char *path
numpaths++;
}
if(!string->entries)
{
if((string->entries = (struct DevPropDevice**)malloc(sizeof(device)))== NULL)
if((string->entries = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice) * MAX_STRING_NUM_ENTRIES))== NULL)
{
free(device);
return NULL;
}
}
struct DevPropDevice **string_entries_arrey = (struct DevPropDevice **) string->entries;
if((string->entries[string->numentries++] = (struct DevPropDevice*)malloc(sizeof(device)))== NULL)
{
free(device);
free(string->entries);
return NULL;
}
string->entries[string->numentries-1] = device;
string->numentries++;
string_entries_arrey[string->numentries-1] = device;
return device;
}
buffer += 24;
int i = 0, x = 0;
struct DevPropDevice **string_entries_arrey = (struct DevPropDevice **) string->entries;
while(i < string->numentries)
{
sprintf(buffer, "%08x%04x%04x", dp_swap32(string->entries[i]->length),
dp_swap16(string->entries[i]->numentries), string->entries[i]->WHAT2);
sprintf(buffer, "%08x%04x%04x", dp_swap32(string_entries_arrey[i]->length),
dp_swap16(string_entries_arrey[i]->numentries), string_entries_arrey[i]->WHAT2);
buffer += 16;
sprintf(buffer, "%02x%02x%04x%08x%08x", string->entries[i]->acpi_dev_path.type,
string->entries[i]->acpi_dev_path.subtype,
dp_swap16(string->entries[i]->acpi_dev_path.length),
string->entries[i]->acpi_dev_path._HID,
dp_swap32(string->entries[i]->acpi_dev_path._UID));
sprintf(buffer, "%02x%02x%04x%08x%08x", string_entries_arrey[i]->acpi_dev_path.type,
string_entries_arrey[i]->acpi_dev_path.subtype,
dp_swap16(string_entries_arrey[i]->acpi_dev_path.length),
string_entries_arrey[i]->acpi_dev_path._HID,
dp_swap32(string_entries_arrey[i]->acpi_dev_path._UID));
buffer += 24;
for(x=0;x < string->entries[i]->num_pci_devpaths; x++)
for(x=0;x < string_entries_arrey[i]->num_pci_devpaths; x++)
{
sprintf(buffer, "%02x%02x%04x%02x%02x", string->entries[i]->pci_dev_path[x].type,
string->entries[i]->pci_dev_path[x].subtype,
dp_swap16(string->entries[i]->pci_dev_path[x].length),
string->entries[i]->pci_dev_path[x].function,
string->entries[i]->pci_dev_path[x].device);
sprintf(buffer, "%02x%02x%04x%02x%02x", string_entries_arrey[i]->pci_dev_path[x].type,
string_entries_arrey[i]->pci_dev_path[x].subtype,
dp_swap16(string_entries_arrey[i]->pci_dev_path[x].length),
string_entries_arrey[i]->pci_dev_path[x].function,
string_entries_arrey[i]->pci_dev_path[x].device);
buffer += 12;
}
sprintf(buffer, "%02x%02x%04x", string->entries[i]->path_end.type,
string->entries[i]->path_end.subtype,
dp_swap16(string->entries[i]->path_end.length));
sprintf(buffer, "%02x%02x%04x", string_entries_arrey[i]->path_end.type,
string_entries_arrey[i]->path_end.subtype,
dp_swap16(string_entries_arrey[i]->path_end.length));
buffer += 8;
uint8_t *dataptr = string->entries[i]->data;
for(x = 0; (uint32_t)x < (string->entries[i]->length) - (24 + (6 * string->entries[i]->num_pci_devpaths)) ; x++)
uint8_t *dataptr = string_entries_arrey[i]->data;
for(x = 0; (uint32_t)x < (string_entries_arrey[i]->length) - (24 + (6 * string_entries_arrey[i]->num_pci_devpaths)) ; x++)
{
sprintf(buffer, "%02x", *dataptr++);
buffer += 2;
}
int i;
struct DevPropDevice **string_entries_arrey = (struct DevPropDevice **) string->entries;
for(i = 0; i < string->numentries; i++)
{
if(string->entries[i])
if(string_entries_arrey[i])
{
if(string->entries[i]->data)
if(string_entries_arrey[i]->data)
{
free(string->entries[i]->data);
string->entries[i]->data = NULL;
free(string_entries_arrey[i]->data);
string_entries_arrey[i]->data = NULL;
}
free(string->entries[i]);
string->entries[i] = NULL;
free(string_entries_arrey[i]);
string_entries_arrey[i] = NULL;
}
}
branches/cparm/i386/libsaio/device_inject.h
1111
1212
1313
14
1415
1516
1617
......
6869
6970
7071
71
72
7273
7374
7475
#define DP_ADD_TEMP_VAL(dev, val) devprop_add_value(dev, (char*)val[0], (uint8_t*)val[1], strlen(val[1]) + 1)
#define DP_ADD_TEMP_VAL_DATA(dev, val) devprop_add_value(dev, (char*)val.name, (uint8_t*)val.data, val.size)
#define MAX_PCI_DEV_PATHS 4
#define MAX_STRING_NUM_ENTRIES 100
extern struct DevPropString *string;
extern uint8_t *stringdata;
uint32_t WHAT2;// 0x01000000 ?
uint16_t numentries;
uint16_t WHAT3;// 0x0000 ?
struct DevPropDevice **entries;
struct DevPropDevice *entries;
};
char*efi_inject_get_devprop_string(uint32_t *len);
branches/cparm/i386/libsaio/sys.c
110110
111111
112112
113
114
115
116
117
118
119113
120114
121
122115
123116
124117
......
135128
136129
137130
138
139
131
132
140133
141134
142135
......
162155
163156
164157
158
165159
166160
167161
......
175169
176170
177171
172
178173
179174
180175
......
194189
195190
196191
197
192
198193
199194
200195
......
318313
319314
320315
316
317
321318
322319
323320
......
367364
368365
369366
370
367
371368
372369
373370
......
408405
409406
410407
411
408
409
410
412411
413412
414413
......
531530
532531
533532
533
534534
535535
536536
......
582582
583583
584584
585
586585
587586
588587
......
635634
636635
637636
638
639637
640638
641639
......
651649
652650
653651
654
652
655653
656654
657655
......
689687
690688
691689
692
693690
694691
695692
......
760757
761758
762759
763
760
764761
765762
766763
......
769766
770767
771768
772
773
774769
775770
776771
......
782777
783778
784779
785
780
786781
787782
788783
789784
790785
791
786
787
792788
793789
794790
......
880876
881877
882878
883
879
884880
885881
886882
......
890886
891887
892888
893
889
894890
895891
896892
......
943939
944940
945941
946
942
947943
948944
949
950
945
946
947
951948
952949
953950
......
10751072
10761073
10771074
1078
1075
10791076
10801077
10811078
static struct iob iob[NFILES];
void * gFSLoadAddress = 0;
// Turbo - save what we think is our original BIOS boot volume if we have one 0xab
BVRef gBIOSBootVolume = NULL;
BVRef gBootVolume;
static BVRef newBootVolumeRef( int biosdev, int partno );
static int GetFreeFd(void);
static struct iob * iob_from_fdesc(int fdesc);
static int open_bvr(BVRef bvr, const char *filePath);
// Read file into load buffer. The data in the load buffer will be
// overwritten by the next LoadFile() call.
gFSLoadAddress = (void *) LOAD_ADDR;
safe_set_env(envgFSLoadAddress, (uint32_t)(void *)LOAD_ADDR);
fileSize = bvr->fs_loadfile(bvr, (char *)filePath);
// Return the size of the file, or -1 if load failed.
return LoadVolumeFile(bvr, filePath);
}
#if UNUSED
long ReadFileAtOffset(const char * fileSpec, void *buffer, uint64_t offset, uint64_t length)
{
const char *filePath;
return bvr->fs_readfile(bvr, (char *)filePath, buffer, offset, length);
}
#endif
long LoadThinFatFile(const char *fileSpec, void **binary)
{
// Read file into load buffer. The data in the load buffer will be
// overwritten by the next LoadFile() call.
gFSLoadAddress = (void *) LOAD_ADDR;
safe_set_env(envgFSLoadAddress, (uint32_t)(void *)LOAD_ADDR);
readFile = bvr->fs_readfile;
if (gMakeDirSpec == 0)
gMakeDirSpec = (char *)malloc(1024);
if (!gMakeDirSpec) return -1;
if (!dirSpec) {
long idx, len;
// Return a pointer to an allocated 'iob' based on the file descriptor
// provided. Returns NULL if the file descriptor given is invalid.
static struct iob * iob_from_fdesc(int fdesc)
struct iob * iob_from_fdesc(int fdesc)
{
register struct iob * io;
}
// Load entire file into memory. Unnecessary open() calls must be avoided.
gFSLoadAddress = io->i_buf;
//gFSLoadAddress = io->i_buf;
safe_set_env(envgFSLoadAddress, (uint32_t)(void *)io->i_buf);
io->i_filesize = bvr->fs_loadfile(bvr, (char *)filePath);
if (io->i_filesize < 0) {
close(fdesc);
return io->i_filesize;
}
#if UNUSED
//==========================================================================
struct dirstuff * opendir(const char * path)
0, 0);
}
#if UNUSED
long GetFSUUID(char *spec, char *uuidStr)
{
BVRef bvr;
return fdesc;
}
#endif
//==========================================================================
// lseek() - Reposition the byte offset of the file descriptor from the
// beginning of the file. Returns the relocated offset.
return offset;
}
#if UNUSED
//==========================================================================
// tell() - Returns the byte offset of the file descriptor.
return count;
}
#if UNUSED
int writebyte(int fdesc, char value)
{
struct iob * io;
const char * systemConfigDir()
{
if (gBootFileType == kNetworkDeviceType)
if (get_env(envgBootFileType) == kNetworkDeviceType)
return "";
return "/Library/Preferences/SystemConfiguration";
}
//==========================================================================
int gBootFileType;
void scanBootVolumes( int biosdev, int * count )
{
BVRef bvr = 0;
bvr = nbpScanBootVolumes(biosdev, count);
if (bvr != NULL)
{
gBootFileType = kNetworkDeviceType;
safe_set_env(envgBootFileType, kNetworkDeviceType);
}
#endif
}
else
{
gBootFileType = kBlockDeviceType;
safe_set_env(envgBootFileType, kBlockDeviceType);
}
}
// zhell -- Undo a regression that was introduced from r491 to 492.
// if gBIOSBootVolume is set already, no change is required
if ( (bvr->flags & (kBVFlagBootable|kBVFlagSystemVolume))
&& gBIOSBootVolume
&& get_env(envgBIOSBootVolume)
&& (!filteredChain || (filteredChain && bvr->visible))
&& (bvr->biosdev == gBIOSDev) )
{
// zhell -- if gBIOSBootVolume is NOT set, we use the "if" statement
// from r491,
if ( bvr->flags & kBVFlagBootable
&& ! gBIOSBootVolume
&& !get_env(envgBIOSBootVolume)/*gBIOSBootVolume*/
&& bvr->biosdev == gBIOSDev )
{
bvr2 = bvr;
void setBootGlobals(BVRef chain)
{
// Record default boot device.
gBootVolume = selectBootVolume(chain);
BVRef gBootVolume = selectBootVolume(chain);
// turbo - Save the ORIGINAL boot volume too for loading our mkext
if (!gBIOSBootVolume) gBIOSBootVolume = gBootVolume;
if (!get_env(envgBIOSBootVolume)) safe_set_env(envgBIOSBootVolume, (uint32_t)gBootVolume);
safe_set_env(envgBootVolume, (uint32_t)gBootVolume);
setRootVolume(gBootVolume);
}
if (biosdev == kPseudoBIOSDevBooter)
{
if (bvr1 == NULL )
bvr1 = gBIOSBootVolume;
bvr1 = (BVRef)(uint32_t)get_env(envgBIOSBootVolume);
}
else
{
branches/cparm/i386/libsaio/load.c
3131
3232
3333
34
3435
3536
3637
3738
39
3840
39
40
41
42
43
4441
4542
4643
......
8784
8885
8986
90
87
9188
9289
9390
......
111108
112109
113110
114
111
115112
116113
117114
......
276273
277274
278275
279
276
280277
281278
282279
......
294291
295292
296293
297
294
298295
299296
300297
#include <mach/machine/thread_status.h>
#include "sl.h"
#include "platform.h"
static long DecodeSegment(long cmdBase, unsigned int*load_addr, unsigned int *load_size);
static long DecodeUnixThread(long cmdBase, unsigned int *entry);
static long DecodeSymbolTable(long cmdBase);
static unsigned long gBinaryAddress;
unsigned long gBinaryAddress;
bool gHaveKernelCache;/* XXX aserebln: uninitialized? and only set to true, never to false */
cpu_type_t archCpuType=CPU_TYPE_I386;
// Public Functions
long ThinFatFile(void **binary, unsigned long *length)
fapsize = fap->size;
}
if (fapcputype == archCpuType)
if (fapcputype == get_env(envarchCpuType))
{
*binary = (void *) ((unsigned long)*binary + fapoffset);
size = fapsize;
{
struct mach_header *mH;
mH = (struct mach_header *)(gBinaryAddress);
switch (archCpuType)
switch (get_env(envarchCpuType))
{
case CPU_TYPE_I386:
if (mH->magic != MH_MAGIC)
}
if (vmsize && (strcmp(segname, "__PRELINK") == 0 || strcmp(segname, "__PRELINK_INFO") == 0))
gHaveKernelCache = true;
safe_set_env(envgHaveKernelCache, true);
// Copy from file load area.
if (vmsize>0 && filesize>0)
static long DecodeUnixThread(long cmdBase, unsigned int *entry)
{
switch (archCpuType)
switch (get_env(envarchCpuType))
{
case CPU_TYPE_I386:
{
branches/cparm/i386/libsaio/sl.h
6060
6161
6262
63
64
65
66
63
6764
6865
#define Seek(c, p) diskSeek(c, p);
#define Read(c, a, l) diskRead(c, a, l);
extern void * gFSLoadAddress;
extern cpu_type_t archCpuType;
extern unsigned long HFSLoadVerbose;
cpu_type_t detectCpuType ();
//extern void * gFSLoadAddress;
#endif /* !__LIBSAIO_SL_H */
branches/cparm/i386/libsaio/platform.c
2020
2121
2222
23
24
25
26
2327
2428
2529
......
96100
97101
98102
99
103
100104
101105
102106
......
164168
165169
166170
167
171
168172
169173
170174
......
320324
321325
322326
323
327
324328
325329
326330
......
345349
346350
347351
348
352
349353
350354
351355
......
363367
364368
365369
366
370
367371
368372
369373
......
384388
385389
386390
391
392
393
394
395
396
397
398
399
400
401
402
403
387404
388405
389406
390407
391408
392409
393
394410
395411
396412
397
398
413
414
399415
400
401
416
417
402418
403
404
405
406
407
419
420
421
422
423
408424
409
410
411
412
413
425
426
427
428
429
414430
415431
416
417
418
432
433
434
419435
420
436
421437
422438
423439
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
440
#define DBG(x...)
#endif
#ifndef DEBUG_PLATFORM_CPU
#define DEBUG_PLATFORM_CPU 0
#endif
static char *gboardproduct = NULL;
static char *gPlatformName = NULL;
static char *gRootDevice = NULL;
static struct env_struct *find_env(const char *name) {
struct env_struct *var;
if (setjmp(h_buf_error) == -1) {
if (setjmp(uterror) == -1) {
#if DEBUG_PLATFORM
printf("find_env: Unable to find environement variable\n");
getc();
return;
}
if (setjmp(h_buf_error) == -1) {
if (setjmp(uterror) == -1) {
printf("_set_env: Unable to set environement variable"); // don't try to acces to the string 'name',
//'cause we just returned from the longjump, stack as already changed state.
#if DEBUG_PLATFORM
static void delete_env(struct env_struct *var) {
if (setjmp(h_buf_error) == -1) {
if (setjmp(uterror) == -1) {
printf("delete_env: Unable to delete environement variable\n");
#if DEBUG_PLATFORM
getc();
void free_platform_env(void) {
struct env_struct *current_var, *tmp;
if (setjmp(h_buf_error) == -1) {
if (setjmp(uterror) == -1) {
printf("free_platform_env: Unable to delete all environement variables\n");
#if DEBUG_PLATFORM
getc();
#if DEBUG_PLATFORM
void debug_platform_env(void)
{
struct env_struct *current_var = platform_env;
struct env_struct *current_var;
for(current_var=platform_env;current_var;current_var=(struct env_struct*)(current_var->hh.next))
{
#if DEBUG_PLATFORM >= 2
}
#endif
void showError(void)
{
struct env_struct *current_var;
for(current_var=platform_env;current_var;current_var=(struct env_struct*)(current_var->hh.next))
{
if (strcmp(current_var->name, envConsoleErr) == 0) {
if (current_var->Type == kEnvPtr) {
printf("stderr: %s \n",(char*)(uint32_t)current_var->ptr);
}
}
}
}
/**
Scan platform hardware information, called by the main entry point (common_boot() )
_before_ bootConfig xml parsing settings are loaded
*/
void scan_platform(void)
{
//memset(&Platform, 0, sizeof(PlatformInfo_t));
build_pci_dt();
scan_cpu();
#if DEBUG_PLATFORM
DBG("CPU: %s\n", (char*)get_env_ptr(envBrandString));
#if DEBUG_PLATFORM_CPU
printf("CPU: %s\n", (char*)get_env_ptr(envBrandString));
if (get_env(envVendor) == CPUID_VENDOR_AMD)
DBG("CPU: Vendor/Model/ExtModel: 0x%x/0x%x/0x%x\n", (uint32_t)get_env(envVendor), (uint32_t)get_env(envModel), (uint32_t)get_env(envExtModel));
DBG("CPU: Family/ExtFamily: 0x%x/0x%x\n", (uint32_t)get_env(envFamily), (uint32_t)get_env(envExtFamily));
printf("CPU: Vendor/Model/ExtModel: 0x%x/0x%x/0x%x\n", (uint32_t)get_env(envVendor), (uint32_t)get_env(envModel), (uint32_t)get_env(envExtModel));
printf("CPU: Family/ExtFamily: 0x%x/0x%x\n", (uint32_t)get_env(envFamily), (uint32_t)get_env(envExtFamily));
if (get_env(envVendor) == CPUID_VENDOR_AMD) {
DBG("CPU (AMD): TSCFreq: %dMHz\n", (uint32_t)(get_env(envTSCFreq) / 1000000));
DBG("CPU (AMD): FSBFreq: %dMHz\n", (uint32_t)(get_env(envFSBFreq) / 1000000));
DBG("CPU (AMD): CPUFreq: %dMHz\n", (uint32_t)(get_env(envCPUFreq) / 1000000));
DBG("CPU (AMD): MaxCoef/CurrCoef: 0x%x/0x%x\n", (uint32_t)get_env(envMaxCoef), (uint32_t)get_env(envCurrCoef));
DBG("CPU (AMD): MaxDiv/CurrDiv: 0x%x/0x%x\n", (uint32_t)get_env(envMaxDiv), (uint32_t)get_env(envCurrDiv));
printf("CPU (AMD): TSCFreq: %dMHz\n", (uint32_t)(get_env(envTSCFreq) / 1000000));
printf("CPU (AMD): FSBFreq: %dMHz\n", (uint32_t)(get_env(envFSBFreq) / 1000000));
printf("CPU (AMD): CPUFreq: %dMHz\n", (uint32_t)(get_env(envCPUFreq) / 1000000));
printf("CPU (AMD): MaxCoef/CurrCoef: 0x%x/0x%x\n", (uint32_t)get_env(envMaxCoef), (uint32_t)get_env(envCurrCoef));
printf("CPU (AMD): MaxDiv/CurrDiv: 0x%x/0x%x\n", (uint32_t)get_env(envMaxDiv), (uint32_t)get_env(envCurrDiv));
} else if (get_env(envVendor) == CPUID_VENDOR_INTEL){
DBG("CPU: TSCFreq: %dMHz\n", (uint32_t)(get_env(envTSCFreq) / 1000000));
DBG("CPU: FSBFreq: %dMHz\n", (uint32_t)(get_env(envFSBFreq) / 1000000));
DBG("CPU: CPUFreq: %dMHz\n", (uint32_t)(get_env(envCPUFreq) / 1000000));
DBG("CPU: MaxCoef/CurrCoef: 0x%x/0x%x\n", (uint32_t)(get_env(envMaxCoef)), (uint32_t)(get_env(envCurrCoef)));
DBG("CPU: MaxDiv/CurrDiv: 0x%x/0x%x\n", (uint32_t)(get_env(envMaxDiv)), (uint32_t)(get_env(envCurrDiv)));
printf("CPU: TSCFreq: %dMHz\n", (uint32_t)(get_env(envTSCFreq) / 1000000));
printf("CPU: FSBFreq: %dMHz\n", (uint32_t)(get_env(envFSBFreq) / 1000000));
printf("CPU: CPUFreq: %dMHz\n", (uint32_t)(get_env(envCPUFreq) / 1000000));
printf("CPU: MaxCoef/CurrCoef: 0x%x/0x%x\n", (uint32_t)(get_env(envMaxCoef)), (uint32_t)(get_env(envCurrCoef)));
printf("CPU: MaxDiv/CurrDiv: 0x%x/0x%x\n", (uint32_t)(get_env(envMaxDiv)), (uint32_t)(get_env(envCurrDiv)));
}
DBG("CPU: NoCores/NoThreads: %d/%d\n", (uint32_t)(get_env(envNoCores)), (uint32_t)(get_env(envNoThreads)));
DBG("CPU: Features: 0x%08x\n", (uint32_t)(get_env(envFeatures)));
DBG("CPU: ExtFeatures: 0x%08x\n", (uint32_t)(get_env(envExtFeatures)));
printf("CPU: NoCores/NoThreads: %d/%d\n", (uint32_t)(get_env(envNoCores)), (uint32_t)(get_env(envNoThreads)));
printf("CPU: Features: 0x%08x\n", (uint32_t)(get_env(envFeatures)));
printf("CPU: ExtFeatures: 0x%08x\n", (uint32_t)(get_env(envExtFeatures)));
#ifndef AMD_SUPPORT
DBG("CPU: MicrocodeVersion: %d\n", (uint32_t)(get_env(envMicrocodeVersion)));
printf("CPU: MicrocodeVersion: %d\n", (uint32_t)(get_env(envMicrocodeVersion)));
#endif
pause();
#endif
}
#ifdef ShowCurrentDate
// shamefully ripped to http://wiki.osdev.org/CMOS
/*
* http://wiki.osdev.org/OSDev_Wiki:General_disclaimer
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#define CURRENT_YEAR 2012 // Change this each year!
static int century_register = 0x00; // Set by ACPI table parsing code if possible(... in FADT table)
enum {
cmos_address = 0x70,
cmos_data = 0x71
};
static int get_update_in_progress_flag() {
outb(cmos_address, 0x0A);
return (inb(cmos_data) & 0x80);
}
static unsigned char get_RTC_register(int reg) {
outb(cmos_address, reg);
return inb(cmos_data);
}
static void read_rtc(EFI_TIME *time) {
unsigned char century;
unsigned char last_second;
unsigned char last_minute;
unsigned char last_hour;
unsigned char last_day;
unsigned char last_month;
unsigned char last_year;
unsigned char last_century;
unsigned char registerB;
unsigned char second;
unsigned char minute;
unsigned char hour;
unsigned char day;
unsigned char month;
unsigned int year;
// Note: This uses the "read registers until you get the same values twice in a row" technique
// to avoid getting dodgy/inconsistent values due to RTC updates
while (get_update_in_progress_flag()); // Make sure an update isn't in progress
second = get_RTC_register(0x00);
minute = get_RTC_register(0x02);
hour = get_RTC_register(0x04);
day = get_RTC_register(0x07);
month = get_RTC_register(0x08);
year = get_RTC_register(0x09);
if(century_register != 0) {
century = get_RTC_register(century_register);
}
do {
last_second = second;
last_minute = minute;
last_hour = hour;
last_day = day;
last_month = month;
last_year = year;
last_century = century;
while (get_update_in_progress_flag()); // Make sure an update isn't in progress
second = get_RTC_register(0x00);
minute = get_RTC_register(0x02);
hour = get_RTC_register(0x04);
day = get_RTC_register(0x07);
month = get_RTC_register(0x08);
year = get_RTC_register(0x09);
if(century_register != 0) {
century = get_RTC_register(century_register);
}
} while( (last_second == second) && (last_minute == minute) && (last_hour == hour) &&
(last_day == day) && (last_month == month) && (last_year == year) &&
(last_century == century) );
registerB = get_RTC_register(0x0B);
// Convert BCD to binary values if necessary
if (!(registerB & 0x04)) {
second = (second & 0x0F) + ((second / 16) * 10);
minute = (minute & 0x0F) + ((minute / 16) * 10);
hour = ( (hour & 0x0F) + (((hour & 0x70) / 16) * 10) ) | (hour & 0x80);
day = (day & 0x0F) + ((day / 16) * 10);
month = (month & 0x0F) + ((month / 16) * 10);
year = (year & 0x0F) + ((year / 16) * 10);
if(century_register != 0) {
century = (century & 0x0F) + ((century / 16) * 10);
}
}
// Calculate the full (4-digit) year
if(century_register != 0) {
year += century * 100;
} else {
//year += (CURRENT_YEAR / 100) * 100;
//if(year < CURRENT_YEAR) year += 100;
if ((year += 1900) < 1970)
year += 100;
}
time->Second = second;
time->Minute = minute;
time->Hour = hour;
time->Day = day;
time->Month = month;
time->Year = year;
}
void rtc_time(EFI_TIME *time) {
read_rtc(time);
time->TimeZone = EFI_UNSPECIFIED_TIMEZONE;
return ;
}
char * Date(void)
{
EFI_TIME rtctime;
rtc_time(&rtctime);
return newStringWithFormat("%02d/%02d/%04d %02d:%02d:%02d",rtctime.Month,rtctime.Day,rtctime.Year,
rtctime.Hour,rtctime.Minute,rtctime.Second);
}
#endif
}
branches/cparm/i386/libsaio/cpu.c
4444
4545
4646
47
4847
48
4949
5050
5151
......
7474
7575
7676
77
77
78
7879
7980
8081
......
171172
172173
173174
175
174176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
175312
176313
177314
......
658795
659796
660797
661
798
662799
663800
664801
#if LEGACY_CPU
static uint64_t measure_tsc_frequency(void);
// DFE: enable_PIT2 and disable_PIT2 come from older xnu
/*
" outb %%al,$0x61 \n\t"
: : : "%al" );
}
#if 0
static uint64_t measure_tsc_frequency(void);
// DFE: set_PIT2_mode0, poll_PIT2_gate, and measure_tsc_frequency are
// roughly based on Linux code
disable_PIT2();
return retval;
}
#endif
static inline static void
set_PIT2(int value)
{
/*
* First, tell the clock we are going to write 16 bits to the counter
* and enable one-shot mode (command 0xB8 to port 0x43)
* Then write the two bytes into the PIT2 clock register (port 0x42).
* Loop until the value is "realized" in the clock,
* this happens on the next tick.
*/
asm volatile(
" movb $0xB8,%%al \n\t"
" outb %%al,$0x43 \n\t"
" movb %%dl,%%al \n\t"
" outb %%al,$0x42 \n\t"
" movb %%dh,%%al \n\t"
" outb %%al,$0x42 \n"
"1: inb $0x42,%%al \n\t"
" inb $0x42,%%al \n\t"
" cmp %%al,%%dh \n\t"
" jne 1b"
: : "d"(value) : "%al");
}
static inline static uint64_t
get_PIT2(unsigned int *value)
{
register uint64_t result;
/*
* This routine first latches the time (command 0x80 to port 0x43),
* then gets the time stamp so we know how long the read will take later.
* Read (from port 0x42) and return the current value of the timer.
*/
#ifdef __i386__
asm volatile(
" xorl %%ecx,%%ecx \n\t"
" movb $0x80,%%al \n\t"
" outb %%al,$0x43 \n\t"
" rdtsc \n\t"
" pushl %%eax \n\t"
" inb $0x42,%%al \n\t"
" movb %%al,%%cl \n\t"
" inb $0x42,%%al \n\t"
" movb %%al,%%ch \n\t"
" popl %%eax "
: "=A"(result), "=c"(*value));
#else /* __x86_64__ */
asm volatile(
" xorq %%rcx,%%rcx \n\t"
" movb $0x80,%%al \n\t"
" outb %%al,$0x43 \n\t"
" rdtsc \n\t"
" pushq %%rax \n\t"
" inb $0x42,%%al \n\t"
" movb %%al,%%cl \n\t"
" inb $0x42,%%al \n\t"
" movb %%al,%%ch \n\t"
" popq %%rax "
: "=A"(result), "=c"(*value));
#endif
return result;
}
/*
* timeRDTSC()
* This routine sets up PIT counter 2 to count down 1/20 of a second.
* It pauses until the value is latched in the counter
* and then reads the time stamp counter to return to the caller.
*/
static uint64_t timeRDTSC(void)
{
intattempts = 0;
uint64_t latchTime;
uint64_tsaveTime,intermediate;
unsigned int timerValue, lastValue;
//boolean_tint_enabled;
/*
* Table of correction factors to account for
* - timer counter quantization errors, and
* - undercounts 0..5
*/
#define SAMPLE_CLKS_EXACT(((double) CLKNUM) / 20.0)
#define SAMPLE_CLKS_INT((int) CLKNUM / 20)
#define SAMPLE_NSECS(2000000000LL)
#define SAMPLE_MULTIPLIER(((double)SAMPLE_NSECS)*SAMPLE_CLKS_EXACT)
#define ROUND64(x)((uint64_t)((x) + 0.5))
uint64_tscale[6] = {
ROUND64(SAMPLE_MULTIPLIER/(double)(SAMPLE_CLKS_INT-0)),
ROUND64(SAMPLE_MULTIPLIER/(double)(SAMPLE_CLKS_INT-1)),
ROUND64(SAMPLE_MULTIPLIER/(double)(SAMPLE_CLKS_INT-2)),
ROUND64(SAMPLE_MULTIPLIER/(double)(SAMPLE_CLKS_INT-3)),
ROUND64(SAMPLE_MULTIPLIER/(double)(SAMPLE_CLKS_INT-4)),
ROUND64(SAMPLE_MULTIPLIER/(double)(SAMPLE_CLKS_INT-5))
};
restart:
if (attempts >= 9) // increase to up to 9 attempts.
// This will flash-reboot. TODO: Use tscPanic instead.
printf("Timestamp counter calibation failed with %d attempts\n", attempts);
attempts++;
enable_PIT2();// turn on PIT2
set_PIT2(0);// reset timer 2 to be zero
latchTime = rdtsc64();// get the time stamp to time
latchTime = get_PIT2(&timerValue) - latchTime; // time how long this takes
set_PIT2(SAMPLE_CLKS_INT);// set up the timer for (almost) 1/20th a second
saveTime = rdtsc64();// now time how long a 20th a second is...
get_PIT2(&lastValue);
get_PIT2(&lastValue);// read twice, first value may be unreliable
do {
intermediate = get_PIT2(&timerValue);
if (timerValue > lastValue) {
// Timer wrapped
set_PIT2(0);
disable_PIT2();
goto restart;
}
lastValue = timerValue;
} while (timerValue > 5);
printf("timerValue %d\n",timerValue);
printf("intermediate 0x%016llx\n",intermediate);
printf("saveTime 0x%016llx\n",saveTime);
intermediate -= saveTime;// raw count for about 1/20 second
intermediate *= scale[timerValue];// rescale measured time spent
intermediate /= SAMPLE_NSECS;// so its exactly 1/20 a second
intermediate += latchTime;// add on our save fudge
set_PIT2(0);// reset timer 2 to be zero
disable_PIT2();// turn off PIT 2
return intermediate;
}
#ifdef AMD_SUPPORT
#define MSR_AMD_APERF 0x000000E8
/*
FSBFreq = (uint64_t)(compute_bclk() * 1000000);
#if LEGACY_CPU
TSCFreq = measure_tsc_frequency();
TSCFreq = timeRDTSC() * 20/*measure_tsc_frequency()*/;
#endif
#ifdef AMD_SUPPORT
branches/cparm/i386/libsaio/rtc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* http://wiki.osdev.org/OSDev_Wiki:General_disclaimer
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "libsaio.h"
#define CURRENT_YEAR 2012 // Change this each year!
static int century_register = 0x00; // Set by ACPI table parsing code if possible(... in FADT table)
enum {
cmos_address = 0x70,
cmos_data = 0x71
};
static int get_update_in_progress_flag() {
outb(cmos_address, 0x0A);
return (inb(cmos_data) & 0x80);
}
static unsigned char get_RTC_register(int reg) {
outb(cmos_address, reg);
return inb(cmos_data);
}
void rtc_read_clock(struct tm *time) {
unsigned char century = 0;
unsigned char last_second;
unsigned char last_minute;
unsigned char last_hour;
unsigned char last_day;
unsigned char last_month;
unsigned char last_year;
unsigned char last_century;
unsigned char registerB;
unsigned char second;
unsigned char minute;
unsigned char hour;
unsigned char day;
unsigned char month;
unsigned int year;
// Note: This uses the "read registers until you get the same values twice in a row" technique
// to avoid getting dodgy/inconsistent values due to RTC updates
while (get_update_in_progress_flag()); // Make sure an update isn't in progress
second = get_RTC_register(0x00);
minute = get_RTC_register(0x02);
hour = get_RTC_register(0x04);
day = get_RTC_register(0x07);
month = get_RTC_register(0x08);
year = get_RTC_register(0x09);
if(century_register != 0) {
century = get_RTC_register(century_register);
}
do {
last_second = second;
last_minute = minute;
last_hour = hour;
last_day = day;
last_month = month;
last_year = year;
last_century = century;
while (get_update_in_progress_flag()); // Make sure an update isn't in progress
second = get_RTC_register(0x00);
minute = get_RTC_register(0x02);
hour = get_RTC_register(0x04);
day = get_RTC_register(0x07);
month = get_RTC_register(0x08);
year = get_RTC_register(0x09);
if(century_register != 0) {
century = get_RTC_register(century_register);
}
} while( (last_second == second) && (last_minute == minute) && (last_hour == hour) &&
(last_day == day) && (last_month == month) && (last_year == year) &&
(last_century == century) );
registerB = get_RTC_register(0x0B);
// Convert BCD to binary values if necessary
if (!(registerB & 0x04)) {
second = (second & 0x0F) + ((second / 16) * 10);
minute = (minute & 0x0F) + ((minute / 16) * 10);
hour = ( (hour & 0x0F) + (((hour & 0x70) / 16) * 10) ) | (hour & 0x80);
day = (day & 0x0F) + ((day / 16) * 10);
month = (month & 0x0F) + ((month / 16) * 10);
year = (year & 0x0F) + ((year / 16) * 10);
if(century_register != 0) {
century = (century & 0x0F) + ((century / 16) * 10);
}
}
// Calculate the full (4-digit) year
if(century_register != 0) {
year += century * 100;
} else {
//year += (CURRENT_YEAR / 100) * 100;
//if(year < CURRENT_YEAR) year += 100;
if ((year += 1900) < 1970)
year += 100;
}
time->tm_sec = second;
time->tm_min = minute;
time->tm_hour = hour;
time->tm_mday = day;
time->tm_mon = month;
time->tm_year = year;
}
branches/cparm/i386/libsaio/platform.h
119119
120120
121121
122
122123
124
123125
124
126
125127
126128
127129
......
132134
133135
134136
137
135138
136139
137140
......
152155
153156
154157
158
159
160
161
162
163
164
165
155166
156167
157168
158169
170
159171
160
161172
162173
163174
#define envSysId "boot.hw.sysid"
#define envgBIOSDev "boot.hw.bios_device"
#define envgDeviceCount "boot.hw.device_count"
#define envarchCpuType"boot.hw.cputype"
#define envgHaveKernelCache"boot.kern.HaveKernelCache"
#define envAdler32"boot.kern.adler32"
#define envkCache "boot.kern.kernelcache"
#define envkCacheFile "boot.kern.kernelcache"
#define envMKextName "boot.kern.mkextcache"
#define envArgCntRemaining "boot.kern.argCount_remaining"
#define envgBootArgs"boot.kern.boot_args"
#define envgEnableCDROMRescan "boot.options.rescan_cdrom"
#define envgScanSingleDrive "boot.options.single_drive"
#define envShouldboot "boot.options.should_boot"
#define envgVerboseMode "boot.options.boot_verbose"
#define envDriverExtSpec "boot.drivers.extspec"
#define envDriverSpec "boot.drivers.spec"
#define envgMenuStart "boot.ui.menu_start"
#define envgMenuEnd "boot.ui.menu_end"
#define envConsoleErr"boot.console.stderr"
#define envgBootFileType"boot.disk.Bootfiletype"
#define envHFSLoadVerbose"boot.disk.HFSLoadVerbose"
#define envgFSLoadAddress"boot.disk.FSLoadAddress"
#define envgBIOSBootVolume"boot.disk.BIOSBootVolume"
#define envgBootVolume"boot.disk.BootVolume"
#define envConvMem "boot.memmap.Conventional"
#define envExtMem "boot.memmap.Extended"
#define envMemoryMap "boot.memmap.Address"
#define envMemoryMapCnt "boot.memmap.Count"
#define envMemoryMapNode "boot.memmap.devNode"
#define envRamFrequency "boot.ram.frequency"
#define envRamCas "boot.ram.tCAS"
#define envRamTrc "boot.ram.tRCD"
branches/cparm/i386/libsaio/disk.c
887887
888888
889889
890
890
891
891892
892893
893894
......
900901
901902
902903
903
904
904905
905906
906907
......
15111512
15121513
15131514
1514
1515
1516
15151517
15161518
15171519
// turbo - we want the booter type scanned also
case FDISK_BOOTER:
if (part->bootid & FDISK_ACTIVE) {
gBIOSBootVolume = newFDiskBVRef(
/*gBIOSBootVolume =*/
safe_set_env(envgBIOSBootVolume, (uint32_t)newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
HFSGetDescription,
HFSFree,
0,
kBIOSDevTypeHardDrive, 0);
kBIOSDevTypeHardDrive, 0));
break;
}
#ifndef UFS_SUPPORT
#endif
default:
if (biosdev == (int)get_env(envgBIOSDev))
gBIOSBootVolume = bvr;
//gBIOSBootVolume = bvr;
safe_set_env(envgBIOSBootVolume, (uint32_t)bvr);
break;
}
}
branches/cparm/i386/libsaio/CoreHash.h
2222
2323
2424
25
25
2626
2727
2828
......
4747
4848
4949
50
50
5151
5252
5353
......
8181
8282
8383
84
84
8585
8686
8787
......
104104
105105
106106
107
107
108108
109109
110110
......
123123
124124
125125
126
126
127127
128128
129129
......
157157
158158
159159
160
160
161161
162162
163163
......
194194
195195
196196
197
197
198198
199199
200200
static struct HObj * HObj##_FindStrVar(const char *name, struct HObj *container) { \
struct HObj *var; \
\
if (setjmp(h_buf_error) == -1) { \
if (setjmp(uterror) == -1) { \
\
return NULL; \
} else { \
return NULL; \
} \
\
if (setjmp(h_buf_error) == -1) { \
if (setjmp(uterror) == -1) { \
\
free(var); \
return NULL; \
return; \
} \
\
if (setjmp(h_buf_error) == -1) { \
if (setjmp(uterror) == -1) { \
return; \
} else { \
HASH_DEL( container, var); \
static struct HObj * HObj##_FindIntVar(int id, struct HObj *container) {\
struct HObj *var; \
\
if (setjmp(h_buf_error) == -1) { \
if (setjmp(uterror) == -1) { \
\
return NULL; \
} else { \
\
var->id = id;\
\
if (setjmp(h_buf_error) == -1) { \
if (setjmp(uterror) == -1) { \
\
free(var); \
return NULL; \
return;\
}\
\
if (setjmp(h_buf_error) == -1) {\
if (setjmp(uterror) == -1) {\
return;\
} else {\
HASH_DEL( container, var);\
static void HObj##_DeleteAll(struct HObj *container ) { \
struct HObj *current_var, *tmp; \
\
if (setjmp(h_buf_error) == -1) { \
if (setjmp(uterror) == -1) { \
return;\
} else { \
HASH_ITER(hh, container, current_var, tmp) { \
branches/cparm/i386/libsaio/uthash.h
11
2
2
33
44
55
......
5454
5555
5656
57
57
5858
59
59
60
61
62
6063
64
65
6166
62
67
68
6369
70
71
6472
73
6574
6675
6776
......
94103
95104
96105
97
106
98107
99108
100109
101110
102
111
103112
104113
105114
......
144153
145154
146155
147
156
148157
149158
150159
......
237246
238247
239248
240
249
241250
242251
243252
......
345354
346355
347356
348
357
349358
350359
351360
......
382391
383392
384393
385
394
386395
387396
388397
......
470479
471480
472481
473
482
474483
475484
476485
......
555564
556565
557566
558
559
560
561
562
563
564
565
566
567
568
567
568
569
570
571
572
573
574
575
576
577
569578
570579
571580
/*
Copyright (c) 2003-2011, Troy D. Hanson http://uthash.sourceforge.net
Copyright (c) 2003-2012, Troy D. Hanson http://uthash.sourceforge.net
All rights reserved.
Redistribution and use in source and binary forms, with or without
} while(0)
#endif
#define UTHASH_VERSION 1.9.4
#define UTHASH_VERSION 1.9.6
#define uthash_fatal(msg) longjmp(h_buf_error,-1) /* fatal error (out of memory,etc) */
#ifndef uthash_fatal
#define uthash_fatal(msg) longjmp(uterror,-1) /* fatal error (out of memory,etc) */
#endif
#ifndef uthash_malloc
#define uthash_malloc(sz) malloc(sz) /* malloc fcn */
#endif
#ifndef uthash_free
#define uthash_free(ptr,sz) free(ptr) /* free fcn */
#endif
#ifndef uthash_noexpand_fyi
#define uthash_noexpand_fyi(tbl) /* can be defined to log noexpand */
#endif
#ifndef uthash_expand_fyi
#define uthash_expand_fyi(tbl) /* can be defined to log expands */
#endif
/* initial number of buckets */
#define HASH_INITIAL_NUM_BUCKETS 32 /* initial number of buckets */
if (!((tbl)->bloom_bv)) { uthash_fatal( "out of memory"); } \
memset((tbl)->bloom_bv, 0, HASH_BLOOM_BYTELEN); \
(tbl)->bloom_sig = HASH_BLOOM_SIGNATURE; \
} while (0);
} while (0)
#define HASH_BLOOM_FREE(tbl) \
do { \
uthash_free((tbl)->bloom_bv, HASH_BLOOM_BYTELEN); \
} while (0);
} while (0)
#define HASH_BLOOM_BITSET(bv,idx) (bv[(idx)/8] |= (1U << ((idx)%8)))
#define HASH_BLOOM_BITTEST(bv,idx) (bv[(idx)/8] & (1U << ((idx)%8)))
unsigned _ha_bkt; \
(add)->hh.next = NULL; \
(add)->hh.key = (char*)keyptr; \
(add)->hh.keylen = keylen_in; \
(add)->hh.keylen = (unsigned)keylen_in; \
if (!(head)) { \
head = (add); \
(head)->hh.prev = NULL; \
* This is for uthash developer only; it compiles away if HASH_DEBUG isn't defined.
*/
#ifdef HASH_DEBUG
#define HASH_OOPS(...) do { fprintf(stderr,__VA_ARGS__); longjmp(h_buf_error,-1); } while (0)
#define HASH_OOPS(...) do { printf("%s\n"__VA_ARGS__); longjmp(THIS_BUF_ERROR,-1); } while (0)
#define HASH_FSCK(hh,head) \
do { \
unsigned _bkt_i; \
for(_fn_i=0; _fn_i < keylen; _fn_i++) \
hashv = (hashv * 16777619) ^ _hf_key[_fn_i]; \
bkt = hashv & (num_bkts-1); \
} while(0);
} while(0)
#define HASH_OAT(key,keylen,num_bkts,hashv,bkt) \
do { \
char *_hj_key=(char*)(key); \
hashv = 0xfeedbeef; \
_hj_i = _hj_j = 0x9e3779b9; \
_hj_k = keylen; \
_hj_k = (unsigned)keylen; \
while (_hj_k >= 12) { \
_hj_i += (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 ) \
+ ( (unsigned)_hj_key[2] << 16 ) \
hashv ^= hashv << 25; \
hashv += hashv >> 6; \
bkt = hashv & (num_bkts-1); \
} while(0);
} while(0)
#ifdef HASH_USING_NO_STRICT_ALIASING
/* The MurmurHash exploits some CPU's (x86,x86_64) tolerance for unaligned reads.
#define HASH_KEYCMP(a,b,len) memcmp(a,b,len)
/* iterate over items in a known bucket to find desired item */
#define HASH_FIND_IN_BKT(tbl,hh,head,keyptr,keylen_in,out) \
do { \
if (head.hh_head) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,head.hh_head)); \
else out=NULL; \
while (out) { \
if (out->hh.keylen == keylen_in) { \
if ((HASH_KEYCMP(out->hh.key,keyptr,keylen_in)) == 0) break; \
} \
if (out->hh.hh_next) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,out->hh.hh_next)); \
else out = NULL; \
} \
#define HASH_FIND_IN_BKT(tbl,hh,head,keyptr,keylen_in,out) \
do { \
if (head.hh_head) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,head.hh_head)); \
else out=NULL; \
while (out) { \
if ((out)->hh.keylen == keylen_in) { \
if ((HASH_KEYCMP((out)->hh.key,keyptr,keylen_in)) == 0) break; \
} \
if ((out)->hh.hh_next) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,(out)->hh.hh_next)); \
else out = NULL; \
} \
} while(0)
/* add an item to a bucket */
branches/cparm/i386/libsaio/lib.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* This file is part of the libpayload project.
*
* Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "libsaio.h"
/*
* Convert a number in BCD format to decimal.
*
* @param b The BCD number.
* @return The given BCD number in decimal format.
*/
int bcd2dec(int b)
{
return ((b >> 4) & 0x0f) * 10 + (b & 0x0f);
}
/*
* Convert a number in decimal format into the BCD format.
*
* @param d The decimal number.
* @return The given decimal number in BCD format.
*/
int dec2bcd(int d)
{
return ((d / 10) << 4) | (d % 10);
}
#if UNUSED
/**
* Return the absolute value of the specified integer.
*
* @param j The integer of which we want to know the absolute value.
* @return The absolute value of the specified integer.
*/
int abs(int j)
{
return (j >= 0 ? j : -j);
}
long int labs(long int j)
{
return (j >= 0 ? j : -j);
}
long long int llabs(long long int j)
{
return (j >= 0 ? j : -j);
}
/**
* Given a 4-bit value, return the ASCII hex representation of it.
*
* @param b A 4-bit value which shall be converted to ASCII hex.
* @return The ASCII hex representation of the specified 4-bit value.
* Returned hex-characters will always be lower-case (a-f, not A-F).
*/
u8 bin2hex(u8 b)
{
return (b < 10) ? '0' + b : 'a' + (b - 10);
}
/**
* Given an ASCII hex input character, return its integer value.
*
* For example, the input value '6' will be converted to 6, 'a'/'A' will
* be converted to 10, 'f'/'F' will be converted to 15, and so on.
*
* The return value for invalid input characters is 0.
*
* @param h The input byte in ASCII hex format.
* @return The integer value of the specified ASCII hex byte.
*/
u8 hex2bin(u8 h)
{
return (('0' <= h && h <= '9') ? (h - '0') : \
('A' <= h && h <= 'F') ? (h - 'A' + 10) : \
('a' <= h && h <= 'f') ? (h - 'a' + 10) : 0);
}
#endif
branches/cparm/i386/libsaio/arc4random-fbsd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
* Copyright (c) 2008, Damien Miller <djm@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Arc4 random number generator for OpenBSD.
*
* This code is derived from section 17.1 of Applied Cryptography,
* second edition, which describes a stream cipher allegedly
* compatible with RSA Labs "RC4" cipher (the actual description of
* which is a trade secret). The same algorithm is used as a stream
* cipher called "arcfour" in Tatu Ylonen's ssh package.
*
* Here the stream cipher has been modified always to include the time
* when initializing the state. That makes it impossible to
* regenerate the same random sequence twice, so this can't be used
* for encryption, but will generate good random numbers.
*
* RC4 is a registered trademark of RSA Laboratories.
*/
#include "libsaio.h"
struct arc4_stream {
u_int8_t i;
u_int8_t j;
u_int8_t s[256];
};
#define KEYSIZE128
static struct arc4_stream rs = {
.i = 0,
.j = 0,
.s = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
}
};
//static int rs_initialized;
static int rs_stired;
static int arc4_count;
static inline u_int8_t arc4_getbyte(void);
static void arc4_stir(void);
static struct {
struct timevaltv;
u_int8_trnd[KEYSIZE];
} rdat;
static volatile int rs_data_available = 0;
static inline void
arc4_addrandom(u_char *dat, int datlen)
{
int n;
u_int8_t si;
rs.i--;
for (n = 0; n < 256; n++) {
rs.i = (rs.i + 1);
si = rs.s[rs.i];
rs.j = (rs.j + si + dat[n % datlen]);
rs.s[rs.i] = rs.s[rs.j];
rs.s[rs.j] = si;
}
rs.j = rs.i;
}
static void
arc4_fetch(void)
{
(void)gettimeofday(&rdat.tv, NULL);
}
static void
arc4_stir(void)
{
int n;
/*
* If we don't have data, we need some now before we can integrate
* it into the static buffers
*/
if (!rs_data_available)
{
arc4_fetch();
}
rs_data_available = 0;
__sync_synchronize();
arc4_addrandom((u_char *)&rdat, KEYSIZE);
/*
* Throw away the first N bytes of output, as suggested in the
* paper "Weaknesses in the Key Scheduling Algorithm of RC4"
* by Fluher, Mantin, and Shamir. N=1024 is based on
* suggestions in the paper "(Not So) Random Shuffles of RC4"
* by Ilya Mironov.
*/
for (n = 0; n < 1024; n++)
(void) arc4_getbyte();
arc4_count = 1600000;
rs_stired = 1;
}
static inline u_int8_t
arc4_getbyte(void)
{
u_int8_t si, sj;
rs.i = (rs.i + 1);
si = rs.s[rs.i];
rs.j = (rs.j + si);
sj = rs.s[rs.j];
rs.s[rs.i] = sj;
rs.s[rs.j] = si;
return (rs.s[(si + sj) & 0xff]);
}
static inline u_int32_t
arc4_getword(void)
{
u_int32_t val;
val = arc4_getbyte() << 24;
val |= arc4_getbyte() << 16;
val |= arc4_getbyte() << 8;
val |= arc4_getbyte();
return (val);
}
/* 7944700: force restir in child */
__private_extern__ void
_arc4_fork_child(void)
{
rs_stired = 0;
rs_data_available = 0;
}
static inline int
arc4_check_stir(void)
{
if (!rs_stired || arc4_count <= 0) {
arc4_stir();
return 1;
}
return 0;
}
void
arc4random_stir(void)
{
arc4_stir();
}
void
arc4random_addrandom(u_char *dat, int datlen)
{
arc4_check_stir();
arc4_addrandom(dat, datlen);
}
u_int32_t
arc4random(void)
{
u_int32_t rnd;
int did_stir = arc4_check_stir();
rnd = arc4_getword();
arc4_count -= 4;
if (did_stir)
{
/* stirring used up our data pool, we need to read in new data outside of the lock */
arc4_fetch();
rs_data_available = 1;
__sync_synchronize();
}
return (rnd);
}
void
arc4random_buf(void *_buf, size_t n)
{
u_char *buf = (u_char *)_buf;
int did_stir = 0;
while (n--) {
if (arc4_check_stir())
{
did_stir = 1;
}
buf[n] = arc4_getbyte();
arc4_count--;
}
if (did_stir)
{
/* stirring used up our data pool, we need to read in new data outside of the lock */
arc4_fetch();
rs_data_available = 1;
__sync_synchronize();
}
}
/*
* Calculate a uniformly distributed random number less than upper_bound
* avoiding "modulo bias".
*
* Uniformity is achieved by generating new random numbers until the one
* returned is outside the range [0, 2**32 % upper_bound). This
* guarantees the selected random number will be inside
* [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound)
* after reduction modulo upper_bound.
*/
u_int32_t
arc4random_uniform(u_int32_t upper_bound)
{
u_int32_t r, min;
if (upper_bound < 2)
return (0);
#if (ULONG_MAX > 0xffffffffUL)
min = 0x100000000UL % upper_bound;
#else
/* Calculate (2**32 % upper_bound) avoiding 64-bit math */
if (upper_bound > 0x80000000)
min = 1 + ~upper_bound;/* 2**32 - upper_bound */
else {
/* (2**32 - (x * 2)) % x == 2**32 % x when x <= 2**31 */
min = ((0xffffffff - (upper_bound * 2)) + 1) % upper_bound;
}
#endif
/*
* This could theoretically loop forever but each retry has
* p > 0.5 (worst case, usually far better) of selecting a
* number inside the range we need, so it should rarely need
* to re-roll.
*/
for (;;) {
r = arc4random();
if (r >= min)
break;
}
return (r % upper_bound);
}
void
arc4_init(void)
{
}
#if 0
/*-------- Test code for i386 --------*/
#include <stdio.h>
#include <machine/pctr.h>
int
main(int argc, char **argv)
{
const int iter = 1000000;
int i;
pctrval v;
v = rdtsc();
for (i = 0; i < iter; i++)
arc4random();
v = rdtsc() - v;
v /= iter;
printf("%qd cycles\n", v);
}
#endif
branches/cparm/i386/libsaio/stack_protector.c
3333
3434
3535
36
36
3737
3838
3939
......
4646
4747
4848
49
49
5050
5151
5252
......
5656
5757
5858
59
59
6060
6161
6262
6363
6464
6565
66
66
6767
68
68
6969
long __stack_chk_guard[8] = {0, 0, 0, 0, 0, 0, 0, 0};
//__private_extern__ void __guard_setup(void) /*__attribute__ ((visibility ("hidden")))*/;
static void __guard_setup(void) __attribute__((constructor));
void __guard_setup(void) __attribute__((constructor));
void __stack_chk_fail(void);
size_t i;
long guard[__arraycount(__stack_chk_guard)];
arc4rand(guard, sizeof(guard), 0);
arc4random_buf(guard, sizeof(guard));
for (i = 0; i < __arraycount(guard); i++)
__stack_chk_guard[i] = guard[i];
to the "terminator canary" */
((char*)__stack_chk_guard)[0] = 0; ((char*)__stack_chk_guard)[1] = 0;
((char*)__stack_chk_guard)[2] = '\n'; ((char*)__stack_chk_guard)[3] = 255;
}
void
__stack_chk_fail()
{
#ifndef BOOT1
stop("stack overflow");
stop("stack overflow");
#endif
for(;;);
for(;;);
}
branches/cparm/i386/libsaio/intel_acpi.h
3434
3535
3636
37
37
3838
3939
4040
......
164164
165165
166166
167
167
168168
169169
170170
......
173173
174174
175175
176
176
177177
178178
179179
......
186186
187187
188188
189
189
190190
191191
192192
......
194194
195195
196196
197
197
198198
199199
200200
201201
202202
203203
204
204
205205
206206
207207
208208
209209
210
210
211211
212212
213213
......
220220
221221
222222
223
223
224224
225225
226226
......
230230
231231
232232
233
233
234234
235235
236236
......
247247
248248
249249
250
250
251251
252252
253253
......
259259
260260
261261
262
262
263263
264264
265265
......
276276
277277
278278
279
279
280280
281281
282282
......
288288
289289
290290
291
291
292292
293293
294294
......
344344
345345
346346
347
347
348348
349349
350350
351351
352
352
353353
354354
355355
356356
357357
358358
359
359
360360
361361
362362
......
378378
379379
380380
381
381
382382
383383
384384
......
388388
389389
390390
391
391
392392
393393
394394
......
397397
398398
399399
400
400
401401
402402
403403
......
406406
407407
408408
409
409
410410
411411
412412
413413
414414
415415
416
416
417417
418418
419419
......
421421
422422
423423
424
424
425425
426426
427427
428428
429429
430430
431
431
432432
433433
434434
......
437437
438438
439439
440
440
441441
442442
443443
......
449449
450450
451451
452
452
453453
454454
455455
......
461461
462462
463463
464
464
465465
466466
467467
......
470470
471471
472472
473
473
474474
475475
476476
......
499499
500500
501501
502
502
503503
504504
505505
506506
507507
508
508
509509
510510
511511
512512
513
513
514514
515515
516516
517517
518518
519
519
520520
521521
522522
523523
524524
525
525
526526
527527
528528
529529
530530
531
531
532532
533533
534534
535535
536536
537
537
538538
539539
540540
541541
542
542
543543
544544
545545
546546
547
547
548548
549549
550550
551551
552
552
553553
554554
555555
556556
557
557
558558
559559
560560
561561
562
562
563563
564564
565565
566566
567
567
568568
569569
570570
571571
572
572
573573
574574
575575
576576
577
577
578578
579579
580580
581581
582
582
583583
584584
585585
586586
587587
588588
589
589
590590
591591
592592
593593
594594
595595
596
596
597597
598598
599599
600600
601
601
602602
603603
604604
605605
606
606
607607
608608
609609
......
614614
615615
616616
617
617
618618
619619
620620
621621
622
622
623623
624624
625625
626626
627
627
628628
629629
630630
631631
632
632
633633
634634
635635
......
638638
639639
640640
641
641
642642
643643
644644
......
648648
649649
650650
651
651
652652
653653
654654
......
657657
658658
659659
660
660
661661
662662
663663
......
667667
668668
669669
670
670
671671
672672
673673
......
676676
677677
678678
679
679
680680
681681
682682
......
685685
686686
687687
688
688
689689
690
690
691691
692692
#include "ppmsetup.h"
//
// All tables and structures must be byte-packed to match the ACPI specification
#pragma pack(1)
//#pragma pack(1)
#define ACPI_SIG_DSDT "DSDT" // Differentiated System Description Table
#define ACPI_SIG_FADT "FACP" // Fixed ACPI Description Table
U32 OemRevision; // OEM revision number
U8 AslCompilerId[4]; // ASCII ASL compiler vendor ID
U32 AslCompilerRevision; // ASL compiler version
} ACPI_TABLE_HEADER;
} __attribute__((packed))ACPI_TABLE_HEADER;
// GAS - Generic Address Structure (ACPI 2.0+)
typedef struct acpi_generic_address {
U8 BitOffset; // Bit offset within the register
U8 AccessWidth; // Minimum Access size (ACPI 3.0)
U64 Address; // 64-bit address of struct or register
} ACPI_GENERIC_ADDRESS;
} __attribute__((packed))ACPI_GENERIC_ADDRESS;
// RSDP - Root System Description Pointer (Signature is "RSD PTR ")
typedef struct acpi_table_rsdp {
U64 XsdtPhysicalAddress; // 64-bit physical address of the XSDT (ACPI 2.0+)
U8 ExtendedChecksum; // Checksum of entire table (ACPI 2.0+)
U8 Reserved[3]; // Reserved, must be zero
} ACPI_TABLE_RSDP;
} __attribute__((packed))ACPI_TABLE_RSDP;
#define ACPI_RSDP_REV0_SIZE 20 // Size of original ACPI 1.0 RSDP
typedef struct acpi_table_rsdt {
ACPI_TABLE_HEADER Header; // Common ACPI table header
U32 TableOffsetEntry[1]; // Array of pointers to ACPI tables
} ACPI_TABLE_RSDT;
} __attribute__((packed))ACPI_TABLE_RSDT;
// XSDT - Root System Description Table
typedef struct acpi_table_xsdt {
ACPI_TABLE_HEADER Header; // Common ACPI table header
U64 TableOffsetEntry[1]; // Array of pointers to ACPI tables
} ACPI_TABLE_XSDT;
} __attribute__((packed))ACPI_TABLE_XSDT;
// DSDT - Differentiated System Description Table
typedef struct acpi_table_dsdt {
ACPI_TABLE_HEADER Header; // Common ACPI table header
U32 EntryStart;
} ACPI_TABLE_DSDT;
} __attribute__((packed))ACPI_TABLE_DSDT;
// FACS - Firmware ACPI Control Structure (FACS)
typedef struct acpi_table_facs {
U64 XFirmwareWakingVector; // 64-bit version of the Firmware Waking Vector (ACPI 2.0+)
U8 Version; // Version of this table (ACPI 2.0+)
U8 Reserved[31]; // Reserved, must be zero
} ACPI_TABLE_FACS;
} __attribute__((packed))ACPI_TABLE_FACS;
// SBST - Smart Battery Specification Table - Version 1
typedef struct acpi_table_sbst
U32 LowLevel;
U32 CriticalLevel;
} ACPI_TABLE_SBST;
} __attribute__((packed))ACPI_TABLE_SBST;
// ASF - Alert Standard Format table (Signature "ASF!")
typedef struct acpi_table_asf
U8Flags;
U8Reserved[10];
} ACPI_TABLE_DMAR;
} __attribute__((packed))ACPI_TABLE_DMAR;
// HPET - High Precision Event Timer table - Version 1
typedef struct acpi_table_hpet
U16MinimumTick; /* Main counter min tick, periodic mode */
U8Flags;
} ACPI_TABLE_HPET;
} __attribute__((packed))ACPI_TABLE_HPET;
//MCFG - PCI Memory Mapped Configuration table and sub-table - Version 1
typedef struct acpi_table_mcfg
U8Identifier[16]; /* UUID identifier */
U16DataOffset; /* Offset of remaining data in table */
} ACPI_TABLE_UEFI;
} __attribute__((packed))ACPI_TABLE_UEFI;
// ECDT - Embedded Controller Boot Resources Table - Version 1
typedef struct acpi_table_ecdt
U8Gpe; /* The GPE for the EC */
U8Id[1]; /* Full namepath of the EC in the ACPI namespace */
} ACPI_TABLE_ECDT;
} __attribute__((packed))ACPI_TABLE_ECDT;
// FADT - Fixed ACPI Description Table (Signature "FACP")
typedef struct acpi_table_fadt {
ACPI_GENERIC_ADDRESS XPmTimerBlock; // 64-bit Extended Power Mgt Timer Ctrl Reg Blk address
ACPI_GENERIC_ADDRESS XGpe0Block; // 64-bit Extended General Purpose Event 0 Reg Blk address
ACPI_GENERIC_ADDRESS XGpe1Block; // 64-bit Extended General Purpose Event 1 Reg Blk address
} ACPI_TABLE_FADT;
} __attribute__((packed))ACPI_TABLE_FADT;
// SSDT - Secondary System Description Table
typedef struct acpi_table_ssdt {
ACPI_TABLE_HEADER Header; // Common ACPI table header
} ACPI_TABLE_SSDT;
} __attribute__((packed))ACPI_TABLE_SSDT;
//MADT - Multiple APIC Description Table
typedef struct acpi_table_madt {
ACPI_TABLE_HEADER Header; // Common ACPI table header
U32 Address; // Physical address of local APIC
U32 Flags;
} ACPI_TABLE_MADT;
} __attribute__((packed))ACPI_TABLE_MADT;
// Values for subtable type in ACPI_SUBTABLE_HEADER
typedef struct acpi_subtable_header {
U8 Type;
U8 Length;
} ACPI_SUBTABLE_HEADER;
} __attribute__((packed))ACPI_SUBTABLE_HEADER;
// MADT Sub-tables, correspond to Type in ACPI_SUBTABLE_HEADER
U8 ProcessorId; // ACPI processor id
U8 Id; // Processor's local APIC id
U32 LapicFlags;
} ACPI_MADT_LOCAL_APIC;
} __attribute__((packed))ACPI_MADT_LOCAL_APIC;
// 1: IO APIC
typedef struct acpi_madt_io_apic {
U8 Reserved; // Reserved - must be zero
U32 Address; // APIC physical address
U32 GlobalIrqBase; // Global system interrupt where INTI lines start
} ACPI_MADT_IO_APIC;
} __attribute__((packed))ACPI_MADT_IO_APIC;
// 2: Interrupt Override
typedef struct acpi_madt_interrupt_override {
U8 SourceIrq; // Interrupt source (IRQ)
U32 GlobalIrq; // Global system interrupt
U16 IntiFlags;
} ACPI_MADT_INTERRUPT_OVERRIDE;
} __attribute__((packed))ACPI_MADT_INTERRUPT_OVERRIDE;
// 3: NMI Source
typedef struct acpi_madt_nmi_source {
ACPI_SUBTABLE_HEADER Header;
U16 IntiFlags;
U32 GlobalIrq; // Global system interrupt
} ACPI_MADT_NMI_SOURCE;
} __attribute__((packed))ACPI_MADT_NMI_SOURCE;
// 4: Local APIC NMI
typedef struct acpi_madt_local_apic_nmi {
U8 ProcessorId; // ACPI processor id
U16 IntiFlags;
U8 Lint; // LINTn to which NMI is connected
} ACPI_MADT_LOCAL_APIC_NMI;
} __attribute__((packed))ACPI_MADT_LOCAL_APIC_NMI;
// 5: Address Override
typedef struct acpi_madt_local_apic_override {
ACPI_SUBTABLE_HEADER Header;
U16 Reserved; // Reserved, must be zero
U64 Address; // APIC physical address
} ACPI_MADT_LOCAL_APIC_OVERRIDE;
} __attribute__((packed))ACPI_MADT_LOCAL_APIC_OVERRIDE;
// 6: I/O Sapic
typedef struct acpi_madt_io_sapic {
U8 Reserved; // Reserved, must be zero
U32 GlobalIrqBase; // Global interrupt for SAPIC start
U64 Address; // SAPIC physical address
} ACPI_MADT_IO_SAPIC;
} __attribute__((packed))ACPI_MADT_IO_SAPIC;
// 7: Local Sapic
typedef struct acpi_madt_local_sapic {
U32 LapicFlags;
U32 Uid; // Numeric UID - ACPI 3.0
char UidString[1]; // String UID - ACPI 3.0
} ACPI_MADT_LOCAL_SAPIC;
} __attribute__((packed))ACPI_MADT_LOCAL_SAPIC;
// 8: Platform Interrupt Source
typedef struct acpi_madt_interrupt_source {
U8 IoSapicVector; // Vector value for PMI interrupts
U32 GlobalIrq; // Global system interrupt
U32 Flags; // Interrupt Source Flags
} ACPI_MADT_INTERRUPT_SOURCE;
} __attribute__((packed))ACPI_MADT_INTERRUPT_SOURCE;
// 9: Processor X2APIC
typedef struct acpi_madt_x2apic {
U32 x2apicId; // Processor's X2APIC ID
U32 x2apicFlags;
U32 UID;
} ACPI_MADT_X2APIC;
} __attribute__((packed))ACPI_MADT_X2APIC;
// Common flags fields for MADT subtables
typedef struct packageLength {
U8 packageLength0;
U8 packageLength1;
} ACPI_PACKAGE_LENGTH;
} __attribute__((packed))ACPI_PACKAGE_LENGTH;
typedef struct acpi_scope {
U8 scopeOpcode;
ACPI_PACKAGE_LENGTH pkgLength;
U8 rootChar;
} ACPI_SCOPE;
} __attribute__((packed))ACPI_SCOPE;
typedef struct dual_name_path {
U8 prefix;
U32 nameseg[2];
} DUAL_NAME_PATH;
} __attribute__((packed))DUAL_NAME_PATH;
typedef struct multi_name_path {
U8 prefix;
U8 segCount;
U32 nameseg[MAX_SUPPORTED_CPU_NAMESEGS];
} MULTI_NAME_PATH;
} __attribute__((packed))MULTI_NAME_PATH;
typedef struct generic_register {
U8 genericRegisterField;
ACPI_PACKAGE_LENGTH pkgLength;
ACPI_GENERIC_ADDRESS gas;
} ACPI_GENERIC_REGISTER;
} __attribute__((packed))ACPI_GENERIC_REGISTER;
typedef struct package {
U8 packageOpcode;
ACPI_PACKAGE_LENGTH pkgLength;
U8 numElements;
} ACPI_PACKAGE;
} __attribute__((packed))ACPI_PACKAGE;
typedef struct small_package {
U8 packageOpcode;
U8 packageLength;
U8 numElements;
} ACPI_SMALL_PACKAGE;
} __attribute__((packed))ACPI_SMALL_PACKAGE;
typedef struct small_buffer {
U8 bufferOpcode;
U8 packageLength;
} ACPI_SMALL_BUFFER;
} __attribute__((packed))ACPI_SMALL_BUFFER;
typedef struct end_tag {
U8 endTagField;
U8 checksum;
} ACPI_END_TAG;
} __attribute__((packed))ACPI_END_TAG;
typedef struct return_name_seg {
U8 returnOpcode;
U32 name;
} ACPI_RETURN_NAME_SEG;
} __attribute__((packed))ACPI_RETURN_NAME_SEG;
typedef struct return_package {
U8 returnOpcode;
ACPI_PACKAGE package;
} ACPI_RETURN_PACKAGE;
} __attribute__((packed))ACPI_RETURN_PACKAGE;
typedef struct return_zero {
U8 returnOpcode;
U8 zeroOpcode;
} ACPI_RETURN_ZERO;
} __attribute__((packed))ACPI_RETURN_ZERO;
typedef struct return_opcode {
U8 returnOpcode;
U8 opcodeToReturn;
} ACPI_RETURN_OPCODE;
} __attribute__((packed))ACPI_RETURN_OPCODE;
typedef struct byteConst {
U8 byteOpcode;
U8 byteData;
} ACPI_BYTE_CONST;
} __attribute__((packed))ACPI_BYTE_CONST;
typedef struct wordConst {
U8 wordOpcode;
U16 wordData;
} ACPI_WORD_CONST;
} __attribute__((packed))ACPI_WORD_CONST;
typedef struct dwordConst {
U8 dwordOpcode;
U32 dwordData;
} ACPI_DWORD_CONST;
} __attribute__((packed))ACPI_DWORD_CONST;
typedef struct small_method {
U8 methodOpcode;
U8 packageLength;
U32 name;
U8 methodFlags;
} ACPI_SMALL_METHOD;
} __attribute__((packed))ACPI_SMALL_METHOD;
typedef struct method {
U8 methodOpcode;
ACPI_PACKAGE_LENGTH pkgLength;
U32 name;
U8 methodFlags;
} ACPI_METHOD;
} __attribute__((packed))ACPI_METHOD;
typedef struct namePath {
U8 nameOpcode;
U32 name;
} ACPI_NAME_PATH;
} __attribute__((packed))ACPI_NAME_PATH;
typedef struct named_dword {
ACPI_NAME_PATH namePath;
ACPI_DWORD_CONST dword;
} ACPI_NAMED_DWORD;
} __attribute__((packed))ACPI_NAMED_DWORD;
typedef struct rootNamePath {
U8 nameOpcode;
typedef struct root_named_dword {
ACPI_ROOT_NAME_PATH rootNamePath;
ACPI_DWORD_CONST dword;
} ACPI_ROOT_NAMED_DWORD;
} __attribute__((packed))ACPI_ROOT_NAMED_DWORD;
typedef struct named_object {
ACPI_NAME_PATH namePath;
ACPI_PACKAGE package;
} ACPI_NAMED_OBJECT;
} __attribute__((packed))ACPI_NAMED_OBJECT;
typedef struct small_named_object {
ACPI_NAME_PATH namePath;
ACPI_SMALL_PACKAGE package;
} ACPI_SMALL_NAMED_OBJECT;
} __attribute__((packed))ACPI_SMALL_NAMED_OBJECT;
typedef struct create_dword_field {
ACPI_NAME_PATH namePath;
ACPI_SMALL_PACKAGE package;
} ACPI_CREATE_DWORD_FIELD;
} __attribute__((packed))ACPI_CREATE_DWORD_FIELD;
typedef struct tstate_package {
ACPI_SMALL_PACKAGE package;
ACPI_DWORD_CONST TransLatency;
ACPI_DWORD_CONST Control;
ACPI_DWORD_CONST Status;
} ACPI_TSTATE_PACKAGE;
} __attribute__((packed))ACPI_TSTATE_PACKAGE;
typedef struct pstate_package {
ACPI_SMALL_PACKAGE package;
ACPI_DWORD_CONST BMLatency;
ACPI_DWORD_CONST Control;
ACPI_DWORD_CONST Status;
} ACPI_PSTATE_PACKAGE;
} __attribute__((packed))ACPI_PSTATE_PACKAGE;
typedef struct psd_package {
ACPI_SMALL_PACKAGE package;
ACPI_DWORD_CONST Domain;
ACPI_DWORD_CONST CoordType;
ACPI_DWORD_CONST NumProcessors;
} ACPI_PSD_PACKAGE;
} __attribute__((packed))ACPI_PSD_PACKAGE;
typedef struct csd_package {
ACPI_SMALL_PACKAGE package;
ACPI_DWORD_CONST CoordType;
ACPI_DWORD_CONST NumProcessors;
ACPI_DWORD_CONST Index;
} ACPI_CSD_PACKAGE;
} __attribute__((packed))ACPI_CSD_PACKAGE;
typedef struct tsd_package {
ACPI_SMALL_PACKAGE package;
ACPI_DWORD_CONST Domain;
ACPI_DWORD_CONST CoordType;
ACPI_DWORD_CONST NumProcessors;
} ACPI_TSD_PACKAGE;
} __attribute__((packed))ACPI_TSD_PACKAGE;
typedef struct processor {
U8 processorOpCode;
ACPI_BYTE_CONST ProcID;
ACPI_DWORD_CONST PblkAddr;
ACPI_BYTE_CONST PblkLen;
} ACPI_PROCESSOR;
} __attribute__((packed))ACPI_PROCESSOR;
#pragma pack()
//#pragma pack()
#endif /* !__LIBSAIO_INTEL_ACPI_H */
branches/cparm/i386/libsaio/stringTable.c
421421
422422
423423
424
425
426
427
428
429
430
424431
425432
426433
......
483490
484491
485492
486
493
487494
488495
489496
......
507514
508515
509516
517
510518
511519
512520
return false;
}
config_file_t *resolveConfig(config_file_t *config)
{
ASSERT_CONFIG
config_file_t *new_config = config;
return new_config;
}
#if UNUSED
/*
*
*/
// key not found
return false;
}
}
/*
*get color value from plist format #RRGGBB
}
return false;
}
#endif
bool getValueForKey( const char *key, const char **val, int *size, config_file_t *config )
{
branches/cparm/i386/libsaio/convert.c
5454
5555
5656
57
5758
5859
5960
......
7273
7374
7475
76
7577
7678
7779
}
/** XXX AsereBLN replace by strtoul */
#if UNUSED
uint32_t ascii_hex_to_int(char *buff)
{
uint32_tvalue = 0, i, digit;
}
returnvalue;
}
#endif
void *convertHexStr2Binary(const char *hexStr, int *outLength)
{
branches/cparm/i386/libsaio/saio_types.h
9292
9393
9494
95
95
96
97
98
99
100
101
102
103
104
105
106
107
96108
97
98
99
100
109
110
111
112
101113
102114
103115
*/
#define IO_CONFIG_DATA_SIZE40960 // was 4096 // was 163840
#define rand_tab_len 100
struct tm {
inttm_sec;/* seconds after the minute [0-60] */
inttm_min;/* minutes after the hour [0-59] */
inttm_hour;/* hours since midnight [0-23] */
inttm_mday;/* day of the month [1-31] */
inttm_mon;/* months since January [0-11] */
inttm_year;/* years since 1900 */
inttm_wday;/* days since Sunday [0-6] */
inttm_yday;/* days since January 1 [0-365] */
inttm_isdst;/* Daylight Savings Time flag */
longtm_gmtoff;/* offset from CUT in seconds */
char*tm_zone;/* timezone abbreviation */
};
struct ran_obj {
int tab[rand_tab_len];
int rmin;
int n;
/** System time structure */
struct timeval {
time_t tv_sec; /**< Seconds */
suseconds_t tv_usec; /**< Microseconds */
};
typedef struct tm_t
branches/cparm/i386/libsaio/msdos.c
5252
5353
5454
55
5556
5657
5758
......
131132
132133
133134
134
135
135136
136137
137138
138139
139140
140141
141
142
142143
143144
144145
......
207208
208209
209210
210
211
212
213
211214
212
215
213216
214217
215218
......
669672
670673
671674
672
675
673676
674677
675678
......
779782
780783
781784
785
786
782787
788
783789
784790
785791
......
860866
861867
862868
863
869
870
871
864872
865873
866874
......
905913
906914
907915
908
916
917
918
919
909920
910921
911922
......
955966
956967
957968
969
958970
959971
960972
#include "msdos_private.h"
#include "msdos.h"
#include "platform.h"
#define LABEL_LENGTH11
#define MSDOS_CACHE_BLOCKSIZE BPS
union bootsector *bsp;
struct bpb33 *b33;
struct bpb50 *b50;
struct bpb710 *b710;
//struct bpb710 *b710;
u_int16_t bps;
u_int8_tspc;
bsp = (union bootsector *)buffer;
b33 = (struct bpb33 *)bsp->bs33.bsBPB;
b50 = (struct bpb50 *)bsp->bs50.bsBPB;
b710 = (struct bpb710 *)bsp->bs710.bsBPB;
//b710 = (struct bpb710 *)bsp->bs710.bsBPB;
/* We only work with 512, 1024, and 2048 byte sectors */
bps = OSSwapLittleToHostInt16(b33->bpbBytesPerSec);
/* Check to make sure valid sectors per cluster */
spc = b33->bpbSecPerClust;
if ((spc == 0 ) || (spc & (spc - 1)))
if ((spc == 0 ) || (spc & (spc - 1)))
{
free (buf);
return -1;
}
if (OSSwapLittleToHostInt16(b50->bpbRootDirEnts) == 0) { /* It's FAT32 */
if (memcmp(((struct extboot *)bsp->bs710.bsExt)->exFileSysType, "FAT32 ", 8))
{
st = (struct msdosdirstate *)(long) *dirIndex;
if (!st)
{
st=malloc (sizeof (*st));
st=malloc (sizeof (struct msdosdirstate));
if (dirPath[0])
{
uint8_t *buf=malloc(msdosclustersize);
cluster |= ((uint32_t)OSReadLittleInt16 ((dirp->deHighClust),0)) <<16;
size = (uint32_t)OSReadLittleInt32 ((dirp->deFileSize),0);
if (size<=offset)
{
free (buf);
return -1;
}
nskip=offset/msdosclustersize;
for (i=0;i<nskip;i++)
msdosreadcluster (ih, 0, 0, &cluster);
long MSDOSLoadFile(CICell ih, char * filePath)
{
return MSDOSReadFile(ih, filePath, (void *)gFSLoadAddress, 0, 0);
//return MSDOSReadFile(ih, filePath, (void *)gFSLoadAddress, 0, 0);
return MSDOSReadFile(ih, filePath, (void *)(uint32_t)get_env(envgFSLoadAddress), 0, 0);
}
/* Fix up volume label. */
str[0]=0;
return;
}
bzero(label,sizeof(label));
bzero(vfatlabel,sizeof(vfatlabel));
label[0] = '\0';
initRoot (&st);
if (MSDOSInitPartition (ih)<0)
{
free (buf);
return -1;
}
bzero (uuidStr, 16);
branches/cparm/i386/libsaio/fake_efi.c
175175
176176
177177
178
178
179179
180180
181181
......
193193
194194
195195
196
196
197197
198198
199199
......
227227
228228
229229
230
230
231231
232232
233233
......
241241
242242
243243
244
244
245245
246246
247247
......
265265
266266
267267
268
268
269269
270270
271271
......
278278
279279
280280
281
281
282282
283283
284284
......
736736
737737
738738
739
739
740740
741741
742742
......
806806
807807
808808
809
809
810810
811811
812812
813813
814814
815
815
816816
817817
818818
......
10051005
10061006
10071007
1008
1008
10091009
1010
1010
10111011
10121012
10131013
......
10621062
10631063
10641064
1065
1065
10661066
10671067
10681068
//Azi: as is, cpu's with em64t will use EFI64 on pre 10.6 systems,
// wich seems to cause no problem. In case it does, force i386 arch.
if (archCpuType == CPU_TYPE_I386)
if (get_env(envarchCpuType) == CPU_TYPE_I386)
{
i = gNumTables32;
}
return EFI_ABORTED;
}
if (archCpuType == CPU_TYPE_I386)
if (get_env(envarchCpuType) == CPU_TYPE_I386)
{
gEfiConfigurationTable32[i].VendorGuid = *pGuid;
static VOID EFI_ST_FIX_CRC32(void)
{
if (archCpuType == CPU_TYPE_I386)
if (get_env(envarchCpuType) == CPU_TYPE_I386)
{
gST32->Hdr.CRC32 = 0;
gST32->Hdr.CRC32 = crc32(0L, gST32, gST32->Hdr.HeaderSize);
void finalizeEFIConfigTable(void )
{
if (archCpuType == CPU_TYPE_I386)
if (get_env(envarchCpuType) == CPU_TYPE_I386)
{
EFI_SYSTEM_TABLE_32 *efiSystemTable = gST32;
uint32_t table ;
EFI_GUID Guid;
if (archCpuType == CPU_TYPE_I386)
if (get_env(envarchCpuType) == CPU_TYPE_I386)
{
num = gST32->NumberOfTableEntries;
msglog("EFI Configuration table :\n");
for (i=0; i<num; i++)
{
if (archCpuType == CPU_TYPE_I386)
if (get_env(envarchCpuType) == CPU_TYPE_I386)
{
table = gEfiConfigurationTable32[i].VendorTable;
Guid = gEfiConfigurationTable32[i].VendorGuid;
((boot_progress_element *)bootPict)->width = kFailedBootWidth;
((boot_progress_element *)bootPict)->height = kFailedBootHeight;
((boot_progress_element *)bootPict)->yOffset = kFailedBootOffset;
if (gBootVolume->OSVersion[3] == '8')
if (((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] == '8')
{
((boot_progress_element *)bootPict)->res[0] = size - 32;
}
Node *runtimeServicesNode = DT__AddChild(efiNode, "runtime-services");
Node *kernelCompatibilityNode = 0; // ??? not sure that it should be used like that (because it's maybe the kernel capability and not the cpu capability)
if (gBootVolume->OSVersion[3] > '6')
if (((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] > '6')
{
kernelCompatibilityNode = DT__AddChild(efiNode, "kernel-compatibility");
DT__AddProperty(kernelCompatibilityNode, "i386", sizeof(uint32_t), (EFI_UINT32*)&DEVICE_SUPPORTED);
}
if (archCpuType == CPU_TYPE_I386)
if (get_env(envarchCpuType) == CPU_TYPE_I386)
{
// The value of the table property is the 32-bit physical address for the RuntimeServices table.
// Since the EFI system table already has a pointer to it, we simply use the address of that pointer
if (mps_p)
{
uint64_t mps = ((uint64_t)((uint32_t)mps_p));
//uint64_t mps = ((uint64_t)((uint32_t)mps_p));
addConfigurationTable(&gEfiMpsTableGuid, &mps, NULL);
addConfigurationTable(&gEfiMpsTableGuid, ((uint64_t*)((uint32_t)mps_p)), NULL);
}
#if DEBUG_EFI
setup_Smbios();
// Initialize the base table
if (archCpuType == CPU_TYPE_I386)
if (get_env(envarchCpuType) == CPU_TYPE_I386)
{
setupEfiTables(32);
}
branches/cparm/i386/libsaio/misc.c
120120
121121
122122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250123
251124
252125
}
#endif
static bool fix_random=true;
struct ran_obj* random_init (int rmin, int rmax)
{
if (rmin > rmax)
return false;
int n = (rmax+1) - rmin;
int tab[rand_tab_len];
struct ran_obj * self = (struct ran_obj * )malloc(sizeof(struct ran_obj));
if (!self) {
return NULL;
}
bzero(self,sizeof(struct ran_obj));
self->rmin= rmin;
self->n= n;
int i;
srand(time18());
int limit1= 0, limit2= 0, gate1 = 0, gate2 = 0;
if (fix_random) {
limit1 = (rand() % 20) ;
limit2 = (rand() % 20) ;
}
for (i = 0; i < rand_tab_len; i++){
tab[i] = (rand() % n) + rmin;
if (fix_random) {
if (i > 1 && gate1 < limit1 && tab[i]==tab[i-2]) {
i--;
gate1++;
continue;
}
if (i > 7 && gate2 < limit2 && tab[i]==tab[i-((rand() % 4)+5)]) {
i--;
gate2++;
continue;
}
}
self->tab[i]= tab[i];
}
return self;
}
int random (struct ran_obj* self)
{
struct ran_obj * ret = self ;
static int wheel = 0;
int gate3 = 0;
int limit3 = 0;
static int retlst[rand_tab_len];
int index;
int rn;
if (!ret) {
return -1;// TODO: fix this
}
if (fix_random) {
gate3 = rand() % 2;
}
retry:
index = rand() % rand_tab_len;
rn = ret->tab[index];
ret->tab[index] = (rand() % ret->n) + ret->rmin;
if (fix_random) {
if ((gate3 && limit3 < 5) && (ret->tab[index] == rn)) {
limit3++;
goto retry;
}
retlst[wheel] = rn;
if (wheel > 0 && limit3 < 5) {
if (gate3 && (rn == retlst[wheel-1])) {
limit3++;
goto retry;
}
if (gate3 && (wheel > 3 && rn==retlst[wheel-((rand() % 3)+1)]) && (limit3 < 5)) {
limit3++;
goto retry;
}
}
wheel++;
}
self = ret;
return rn;
}
void random_free (struct ran_obj* self)
{
if (self /* && self->sgn == random_obj_sgn */) {
free(self);
}
}
void usefixedrandom (bool opt)
{
fix_random = opt;
}
//==========================================================================
// Return the platform name for this hardware.
//
branches/cparm/i386/libsaio/saio_internal.h
2929
3030
3131
32
33
32
33
34
35
36
37
38
3439
3540
3641
......
5762
5863
5964
60
6165
6266
6367
......
97101
98102
99103
100
104
101105
102106
103107
104108
105109
106
107
108110
109111
110112
......
122124
123125
124126
125
127
126128
127
129
128130
129131
130132
......
148150
149151
150152
151
152153
153154
154155
......
157158
158159
159160
161
162
163
164
165
160166
161
167
162168
163
169
164170
165171
166172
167173
168174
169
175
170176
171177
172178
173179
180
174181
175182
176183
......
205212
206213
207214
215
208216
209217
210218
211
212219
213220
214221
......
221228
222229
223230
231
232
224233
225234
235
226236
227237
228238
......
238248
239249
240250
241
251
242252
243253
244254
245
255
246256
247257
248258
......
261271
262272
263273
274
264275
265276
266277
......
281292
282293
283294
284
285
286
295
296
287297
288298
289299
290300
301
302
303
291304
292
305
293306
294307
308
309
310
295311
/* arc4random.c */
extern void arc4_init(void);
extern void arc4rand(void *ptr, u_int len, int reseed);
extern uint32_t arc4random(void);
extern void arc4random_buf(void *_buf, size_t n);
extern u_int32_t arc4random_uniform(u_int32_t upper_bound);
extern u_int32_t arc4random(void);
extern void arc4random_addrandom(u_char *dat, int datlen);
extern void arc4random_stir(void);
#define arc4random_unirange(lo,hi) arc4random_uniform(hi - lo + 1) + lo
#define arc4random_range(lo,hi) (arc4random() % (hi - lo + 1)) + lo
/* asm.s */
extern void real_to_prot(void);
extern void putc(int ch);
extern void putca(int ch, int attr, int repeat);
extern int getc(void);
extern void pause();
extern int readKeyboardStatus(void);
extern int readKeyboardShiftFlags(void);
extern unsigned int time18(void);
/* cache.c */
extern void CacheReset();
extern void CacheReset();
extern void CacheInit(CICell ih, long blockSize);
extern long CacheRead(CICell ih, char *buffer, long long offset,
long length, long cache);
/* console.c */
extern bool gVerboseMode;
extern bool gErrors;
extern void initBooterLog(void);
extern void setupBooterLog(void);
extern void putchar(int ch);
extern void pause(void);
/* disk.c */
extern void rescanBIOSDevice(int biosdev);
extern void rescanBIOSDevice(int biosdev);
extern struct DiskBVMap* diskResetBootVolumes(int biosdev);
extern void diskFreeMap(struct DiskBVMap *map);
extern void diskFreeMap(struct DiskBVMap *map);
extern int testBiosread( int biosdev, unsigned long long secno );
extern BVRef diskScanBootVolumes(int biosdev, int *count);
extern void diskSeek(BVRef bvr, long long position);
u_int16_t *ucslen, u_int32_t bufsize, int byte_order );
/* load.c */
extern bool gHaveKernelCache;
extern long ThinFatFile(void **binary, unsigned long *length);
extern long DecodeMachO(void *binary, entry_t *rentry, char **raddr, int *rsize);
*/
extern int decompress_lzss(u_int8_t *dst, u_int8_t *src, u_int32_t srclen);
/* lib.c */
extern int bcd2dec(int b);
extern int dec2bcd(int d);
/* memory.c */
long AllocateKernelMemory( long inSize );
extern long AllocateKernelMemory( long inSize );
long
extern long
AllocateMemoryRange(char * rangeName, long start, long length);
/* misc.c */
extern void enableA20(void);
extern void turnOffFloppy(void);
#if UNUSED
extern void random_free (struct ran_obj* self);
extern int random (struct ran_obj* self);
extern struct ran_obj* random_init (int rmin, int rmax);
extern void usefixedrandom (bool opt);
#endif
extern void getPlatformName(char *nameBuf);
extern void re_set_env(const char *name , unsigned long long value) ;
extern void unset_env(const char *name);
extern void free_platform_env(void);
void showError(void);
void debug_platform_env(void);
/* stringTable.c */
extern char * newStringFromList(char **list, int *size);
extern int stringLength(const char *table, int compress);
extern const char * getStringForKey(const char * key, config_file_t *config);
extern bool getBoolForKey(const char *key, bool *val, config_file_t *configBuff);
extern bool getIntForKey(const char *key, int *val, config_file_t *configBuff);
extern config_file_t *resolveConfig(config_file_t *config);
#if UNUSED
extern bool getColorForKey(const char *key, unsigned int *val, config_file_t *configBuff);
extern bool getDimensionForKey( const char *key, unsigned int *value, config_file_t *config, unsigned int dimension_max, unsigned int object_size );
#endif
extern int loadConfigFile(const char *configFile, config_file_t *configBuff);
extern int loadBooterConfig(void);
extern int loadSystemConfig(void);
extern int ParseXMLFile( char * buffer, TagPtr * dict );
/* sys.c */
extern BVRef getBootVolumeRef( const char * path, const char ** outPath );
extern BVRef getBootVolumeRef( const char * path, const char ** outPath );
extern long LoadVolumeFile(BVRef bvr, const char *fileSpec);
extern long LoadFile(const char *fileSpec);
extern long ReadFileAtOffset(const char * fileSpec, void *buffer, uint64_t offset, uint64_t length);
extern long LoadThinFatFile(const char *fileSpec, void **binary);
extern long LoadThinFatFile(const char *fileSpec, void **binary);
extern long GetDirEntry(const char *dirSpec, long long *dirIndex, const char **name,
long *flags, long *time);
extern long GetFileInfo(const char *dirSpec, const char *name,
extern int write(int fdesc, const char *buf, int count);
extern int writebyte(int fdesc, char value);
extern int writeint(int fdesc, int value);
extern struct iob * iob_from_fdesc(int fdesc);
extern int b_lseek(int fdesc, int addr, int ptr);
extern int tell(int fdesc);
extern const char * systemConfigDir(void);
extern void setBootGlobals(BVRef chain);
extern int getDeviceDescription(BVRef volume, char *str);
extern int gBootFileType;
extern BVRef gBootVolume;
extern BVRef gBIOSBootVolume;
/* rtc.c */
extern void rtc_read_clock(struct tm *time) ;
/* smp.c */
extern void * getMPSTable();
/* time.c */
extern int gettimeofday(struct timeval *tv, void *tz);
/* uterror.c */
extern jmp_buf h_buf_error;
extern jmp_buf uterror;
extern void init_ut_fnc(void);
//#define LOCALIZE
//extern int localVPrintf(const char *format, va_list ap);
#endif /* !__LIBSAIO_SAIO_INTERNAL_H */
branches/cparm/i386/libsaio/utarray.h
11
2
2
33
44
55
......
2727
2828
2929
30
30
3131
3232
3333
......
3737
3838
3939
40
41
40
41
42
43
44
45
46
47
48
49
50
51
4252
4353
4454
......
6878
6979
7080
71
81
7282
7383
7484
7585
7686
77
87
7888
7989
8090
8191
8292
83
93
8494
8595
8696
8797
8898
89
99
90100
91101
92102
......
185195
186196
187197
188
189
190
191
198
199
200
201
192202
193203
194204
......
210220
211221
212222
223
213224
214225
215226
......
220231
221232
222233
223
234
224235
225236
226237
/*
Copyright (c) 2008-2011, Troy D. Hanson http://uthash.sourceforge.net
Copyright (c) 2008-2012, Troy D. Hanson http://uthash.sourceforge.net
All rights reserved.
Redistribution and use in source and binary forms, with or without
#ifndef UTARRAY_H
#define UTARRAY_H
#define UTARRAY_VERSION 1.9.4
#define UTARRAY_VERSION 1.9.6
#ifdef __GNUC__
#define _UNUSED_ __attribute__ ((__unused__))
#include "libsaio.h"
#define oom() longjmp(h_buf_error,-1)
#ifndef utarray_oom
#define utarray_oom() longjmp(uterror,-1)
#endif
#ifndef __utarray_malloc
#define __utarray_malloc(sz) malloc(sz) /* malloc fcn */
#endif
#ifndef __utarray_free
#define __utarray_free(ptr) free(ptr) /* free fcn */
#endif
#ifndef __utarray_realloc
#define __utarray_realloc(ptr,sz) realloc(ptr,sz) /* realloc fcn */
#endif
typedef void (ctor_f)(void *dst, const void *src);
typedef void (dtor_f)(void *elt);
typedef void (init_f)(void *elt);
(a)->icd.dtor(utarray_eltptr(a,_ut_i)); \
} \
} \
free((a)->d); \
__utarray_free((a)->d); \
} \
(a)->n=0; \
} while(0)
#define utarray_new(a,_icd) do { \
a=(UT_array*)malloc(sizeof(UT_array)); \
a=(UT_array*)utarray_malloc(sizeof(UT_array)); \
utarray_init(a,_icd); \
} while(0)
#define utarray_free(a) do { \
utarray_done(a); \
free(a); \
__utarray_free(a); \
} while(0)
#define utarray_reserve(a,by) do { \
if (((a)->i+by) > ((a)->n)) { \
while(((a)->i+by) > ((a)->n)) { (a)->n = ((a)->n ? (2*(a)->n) : 8); } \
if ( ((a)->d=(char*)realloc((a)->d, (a)->n*(a)->icd.sz)) == NULL) oom(); \
if ( ((a)->d=(char*)__utarray_realloc((a)->d, (a)->n*(a)->icd.sz)) == NULL) utarray_oom(); \
} \
} while(0)
(a)->i -= (len); \
} while(0)
#define utarray_renew(a,u) do { \
if (a) utarray_clear(a); \
else utarray_new((a),(u)); \
} while(0);
#define utarray_renew(a,u) do { \
if (a) utarray_clear(a); \
else utarray_new((a),(u)); \
} while(0)
#define utarray_clear(a) do { \
if ((a)->i > 0) { \
#define utarray_front(a) (((a)->i) ? (_utarray_eltptr(a,0)) : NULL)
#define utarray_next(a,e) (((e)==NULL) ? utarray_front(a) : ((((a)->i) > (utarray_eltidx(a,e)+1)) ? _utarray_eltptr(a,utarray_eltidx(a,e)+1) : NULL))
#define utarray_prev(a,e) (((e)==NULL) ? utarray_back(a) : ((utarray_eltidx(a,e) > 0) ? _utarray_eltptr(a,utarray_eltidx(a,e)-1) : NULL))
#define utarray_back(a) (((a)->i) ? (_utarray_eltptr(a,(a)->i-1)) : NULL)
#define utarray_eltidx(a,e) (((char*)(e) >= (char*)((a)->d)) ? (((char*)(e) - (char*)((a)->d))/(a)->icd.sz) : -1)
}
static void utarray_str_dtor(void *elt) {
char **eltc = (char**)elt;
if (*eltc) free(*eltc);
if (*eltc) __utarray_free(*eltc);
}
static const UT_icd ut_str_icd _UNUSED_ = {sizeof(char*),NULL,utarray_str_cpy,utarray_str_dtor};
static const UT_icd ut_int_icd _UNUSED_ = {sizeof(int),NULL,NULL,NULL};
branches/cparm/i386/MakeInc.dir
3939
4040
4141
42
4342
4443
4544
......
4847
4948
5049
51
52
53
54
55
5650
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
7251
73
52
7453
7554
76
55
7756
7857
79
58
8059
8160
8261
.SUFFIXES: .s .i .c .o
ifeq "makedep" "NO"
.c.o .m.o:
$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c $(INC) $< -o $(OBJROOT)/$*.o
$(OBJROOT)/%.o: %.m
$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c $(INC) $< -o $(OBJROOT)/$*.o
else
.c.o .m.o:
$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c $(INC) $< -o $(OBJROOT)/$*.o \
-MD -dependency-file $(OBJROOT)/$*.d
md -u $(OBJROOT)/Makedep -f -d $(OBJROOT)/$*.d
$(OBJROOT)/%.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c $(INC) $< -o $(OBJROOT)/$*.o \
-MD -dependency-file $(OBJROOT)/$*.d
md -u $(OBJROOT)/Makedep -f -d $(OBJROOT)/$*.d
$(OBJROOT)/%.o: %.m
$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c $(INC) $< -o $(OBJROOT)/$*.o \
-MD -dependency-file $(OBJROOT)/$*.d
md -u $(OBJROOT)/Makedep -f -d $(OBJROOT)/$*.d
endif
#.s.o:
#cc $(INC) -E $< > $(OBJROOT)/$*.o2
#$(AS) -o $(OBJROOT)/$@ $(OBJROOT)/$*.o2
.s.o:
gcc $(CPPFLAGS) -c $(INC) -arch i386 -o $(OBJROOT)/$(@F) $<
$(CC) $(CPPFLAGS) -no-integrated-as -c $(INC) -arch i386 -o $(OBJROOT)/$(@F) $<
boot2.o:
gcc $(CPPFLAGS) -Wa,-n -c $(INC) -arch i386 -o $(OBJROOT)/$(@F) boot2.s
$(CC) $(CPPFLAGS) -Wa,-n -c $(INC) -no-integrated-as -arch i386 -o $(OBJROOT)/$(@F) boot2.s
$(OBJROOT)/%.o: %.s
gcc $(CPPFLAGS) -c $(INC) -arch i386 -o $(OBJROOT)/$(@F) $<
$(CC) $(CPPFLAGS) -no-integrated-as -c $(INC) -arch i386 -o $(OBJROOT)/$(@F) $<
$(DIRS_NEEDED) $(INSTALLDIR) $(SRCROOT):
$(MKDIRS) $@
branches/cparm/i386/boot2/graphics.c
3232
3333
3434
35
3536
3637
3738
......
617618
618619
619620
620
621
621622
622623
623624
#include "appleClut8.h"
#include "bootstruct.h"
#include "modules.h"
#include "platform.h"
#define VIDEO(x) (bootArgs->Video.v_ ## x)
if ( mode == GRAPHICS_MODE )
{
if ( (err=initGraphicsMode ()) == errSuccess ) {
if (gVerboseMode) {
if (get_env(envgVerboseMode)) {
// Tell the kernel to use text mode on a linear frame buffer display
bootArgs->Video.v_display = FB_TEXT_MODE;
} else {
branches/cparm/i386/boot2/boot.c
6161
6262
6363
64
6465
6566
6667
......
7879
7980
8081
81
82
83
8482
8583
8684
85
86
8787
88
89
90
91
92
9388
9489
95
96
97
9890
9991
10092
10193
10294
95
96
97
10398
10499
105100
......
159154
160155
161156
157
162158
163159
164160
......
167163
168164
169165
170
166
171167
172168
173169
......
184180
185181
186182
187
183
188184
189185
190
186
191187
192188
193189
......
196192
197193
198194
199
195
200196
201197
202198
......
216212
217213
218214
219
215
220216
221217
222218
223219
224
225
226
227
228
229
230
231
220
232221
233222
234223
235224
236225
237
226
238227
239228
240229
241
230
242231
243232
244233
......
277266
278267
279268
280
269
281270
282271
283272
......
317306
318307
319308
320
309
321310
322311
323312
......
342331
343332
344333
345
334
346335
347336
348337
......
425414
426415
427416
428
429
430417
431418
432419
......
435422
436423
437424
425
426
427
438428
439429
440
430
441431
442
432
433
434
435
443436
444
445
437
446438
447439
448440
......
501493
502494
503495
504
496
505497
506
507
498
499
500
508501
509
502
510503
511
512
513504
514505
515506
......
538529
539530
540531
541
542
532
533
543534
544535
545536
......
567558
568559
569560
570
571561
572562
573563
......
580570
581571
582572
583
573
584574
585575
586576
......
602592
603593
604594
605
595
596
606597
607598
608599
609
600
601
610602
611603
612604
......
629621
630622
631623
632
624
633625
634626
635627
......
649641
650642
651643
652
644
653645
654646
655647
......
665657
666658
667659
668
660
669661
670662
671663
......
711703
712704
713705
714
706
715707
716708
717
709
718710
719
711
720712
721713
722714
......
760752
761753
762754
763
755
764756
765
757
766758
767759
768760
......
780772
781773
782774
783
775
784776
785777
786778
......
810802
811803
812804
813
805
814806
815807
816808
......
821813
822814
823815
824
816
817
825818
826819
827820
828
821
829822
830823
831824
......
864857
865858
866859
867
860
868861
869862
870863
871
864
872865
873866
874867
......
921914
922915
923916
924
917
925918
926919
927920
......
938931
939932
940933
941
934
942935
943936
944937
......
981974
982975
983976
984
977
985978
986979
987980
......
10201013
10211014
10221015
1023
1016
10241017
10251018
10261019
......
10361029
10371030
10381031
1039
1032
10401033
1041
1042
1043
1044
1045
1046
1047
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
10481044
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1045
1046
1047
1048
1049
1050
10861051
1087
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
10881067
10891068
10901069
......
10981077
10991078
11001079
1101
1080
11021081
1103
1082
11041083
11051084
11061085
#include "modules.h"
#include "xml.h"
#include "options.h"
#include "drivers.h"
#ifndef DEBUG_BOOT
#define DEBUG_BOOT 0
char rootPath[ROOT_PATH_LEN];
} PlatformInfo;
static char gBootKernelCacheFile[Cache_len_name];
static char gMKextName[Cache_len_name];
static BVRef bvChain;
static bool forcecache = false;
static char gBootKernelCacheFile[Cache_len_name];
static char gMKextName[Cache_len_name];
static void zeroBSS(void);
#ifdef SAFE_MALLOC
static inline void malloc_error(char *addr, size_t size, const char *file, int line);
#else
static inline void malloc_error(char *addr, size_t size);
#endif
static int ExecKernel(void *binary);
static void getRootDevice();
#ifdef NBP_SUPPORT
static bool gUnloadPXEOnExit = false;
#endif
static bool find_file_with_ext(const char* dir, const char *ext, const char * name_compare, size_t ext_size);
static bool found_extra_kext(void);
static void determineCpuArch(void);
static void init_pic(void);
void getKernelCachePath(void);
#ifdef NBP_SUPPORT
static bool gUnloadPXEOnExit = false;
#endif
/*
static void init_pic(void)
{
/* Remap IRQ's */
/*
outb(0x20, 0x11);
outb(0xA0, 0x11);
outb(0x21, 0x20);
outb(0xA1, 0x02);
outb(0x21, 0x01);
outb(0xA1, 0x01);
*/
//outb(0x70, inb(0x70)|0x80); /* Disable NMI */
outb(0x21, 0xff); /* Maskout all interrupts Pic1 */
bootArgs->kaddr = bootArgs->ksize = 0;
if(gBootVolume->OSVersion[3] <= '6')
if(((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] <= '6')
{
bootArgs->Header.Version = kBootArgsVersion1;
bootArgs->Header.Revision = gBootVolume->OSVersion[3];
bootArgs->Header.Revision = ((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3];
}
else
{
bootArgs->Header.Version = kBootArgsVersion;
bootArgs->Header.Revision = kBootArgsRevision;
#else
if(gBootVolume->OSVersion[3] >= '7')
if(((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] >= '7')
{
bootArgs->Header.Version = 2;
bootArgs->Header.Revision = 0;
// Load boot drivers from the specifed root path.
if (!gHaveKernelCache)
if (!get_env(envgHaveKernelCache))
{
LoadDrivers("/");
}
if (gErrors)
{
printf("Errors encountered while starting up the computer.\n");
#if DEBUG_BOOT
printf("Pausing %d seconds...\n", kBootErrorTimeout);
sleep(kBootErrorTimeout);
#endif
}
showError();
execute_hook("md0Ramdisk", NULL, NULL, NULL, NULL, NULL, NULL);
setupFakeEfi();
verbose("Starting Darwin %s\n",( archCpuType == CPU_TYPE_I386 ) ? "x86" : "x86_64");
verbose("Starting Darwin %s\n",( get_env(envarchCpuType) == CPU_TYPE_I386 ) ? "x86" : "x86_64");
#ifdef NBP_SUPPORT
// Cleanup the PXE base code.
if ( (gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit )
if ( (get_env(envgBootFileType) == kNetworkDeviceType) && gUnloadPXEOnExit )
{
if ( (ret = nbpUnloadBaseCode()) != nbpStatusSuccess )
{
__setVideoMode( GRAPHICS_MODE );
if(!gVerboseMode)
if(!get_env(envgVerboseMode))
{
__drawColorRectangle(0, 0, DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, 0x01);
execute_hook("Kernel Start", (void*)kernelEntry, (void*)bootArgs, NULL, NULL, NULL, NULL);// Notify modules that the kernel is about to be started
switch (gBootVolume->OSVersion[3]) {
switch (((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3]) {
case '4':
case '5':
case '6':
IMPS_LAPIC_WRITE(LAPIC_LVT1, LAPIC_ICR_DM_NMI);
#endif
switch (gBootVolume->OSVersion[3]) {
switch (((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3]) {
case '4':
case '5':
case '6':
init_ut_fnc();
arc4_init();
initBooterLog();
// Initialize boot info structure.
// Scan and record the system's hardware information.
scan_platform();
// Pseudo-random generator initialization.
arc4_init();
set_env(envgBIOSDev, (BIOSDev = biosdev & kBIOSDevMask));
set_env(envShouldboot, false);
set_env(envkCache, (uint32_t)gBootKernelCacheFile);
set_env(envkCacheFile, (uint32_t)gBootKernelCacheFile);
set_env(envMKextName, (uint32_t)gMKextName);
set_env(envHFSLoadVerbose, 1);
set_env(envarchCpuType, CPU_TYPE_I386);
set_env(envgHaveKernelCache, false);
InitBootPrompt();
// First get info for boot volume.
scanBootVolumes(BIOSDev, 0);
// Create a separated bvr chain using the specified filters.
bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &devcnt);
safe_set_env(envgDeviceCount,devcnt);
safe_set_env(envgDeviceCount,devcnt);
gBootVolume = selectBootVolume(bvChain);
//gBootVolume = selectBootVolume(bvChain);
safe_set_env(envgBootVolume, (uint32_t)selectBootVolume(bvChain));
LoadBundles("/Extra/");
LoadBundles("/Extra/");
load_all_internal_modules();
// Loading preboot ramdisk if exists.
execute_hook("loadPrebootRAMDisk", NULL, NULL, NULL, NULL, NULL, NULL);
}
#if DEBUG
printf(" Default: %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags);
printf(" bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags);
printf(" Default: %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", ((BVRef)(uint32_t)get_env(envgBootVolume)), ((BVRef)(uint32_t)get_env(envgBootVolume))->biosdev, ((BVRef)(uint32_t)get_env(envgBootVolume))->part_no, ((BVRef)(uint32_t)get_env(envgBootVolume))->flags);
printf(" bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", ((BVRef)(uint32_t)get_env(envgBIOSBootVolume)), ((BVRef)(uint32_t)get_env(envgBIOSBootVolume))->biosdev, ((BVRef)(uint32_t)get_env(envgBIOSBootVolume))->part_no, ((BVRef)(uint32_t)get_env(envgBIOSBootVolume))->flags);
getc();
#endif
// Initialize globals.
safe_set_env(envSysConfigValid, false);
gErrors = false;
status = getBootOptions(firstRun);
firstRun = false;
if ( status == -1 )
{
// gBootVolume == NULL usually means the user hit escape.
if(gBootVolume == NULL)
if(((BVRef)(uint32_t)get_env(envgBootVolume)) == NULL)
{
freeFilteredBVChain(bvChain);
{
if (strncmp(val, "x86_64", 4) == 0)
{
archCpuType = CPU_TYPE_X86_64;
safe_set_env(envarchCpuType, CPU_TYPE_X86_64);
}
else if (strncmp(val, "i386", 4) == 0)
{
archCpuType = CPU_TYPE_I386;
safe_set_env(envarchCpuType, CPU_TYPE_I386);
}
else
{
if (((get_env(envgBootMode) & kBootModeSafe) == 0) &&
!get_env(envgOverrideKernel) &&
(gBootFileType == kBlockDeviceType) &&
(get_env(envgBootFileType) == kBlockDeviceType) &&
(gMKextName[0] == '\0') &&
!getValueForBootKey(bootArgs->CommandLine, kIgnorePrelinkKern, &val, &len))
{
trycache = false;
}
verbose("Loading Darwin %s\n", gBootVolume->OSVersion);
verbose("Loading Darwin %s\n", ((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion);
{
long cachetime, kerneltime = 0, exttime;
if (trycache && !forcecache) do {
break;
}
}
else if (gBootVolume->kernelfound != true) // Should never happen.
else if (((BVRef)(uint32_t)get_env(envgBootVolume))->kernelfound != true) // Should never happen.
{
bootFile = kDefaultKernel;
goto out;
{
bootFile = gBootKernelCacheFile;
verbose("Loading kernel cache %s\n", bootFile);
if (gBootVolume->OSVersion[3] > '6')
if (((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] > '6')
{
ret = LoadThinFatFile(bootFile, &binary);
if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)
if ((ret <= 0) && (get_env(envarchCpuType) == CPU_TYPE_X86_64))
{
archCpuType = CPU_TYPE_I386;
safe_set_env(envarchCpuType, CPU_TYPE_I386);
ret = LoadThinFatFile(bootFile, &binary);
}
}
verbose("Loading kernel %s\n", bootFileSpec);
ret = LoadThinFatFile(bootFileSpec, &binary);
if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)
if ((ret <= 0) && (get_env(envarchCpuType) == CPU_TYPE_X86_64))
{
archCpuType = CPU_TYPE_I386;
safe_set_env(envarchCpuType, CPU_TYPE_I386);
ret = LoadThinFatFile(bootFileSpec, &binary);
}
sleep(1);
#ifdef NBP_SUPPORT
if (gBootFileType == kNetworkDeviceType)
if (get_env(envgBootFileType) == kNetworkDeviceType)
{
// Return control back to PXE. Don't unload PXE base code.
gUnloadPXEOnExit = false;
}
}
#ifdef NBP_SUPPORT
if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit)
if ((get_env(envgBootFileType) == kNetworkDeviceType) && gUnloadPXEOnExit)
{
nbpUnloadBaseCode();
}
{
if (cpu_mode_is64bit())
{
archCpuType = CPU_TYPE_X86_64;
safe_set_env(envarchCpuType, CPU_TYPE_X86_64);
}
else
{
archCpuType = CPU_TYPE_I386;
safe_set_env(envarchCpuType, CPU_TYPE_I386);
}
}
}
else
{
if(gBootVolume->OSVersion[3] > '6')
if(((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] > '6')
{
sprintf(gBootKernelCacheFile, "%s", kDefaultCachePath);
}
else if(gBootVolume->OSVersion[3] <= '6')
else if(((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] <= '6')
{
PlatformInfo *platformInfo = malloc(sizeof(PlatformInfo));
DBG("Adler32: %08lX\n",Adler32);
if (gBootVolume->OSVersion[3] < '6')
if (((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] < '6')
{
long flags, cachetime;
int ret = -1;
}
} else if (Adler32)
sprintf(gBootKernelCacheFile, "%s_%s.%08lX", kDefaultCachePath, (archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64", Adler32); //Snow Leopard
sprintf(gBootKernelCacheFile, "%s_%s.%08lX", kDefaultCachePath, (get_env(envarchCpuType) == CPU_TYPE_I386) ? "i386" : "x86_64", Adler32); //Snow Leopard
}
}
//
// Try an alternate method for getting the root UUID on boot helper partitions.
//
if (gBootVolume->flags & kBVFlagBooter)
if (((BVRef)(uint32_t)get_env(envgBootVolume))->flags & kBVFlagBooter)
{
if((loadHelperConfig() == 0)
&& getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig) )
goto out;
}
if (gBootVolume->fs_getuuid && gBootVolume->fs_getuuid (gBootVolume, bootInfo->uuidStr) == 0)
if (((BVRef)(uint32_t)get_env(envgBootVolume))->fs_getuuid && (((BVRef)(uint32_t)get_env(envgBootVolume))->fs_getuuid (((BVRef)(uint32_t)get_env(envgBootVolume)), bootInfo->uuidStr) == 0))
{
verbose("Setting boot-uuid to: %s\n", bootInfo->uuidStr);
//uuidSet = true;
SetgRootDevice(val);
}
static bool find_file_with_ext(const char* dir, const char *ext, const char * name_compare, size_t ext_size)
static bool find_file_with_ext(const char* dir, const char *ext, const char * name_to_compare, size_t ext_size)
{
char* name;
long flags;
long time;
struct dirstuff* moduleDir = opendir(dir);
while(readdir(moduleDir, (const char**)&name, &flags, &time) >= 0)
{
int len = strlen(name);
long ret, length, flags, time;
long long index;
const char * name;
DBG("FileLoadBundles in %s\n",dirSpec);
index = 0;
while (1) {
ret = GetDirEntry(dir, &index, &name, &flags, &time);
if (ret == -1) break;
if (len >= ext_size)
{
if(strcmp(&name[len - ext_size], ext) == 0)
{
if (name_compare)
{
if (strcmp(name, name_compare) == 0)
{
DBG("found : %s\n", name);
closedir(moduleDir);
return true;
}
}
else
{
DBG("found : %s\n", name);
closedir(moduleDir);
return true;
}
}
#if DEBUG_BOOT
else
{
DBG("Ignoring %s\n", name);
}
#endif
}
#if DEBUG_BOOT
else
{
DBG("Ignoring %s\n", name);
}
#endif
}
if (moduleDir) {
closedir(moduleDir);
// Make sure this is not a directory.
if ((flags & kFileTypeMask) != kFileTypeFlat) continue;
// Make sure this is a kext or mkext.
length = strlen(name);
if (strcmp(name + length - ext_size, ext)) continue;
}
if (name_to_compare)
{
if (strcmp(name, name_to_compare) == 0)
{
DBG("found : %s\n", name);
return true;
}
}
else
{
DBG("found : %s\n", name);
return true;
}
}
return false;
}
{
#define EXTENSIONS "Extensions"
#define MKEXT_EXT ".mkext"
#define MKEXT_EXT_SIZE sizeof("mkext")
#define MKEXT_EXT_SIZE strlen(MKEXT_EXT)
#define KEXT_EXT ".kext"
#define KEXT_EXT_SIZE sizeof("kext")
#define KEXT_EXT_SIZE strlen(KEXT_EXT)
long flags;
long exttime;
branches/cparm/i386/boot2/boot.h
4545
4646
4747
48
49
5048
5149
5250
......
8381
8482
8583
86
87
88
89
90
9184
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
11385
11486
11587
kF10Key= 0x4400
};
/*
* Flags to the booter or kernel
*/
extern void common_boot(int biosdev);
extern BVRef getBvChain(void);
/*
* drivers.c
*/
extern long LoadDrivers(char * dirSpec);
extern long DecodeKernel(void *binary, entry_t *rentry, char **raddr, int *rsize);
typedef long (*FileLoadDrivers_t)(char *dirSpec, long plugin);
/*!
Hookable function pointer called during the driver loading phase that
allows other code to cause additional drivers to be loaded.
*/
//extern struct multiboot_info *gMI;
struct compressed_kernel_header {
u_int32_t signature;
u_int32_t compress_type;
u_int32_t adler32;
u_int32_t uncompressed_size;
u_int32_t compressed_size;
u_int32_t reserved[11];
char platform_name[PLATFORM_NAME_LEN];
char root_path[ROOT_PATH_LEN];
u_int8_t data[0];
};
typedef struct compressed_kernel_header compressed_kernel_header;
/*
* prompt.c
*/
branches/cparm/i386/boot2/drivers.c
9191
9292
9393
94
95
9496
9597
9698
......
156158
157159
158160
159
161
160162
161163
162164
......
165167
166168
167169
168
170
169171
170172
171173
......
176178
177179
178180
179
181
180182
181183
182184
......
185187
186188
187189
188
190
191
189192
190193
191
194
192195
193196
194197
......
206209
207210
208211
209
212
210213
211214
212215
......
810813
811814
812815
813
814
816
817
815818
816819
817820
818821
819822
820823
821
824
822825
823
826
824827
825828
826829
827830
828831
829
832
830833
831
834
832835
833836
834837
static char * gTempSpec;
static char * gFileName;
long LoadDrivers( char * dirSpec );
long DecodeKernel(void *binary, entry_t *rentry, char **raddr, int *rsize);
long InitDriverSupport(void);
long FileLoadDrivers(char *dirSpec, long plugin);
long LoadDriverMKext(char *fileSpec);
int step = 0;
execute_hook("ramDiskLoadDrivers", &step, NULL, NULL, NULL, NULL, NULL);
#ifdef NBP_SUPPORT
if ( gBootFileType == kNetworkDeviceType )
if ( get_env(envgBootFileType) == kNetworkDeviceType )
{
if (NetLoadDrivers(dirSpec) != 0) {
error("Could not load drivers from the network\n");
}
else
#endif
if ( gBootFileType == kBlockDeviceType )
if ( get_env(envgBootFileType) == kBlockDeviceType )
{
// First try to load Extra extensions from the ramdisk if isn't aliased as bt(0,0).
// First try a specfic OS version folder ie 10.5
sprintf(dirSpecExtra, "/Extra/%s/", (char*)gBootVolume->OSVersion);
sprintf(dirSpecExtra, "/Extra/%s/", (char*)((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion);
if (FileLoadDrivers(dirSpecExtra, 0) != 0)
{
// Next try to load Extra extensions from the selected root partition.
{
// If failed, then try to load Extra extensions from the boot partition
// in case we have a separate booter partition or a bt(0,0) aliased ramdisk.
if (!(gBIOSBootVolume->biosdev == gBootVolume->biosdev && gBIOSBootVolume->part_no == gBootVolume->part_no))
//if (!(gBIOSBootVolume->biosdev == gBootVolume->biosdev && gBIOSBootVolume->part_no == gBootVolume->part_no))
if (!((((BVRef)(uint32_t)get_env(envgBIOSBootVolume))->biosdev == ((BVRef)(uint32_t)get_env(envgBootVolume))->biosdev) && (((BVRef)(uint32_t)get_env(envgBIOSBootVolume))->part_no == ((BVRef)(uint32_t)get_env(envgBootVolume))->part_no)))
{
// First try a specfic OS version folder ie 10.5
sprintf(dirSpecExtra, "bt(0,0)/Extra/%s/", (char*)gBootVolume->OSVersion);
sprintf(dirSpecExtra, "bt(0,0)/Extra/%s/", (char*)((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion);
if (FileLoadDrivers(dirSpecExtra, 0) != 0)
{
// Next we'll try the base
#ifdef BOOT_HELPER_SUPPORT
// TODO: fix this, the order does matter, and it's not correct now.
// Also try to load Extensions from boot helper partitions.
if (gBootVolume->flags & kBVFlagBooter)
if (((BVRef)(uint32_t)get_env(envgBootVolume))->flags & kBVFlagBooter)
{
strlcpy(dirSpecExtra, "/com.apple.boot.P/System/Library/", sizeof(dirSpecExtra));
if (FileLoadDrivers(dirSpecExtra, 0) != 0)
printf("adler mismatch\n");
return -1;
}
char* BootKernelCacheFile = (char*)(uint32_t)get_env(envkCache);
if (((get_env(envgBootMode) & kBootModeSafe) == 0) && (BootKernelCacheFile[0] != '\0') && gBootVolume->OSVersion[3] > '6')
char* BootKernelCacheFile = (char*)(uint32_t)get_env(envkCacheFile);
if (((get_env(envgBootMode) & kBootModeSafe) == 0) && (BootKernelCacheFile[0] != '\0') && ((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] > '6')
safe_set_env(envAdler32, kernel_header->adler32);
}
{
unsigned long len;
ret = ThinFatFile(&binary, &len);
if (ret == 0 && len == 0 && archCpuType==CPU_TYPE_X86_64)
if ((ret == 0) && (len == 0) && (get_env(envarchCpuType)==CPU_TYPE_X86_64))
{
archCpuType=CPU_TYPE_I386;
safe_set_env(envarchCpuType, CPU_TYPE_I386);
ThinFatFile(&binary, &len);
}
ret = DecodeMachO(binary, rentry, raddr, rsize);
if (ret<0 && archCpuType==CPU_TYPE_X86_64)
if (ret<0 && get_env(envarchCpuType)==CPU_TYPE_X86_64)
{
archCpuType=CPU_TYPE_I386;
safe_set_env(envarchCpuType, CPU_TYPE_I386);
ret = DecodeMachO(binary, rentry, raddr, rsize);
}
}
branches/cparm/i386/boot2/drivers.h
4040
4141
4242
43
44
43
44
45
46
47
48
49
50
51
52
53
54
4555
56
57
58
59
60
4661
#include "xml.h"
#include "modules.h"
long LoadDrivers( char * dirSpec );
long DecodeKernel(void *binary, entry_t *rentry, char **raddr, int *rsize);
struct compressed_kernel_header {
u_int32_t signature;
u_int32_t compress_type;
u_int32_t adler32;
u_int32_t uncompressed_size;
u_int32_t compressed_size;
u_int32_t reserved[11];
char platform_name[PLATFORM_NAME_LEN];
char root_path[ROOT_PATH_LEN];
u_int8_t data[0];
};
typedef struct compressed_kernel_header compressed_kernel_header;
extern long LoadDrivers(char * dirSpec);
extern long DecodeKernel(void *binary, entry_t *rentry, char **raddr, int *rsize);
typedef long (*FileLoadDrivers_t)(char *dirSpec, long plugin);
#endif /* _BOOT2_DRIVERS_H */
branches/cparm/i386/boot2/options.c
585585
586586
587587
588
589
588
589
590
590591
591592
592593
......
690691
691692
692693
693
694
694695
695696
696697
......
745746
746747
747748
748
749
750
749751
750752
751753
......
889891
890892
891893
892
894
895
893896
894897
895898
......
904907
905908
906909
907
910
911
908912
909913
910914
......
914918
915919
916920
917
921
922
923
918924
919925
920926
......
992998
993999
9941000
995
1001
9961002
997
1003
9981004
999
1005
10001006
10011007
10021008
......
10041010
10051011
10061012
1007
1013
10081014
10091015
10101016
10111017
10121018
1013
1019
10141020
10151021
10161022
......
10591065
10601066
10611067
1062
1068
10631069
10641070
10651071
1066
1072
10671073
10681074
10691075
......
11201126
11211127
11221128
1123
1129
11241130
1131
11251132
11261133
11271134
int optionKey;
// Initialize default menu selection entry.
gBootVolume = menuBVR = selectBootVolume(getBvChain());
/*gBootVolume =*/ menuBVR = selectBootVolume(getBvChain());
safe_set_env(envgBootVolume, (uint32_t)menuBVR);
if (biosDevIsCDROM((int)get_env(envgBIOSDev))) {
isCDROM = true;
} else {
stop("Couldn't allocate memory for the device name\n"); //TODO: Find a better stategie
return -1;
}
getBootVolumeDescription(gBootVolume, name, 79, false);
getBootVolumeDescription(((BVRef)(uint32_t)get_env(envgBootVolume)), name, 79, false);
prompt = malloc(256);
if (!prompt) {
free(name);
// Look at partitions hosting OS X other than the CD-ROM
for (bvr = getBvChain(); bvr; bvr=bvr->next) {
if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != (int)get_env(envgBIOSDev)) {
gBootVolume = bvr;
//gBootVolume = bvr;
safe_set_env(envgBootVolume, (uint32_t)bvr);
}
}
}
showBootPrompt(nextRow, showPrompt);
break;
}
gBootVolume = menuBVR;
//gBootVolume = menuBVR;
safe_set_env(envgBootVolume, (uint32_t)menuBVR);
setRootVolume(menuBVR);
safe_set_env(envgBIOSDev,menuBVR->biosdev);
break;
// if the user enabled rescanning the optical drive.
// Otherwise boot the default boot volume.
if (get_env(envgEnableCDROMRescan)) {
gBootVolume = NULL;
//gBootVolume = NULL;
safe_set_env(envgBootVolume, (uint32_t)NULL);
clearBootArgs();
}
break;
scanDisks();
gBootVolume = NULL;
//gBootVolume = NULL;
safe_set_env(envgBootVolume, (uint32_t)NULL);
clearBootArgs();
break;
// Update the unit and partition number.
if ( gBootVolume )
if ( ((BVRef)(uint32_t)get_env(envgBootVolume)) )
{
if (!( gBootVolume->flags & kBVFlagNativeBoot ))
if (!( ((BVRef)(uint32_t)get_env(envgBootVolume))->flags & kBVFlagNativeBoot ))
{
readBootSector( gBootVolume->biosdev, gBootVolume->part_boff,
readBootSector( ((BVRef)(uint32_t)get_env(envgBootVolume))->biosdev, ((BVRef)(uint32_t)get_env(envgBootVolume))->part_boff,
(void *) 0x7c00 );
//
// foreign booter.
//
chainbootdev = gBootVolume->biosdev;
chainbootdev = ((BVRef)(uint32_t)get_env(envgBootVolume))->biosdev;
chainbootflag = 1;
return 1;
}
setRootVolume(gBootVolume);
setRootVolume(((BVRef)(uint32_t)get_env(envgBootVolume)));
}
// If no boot volume fail immediately because we're just going to fail
if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) {
safe_set_env(envgOverrideKernel,true);
}
} else if (gBootVolume->kernelfound == true) {
} else if (((BVRef)(uint32_t)get_env(envgBootVolume))->kernelfound == true) {
strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) );
} else {
printf("No kernel found on this volume : hd(%d,%d)\n", BIOS_DEV_UNIT(gBootVolume), gBootVolume->part_no);
printf("No kernel found on this volume : hd(%d,%d)\n", BIOS_DEV_UNIT(((BVRef)(uint32_t)get_env(envgBootVolume))), ((BVRef)(uint32_t)get_env(envgBootVolume))->part_no);
sleep(1);
return -1;
}
if(!get_env(envShouldboot))
{
gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, DEFAULT_BOOT_CONFIG ) ||
bool gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, DEFAULT_BOOT_CONFIG ) ||
getValueForKey( kSingleUserModeFlag, &val, &cnt, DEFAULT_BOOT_CONFIG );
safe_set_env(envgVerboseMode, gVerboseMode);
long gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, DEFAULT_BOOT_CONFIG ) ) ?
kBootModeSafe : kBootModeNormal;
branches/cparm/i386/boot2/Makefile
2727
2828
2929
30
30
3131
3232
3333
......
6868
6969
7070
71
71
7272
7373
7474
......
8080
8181
8282
83
83
8484
8585
8686
CFLAGS= $(RC_CFLAGS) $(OPTIM) $(MORECPP) -arch i386 -g -Wmost -Werror -fno-stack-protector \
-fno-builtin -DSAIO_INTERNAL_USER -static $(OMIT_FRAME_POINTER_CFLAG) \
-mpreferred-stack-boundary=2 -fno-align-functions \
-march=pentium4 -msse2 -mfpmath=sse -msoft-float
-march=pentium4 -msse2 -mfpmath=sse -msoft-float -Qunused-arguments -ffreestanding -DBOOT_CORE
DEFINES=
CONFIG = hd
BOOT2ADDR = 20200
MAXBOOTSIZE = 458240
#CFLAGS += -DSAFE_MALLOC
CFLAGS += -DSAFE_MALLOC
# CFLAGS += -DBOOT_HELPER_SUPPORT # +992 bytes
@echo "\t[LD] boot.sys"
@$(CC) -static -Wl,-preload -Wl,-segaddr,__INIT,$(BOOT2ADDR) \
-nostdlib -arch i386 -Wl,-segalign,20 \
-o $(SYMROOT)/boot.sys $(filter %.o,$^) $(LIBS) #-e boot2
-o $(SYMROOT)/boot.sys $(filter %.o,$^) $(LIBS) -e boot2
@echo "\t[MACHOCONV] boot"
@$(SYMROOT)/machOconv $(SYMROOT)/boot.sys $(SYMROOT)/boot &> /dev/null
branches/cparm/i386/modules/NetbookInstaller/NBI.c
129129
130130
131131
132
133
132
133
134
134135
135136
136137
......
208209
209210
210211
211
212
212213
213214
214215
......
218219
219220
220221
221
222
222223
223224
224225
......
227228
228229
229230
230
231
231232
232233
233234
}
// Force arch=i386 + -v
archCpuType = CPU_TYPE_I386;
gVerboseMode = true;
//archCpuType = CPU_TYPE_I386;
safe_set_env(envarchCpuType, CPU_TYPE_I386);
safe_set_env(envgVerboseMode, true);
}
}
int step = 0;
execute_hook("ramDiskLoadDrivers", &step, NULL, NULL, NULL, NULL, NULL);
#ifdef NBP_SUPPORT
if ( gBootFileType == kNetworkDeviceType )
if ( get_env(envgBootFileType) == kNetworkDeviceType )
{
if (NetLoadDrivers(dirSpec) != 0)
{
}
else
#endif
if ( gBootFileType == kBlockDeviceType )
if ( get_env(envgBootFileType) == kBlockDeviceType )
{
verbose("Loading Recovery Extensions\n");
strcpy(dirSpecExtra, "/Extra/RecoveryExtensions/");
#ifdef BOOT_HELPER_SUPPORT
// TODO: fix this, the order does matter, and it's not correct now.
// Also try to load Extensions from boot helper partitions.
if (gBootVolume->flags & kBVFlagBooter)
if (((BVRef)(uint32_t)get_env(envgBootVolume))->flags & kBVFlagBooter)
{
strcpy(dirSpecExtra, "/com.apple.boot.P/System/Library/");
if (FileLoadDrivers(dirSpecExtra, 0) != 0)
branches/cparm/i386/modules/RamDiskLoader/RamDiskLoader.c
1313
1414
1515
16
1617
1718
1819
......
6061
6162
6263
63
64
6465
6566
6667
......
7071
7172
7273
73
74
7475
7576
7677
#include "ramdisk.h"
#include "drivers.h"
#include "disk.h"
#include "platform.h"
void loadPrebootRAMDisk_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6);
break;
case 1:
// First try a specfic OS version folder ie 10.5
sprintf(dirSpecExtra, "rd(0,0)/Extra/%s/", (char*)gBootVolume->OSVersion);
sprintf(dirSpecExtra, "rd(0,0)/Extra/%s/", (char*)((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion);
if (FileLoadDrivers(dirSpecExtra, 0) != 0)
{
// Next we'll try the base
break;
case 2:
// First try a specfic OS version folder ie 10.5
sprintf(dirSpecExtra, "bt(0,0)/Extra/%s/", (char*)gBootVolume->OSVersion);
sprintf(dirSpecExtra, "bt(0,0)/Extra/%s/", (char*)((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion);
if (FileLoadDrivers(dirSpecExtra, 0) != 0)
{
// Next we'll try the base
branches/cparm/i386/modules/RamDiskLoader/ramdisk.c
393393
394394
395395
396
397
396398
397399
398400
......
405407
406408
407409
408
409
410
410
411
412
413
414
415
416
417
418
411419
412
413
414
415
416
417
420
421
418422
419423
420424
{
char extensionsSpec[1024];
int ramdiskUnit;
long ret, flags, cachetime;
for(ramdiskUnit = 0; ramdiskUnit < gRAMDiskMI->mi_mods_count; ++ramdiskUnit)
{
int partCount; // unused
for(; ramdiskChain != NULL; ramdiskChain = ramdiskChain->next)
{
sprintf(extensionsSpec, "rd(%d,%d)/Extra/", ramdiskUnit, ramdiskChain->part_no);
struct dirstuff *extradir = opendir(extensionsSpec);
closedir(extradir);
if(extradir != NULL)
ret = GetFileInfo(NULL, extensionsSpec, &flags, &cachetime);
if (!ret) continue;
if (((flags & kFileTypeMask) != kFileTypeDirectory)) continue;
ret = FileLoadDrivers_p(extensionsSpec, 0 /* this is a kext root dir, not a kext with plugins */);
if(ret != 0)
{
int ret = FileLoadDrivers_p(extensionsSpec, 0 /* this is a kext root dir, not a kext with plugins */);
if(ret != 0)
{
verbose("FileLoadDrivers failed on a ramdisk\n");
return ret;
}
verbose("FileLoadDrivers failed on a ramdisk\n");
return ret;
}
}
}
branches/cparm/i386/modules/GUI/gui.c
319319
320320
321321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
322405
323406
324407
......
10351118
10361119
10371120
1038
1039
1040
1121
10411122
10421123
10431124
......
26532734
26542735
26552736
2656
2657
2737
2738
26582739
26592740
26602741
{
setCursorPosition( col, row, 0 );
}
/*
*
*/
bool getDimensionForKey( const char *key, unsigned int *value, config_file_t *config, unsigned int dimension_max, unsigned int object_size )
{
const char *val;
int size = 0;
int sum = 0;
bool negative = false;
bool percentage = false;
config = resolveConfig(config);
if (getValueForKey(key, &val, &size, config))
{
if ( size )
{
if (*val == '-')
{
negative = true;
val++;
size--;
}
if (val[size-1] == '%')
{
percentage = true;
size--;
}
// convert string to integer
for (sum = 0; size > 0; size--)
{
if (*val < '0' || *val > '9')
return false;
sum = (sum * 10) + (*val++ - '0');
}
if (percentage)
sum = ( dimension_max * sum ) / 100;
// calculate offset from opposite origin
if (negative)
sum = ( ( dimension_max - object_size ) - sum );
} else {
// null value calculate center
sum = ( dimension_max - object_size ) / 2;
}
*value = (uint16_t) sum;
return true;
}
// key not found
return false;
}
static bool getColorForKey( const char *key, unsigned int *value, config_file_t *config )
{
const char *val;
int size;
config = resolveConfig(config);
if (getValueForKey(key, &val, &size, config))
{
if (*val == '#')
{
val++;
*value = strtol(val, NULL, 16);
return true;
}
}
return false;
}
//==========================================================================
/* Flush keyboard buffer; returns TRUE if any of the flushed
if (i) {
srand (time18());
uint8_t choosen = rand() % i;
uint8_t choosen = arc4random_uniform(i+1);
themeList_t* entry = themeList;
position_t p = pos( gui.screen.width / 2 + 1 , ( gui.devicelist.pos.y + 3 ) + ( ( gui.devicelist.height - gui.devicelist.iconspacing ) / 2 ) );
char dummy[80];
getBootVolumeDescription( gBootVolume, dummy, sizeof(dummy) - 1, true );
drawDeviceIcon( gBootVolume, gui.screen.pixmap, p, true );
getBootVolumeDescription( ((BVRef)(uint32_t)get_env(envgBootVolume)), dummy, sizeof(dummy) - 1, true );
drawDeviceIcon( ((BVRef)(uint32_t)get_env(envgBootVolume)), gui.screen.pixmap, p, true );
drawStrCenteredAt( (char *) msg, &font_small, gui.screen.pixmap, gui.countdown.pos );
// make this screen the new background
branches/cparm/i386/modules/GUI/GUI_module.c
9696
9797
9898
99
10099
101100
102101
......
106105
107106
108107
109
110
111108
112109
113110
......
179176
180177
181178
182
179
183180
184181
185182
......
212209
213210
214211
215
212
216213
217214
218215
......
247244
248245
249246
250
251247
252248
253249
......
373369
374370
375371
376
372
377373
378374
379375
380376
381377
382
378
383379
384380
385381
386382
387383
388
384
389385
390386
391387
392388
393389
394
390
395391
396392
397393
......
703699
704700
705701
706
707
702
703
704
708705
709706
710707
......
831828
832829
833830
834
831
835832
836833
837834
......
892889
893890
894891
895
892
893
896894
897895
898896
......
10971095
10981096
10991097
1100
1098
1099
11011100
11021101
11031102
......
11121111
11131112
11141113
1115
1114
1115
11161116
11171117
11181118
......
11241124
11251125
11261126
1127
1127
1128
1129
11281130
11291131
11301132
......
12021204
12031205
12041206
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
12261207
12271208
12281209
12291210
12301211
12311212
1232
1213
12331214
12341215
12351216
......
12441225
12451226
12461227
1247
1228
12481229
12491230
1250
1231
12511232
1252
1233
12531234
12541235
1255
1236
12561237
12571238
12581239
......
12781259
12791260
12801261
1281
1262
12821263
12831264
1284
1265
12851266
1286
1267
12871268
12881269
1289
1270
12901271
12911272
12921273
int GUI_printf(const char * fmt, ...);
int GUI_verbose(const char * fmt, ...);
int GUI_error(const char * fmt, ...);
void GUI_stop(const char * fmt, ...);
char * last_str;
};
void sputc(int c, struct putc_info * pi);
extern char *msgbuf;
extern char *cursor;
static void (*showTextBuffer)(char *, int ) = NULL;
static char *(*getMemoryInfoString)(void) = NULL;
**/
void GUI_ExecKernel_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)
{
if(!gVerboseMode)
if(!get_env(envgVerboseMode))
{
// Note: shouldn't be needed, but just in case
drawBootGraphics();
drawBackground();
updateVRAM();
if(!gVerboseMode)
if(!get_env(envgVerboseMode))
{
// Disable outputs, they will still show in the boot log.
replace_system_function("_printf", &GUI_verbose);
replace_system_function("_printf", &GUI_printf);
replace_system_function("_verbose", &GUI_verbose);
replace_system_function("_error", &GUI_error);
replace_system_function("_stop", &GUI_stop);
replace_system_function("_showMessage", &GUI_showMessage);
switch (res)
{
case BOOT_NORMAL:
gVerboseMode = false;
safe_set_env(envgVerboseMode, false);
safe_set_env(envgBootMode, kBootModeNormal);
break;
case BOOT_VERBOSE:
gVerboseMode = true;
safe_set_env(envgVerboseMode, true);
safe_set_env(envgBootMode, kBootModeNormal);
GUI_addBootArg(kVerboseModeFlag);
break;
case BOOT_IGNORECACHE:
gVerboseMode = false;
safe_set_env(envgVerboseMode, false);
safe_set_env(envgBootMode, kBootModeNormal);
GUI_addBootArg(kIgnoreCachesFlag);
break;
case BOOT_SINGLEUSER:
gVerboseMode = true;
safe_set_env(envgVerboseMode, true);
safe_set_env(envgBootMode, kBootModeNormal);
GUI_addBootArg(kSingleUserModeFlag);
break;
int devcnt = (int)get_env(envgDeviceCount);
// Initialize default menu selection entry.
gBootVolume = menuBVR = selectBootVolume(getBvChain());
/*gBootVolume =*/ menuBVR = selectBootVolume(getBvChain());
safe_set_env(envgBootVolume, (uint32_t)menuBVR);
if (biosDevIsCDROM((int)get_env(envgBIOSDev)))
{
isCDROM = true;
stop("Couldn't allocate memory for the device name\n"); //TODO: Find a better stategie
return -1;
}
getBootVolumeDescription(gBootVolume, name, 79, false);
getBootVolumeDescription(((BVRef)(uint32_t)get_env(envgBootVolume)), name, 79, false);
prompt = malloc(256);
if (!prompt) {
free(name);
// Look at partitions hosting OS X other than the CD-ROM
for (bvr = getBvChain(); bvr; bvr=bvr->next) {
if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != (int)get_env(envgBIOSDev)) {
gBootVolume = bvr;
//gBootVolume = bvr;
safe_set_env(envgBootVolume, (uint32_t)bvr);
}
}
}
GUI_showBootPrompt(nextRow, showPrompt);
break;
}
gBootVolume = menuBVR;
//gBootVolume = menuBVR;
safe_set_env(envgBootVolume, (uint32_t)menuBVR);
setRootVolume(menuBVR);
safe_set_env(envgBIOSDev,menuBVR->biosdev);
break;
// if the user enabled rescanning the optical drive.
// Otherwise boot the default boot volume.
if (get_env(envgEnableCDROMRescan)) {
gBootVolume = NULL;
//gBootVolume = NULL;
safe_set_env(envgBootVolume, (uint32_t)NULL);
GUI_clearBootArgs();
}
break;
#else
scanDisks();
#endif
gBootVolume = NULL;
//gBootVolume = NULL;
safe_set_env(envgBootVolume, (uint32_t)NULL);
GUI_clearBootArgs();
break;
return 0;
}
int GUI_error(const char * fmt, ...)
{
va_list ap;
gErrors = true;
va_start(ap, fmt);
if (getVideoMode() == VGA_TEXT_MODE)
{
prf(fmt, ap, putchar, 0);
}
else
{
vprf(fmt, ap);
}
va_end(ap);
return(0);
}
int GUI_verbose(const char * fmt, ...)
{
va_list ap;
va_start(ap, fmt);
if (gVerboseMode && (KernelStart == false))
if (get_env(envgVerboseMode) && (KernelStart == false))
{
if (getVideoMode() == VGA_TEXT_MODE)
{
/* Kabyl: BooterLog */
struct putc_info pi;
if (!msgbuf)
if (!getConsoleMsg())
return 0;
if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
if (((getConsoleCursor() - getConsoleMsg()) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
return 0;
pi.str = cursor;
pi.str = getConsoleCursor();
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
cursor += strlen((char *)cursor);
setConsoleCursor(getConsoleCursor() + strlen(getConsoleCursor()));
va_end(ap);
/* Kabyl: BooterLog */
struct putc_info pi;
if (!msgbuf)
if (!getConsoleMsg())
return 0;
if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
if (((getConsoleCursor() - getConsoleMsg()) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
return 0;
pi.str = cursor;
pi.str = getConsoleCursor();
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
cursor += strlen((char *)cursor);
setConsoleCursor(getConsoleCursor() + strlen(getConsoleCursor()));
va_end(ap);
return 0;
branches/cparm/i386/modules/GUI/graphic_utils.c
99
1010
1111
12
1213
1314
1415
......
682683
683684
684685
685
686
686687
687688
688689
#include "appleClut8.h"
#include "vbe.h"
#include "gui.h"
#include "platform.h"
#define VIDEO(x) (((boot_args_common*)getBootArgs())->Video.v_ ## x)
if ( mode == GRAPHICS_MODE )
{
if ( (err=GUI_initGraphicsMode ()) == errSuccess ) {
if (gVerboseMode) {
if (get_env(envgVerboseMode)) {
// Tell the kernel to use text mode on a linear frame buffer display
setBootArgsVideoMode(FB_TEXT_MODE);
branches/cparm/i386/modules/SMBiosGetters/mysmbios.c
535535
536536
537537
538
539
540
541
542
543538
539
540
541
542
544543
545544
546545
......
566565
567566
568567
569
570
571
572
568
569
573570
574571
575572
......
595592
596593
597594
598
599
600
601595
596
597
602598
603599
604600
......
622618
623619
624620
625
626
627
628621
622
623
629624
630625
631626
int rand_sn1 ;
int rand_sn2 ;
int rand_sn3 ;
struct ran_obj* random_serial_obj = random_init(0,35);
rand_sn1 = random(random_serial_obj);
rand_sn2 = random(random_serial_obj);
rand_sn3 = random(random_serial_obj);
random_free(random_serial_obj);
rand_sn1 = arc4random_unirange(0,35);
rand_sn2 = arc4random_unirange(0,35);
rand_sn3 = arc4random_unirange(0,35);
// Append all charaters to the string
char tmp[2];
bzero(tmp,sizeof(tmp));
{
// Get randomized characters
int rand_week ;
struct ran_obj* random_week_obj = random_init(0,47)/* random_init(1,48) */;
rand_week = random(random_week_obj);
random_free(random_week_obj);
rand_week = arc4random_unirange(0,47);
// Append all charaters to the string
char tmp[3];
bzero(tmp,sizeof(tmp));
{
// Get randomized characters
int rand_year ;
struct ran_obj* random_year_obj = random_init(0,9);
rand_year = random(random_year_obj);
random_free(random_year_obj);
rand_year = arc4random_unirange(0,9);
// Append all charaters to the string
char tmp[2];
bzero(tmp,sizeof(tmp));
// Get randomized characters
int rand_country ;
struct ran_obj* random_country_obj = random_init(0,(sizeof(sm_country_list) / sizeof(sm_country_list[0]))-1);
rand_country = random(random_country_obj);
random_free(random_country_obj);
rand_country = arc4random_unirange(0,(sizeof(sm_country_list) / sizeof(sm_country_list[0]))-1);
strlcpy (str, sm_country_list[rand_country].code,strlen(sm_country_list[rand_country].code)+1);
DBG ("fake_country: %s (%s)\n",str,sm_country_list[rand_country].info);
branches/cparm/i386/modules/HibernateEnabler/resume.c
297297
298298
299299
300
300
301301
302302
303303
IOHibernateImageHeader * header = &_header;
long buffer;
if(gBootVolume->OSVersion[3] >= '7') // TODO: unlocked, but please check the compatibility with the 10.8
if(((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] >= '7') // TODO: unlocked, but please check the compatibility with the 10.8
{
HibernateBoot107(image_filename);
return;
branches/cparm/i386/modules/HibernateEnabler/graphic_utils.c
1010
1111
1212
13
1314
14
1515
1616
1717
......
482482
483483
484484
485
485
486486
487487
488488
#include "bmdecompress.h"
#include "vbe.h"
#include "appleClut8.h"
#include "platform.h"
#ifndef offsetof
#define offsetof(st, m) \
((size_t) ( (char *)&((st *)(0))->m - (char *)0 ))
if ( mode == GRAPHICS_MODE )
{
if ( (err=initGraphicsMode ()) == errSuccess ) {
if (gVerboseMode) {
if (get_env(envgVerboseMode)) {
// Tell the kernel to use text mode on a linear frame buffer display
setBootArgsVideoMode(FB_TEXT_MODE);
} else {
branches/cparm/i386/modules/Keymapper/Keylayout.c
2525
2626
2727
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
2844
2945
3046
......
99115
100116
101117
102
118
103119
104120
105121
#define kKeyboardLayout "KeyboardLayout"
//==========================================================================
// lseek() - Reposition the byte offset of the file descriptor from the
// beginning of the file. Returns the relocated offset.
int key_b_lseek(int fdesc, int offset, int ptr)
{
struct iob * io;
if ((io = iob_from_fdesc(fdesc)) == NULL)
return (-1);
io->i_offset = offset;
return offset;
}
struct keyboard_layout *current_layout = NULL;
int getchar_replacement(void);
if (!current_layout)
goto fail;
b_lseek(fd, KEYBOARD_LAYOUTS_MAP_OFFSET, 0);
key_b_lseek(fd, KEYBOARD_LAYOUTS_MAP_OFFSET, 0);
if (read(fd, (char*) current_layout, sizeof(*current_layout)) != sizeof(*current_layout)) {
printf("Wrong keyboard layout file %s size\n", filename);
branches/cparm/i386/modules/SMBiosPatcher/smbios_patcher.c
305305
306306
307307
308
309
310
311
312
313308
309
310
311
312
314313
315314
316315
......
336335
337336
338337
339
340
341
342
338
339
343340
344341
345342
......
365362
366363
367364
368
369
370
371365
366
367
372368
373369
374370
......
392388
393389
394390
395
396
397
398391
392
393
399394
400395
401396
int rand_sn1 ;
int rand_sn2 ;
int rand_sn3 ;
struct ran_obj* random_serial_obj = random_init(0,35);
rand_sn1 = random(random_serial_obj);
rand_sn2 = random(random_serial_obj);
rand_sn3 = random(random_serial_obj);
random_free(random_serial_obj);
rand_sn1 = arc4random_unirange(0,35);
rand_sn2 = arc4random_unirange(0,35);
rand_sn3 = arc4random_unirange(0,35);
// Append all charaters to the string
char tmp[2];
bzero(tmp,sizeof(tmp));
{
// Get randomized characters
int rand_week ;
struct ran_obj* random_week_obj = random_init(0,47)/* random_init(1,48) */;
rand_week = random(random_week_obj);
random_free(random_week_obj);
rand_week = arc4random_unirange(0,47);
// Append all charaters to the string
char tmp[3];
bzero(tmp,sizeof(tmp));
{
// Get randomized characters
int rand_year ;
struct ran_obj* random_year_obj = random_init(0,9);
rand_year = random(random_year_obj);
random_free(random_year_obj);
rand_year = arc4random_unirange(0,9);
// Append all charaters to the string
char tmp[2];
bzero(tmp,sizeof(tmp));
// Get randomized characters
int rand_country ;
struct ran_obj* random_country_obj = random_init(0,(sizeof(sm_country_list) / sizeof(sm_country_list[0]))-1);
rand_country = random(random_country_obj);
random_free(random_country_obj);
rand_country = arc4random_unirange(0,(sizeof(sm_country_list) / sizeof(sm_country_list[0]))-1);
strlcpy (str, sm_country_list[rand_country].code,strlen(sm_country_list[rand_country].code)+1);
DBG ("fake_country: %s (%s)\n",str,sm_country_list[rand_country].info);
branches/cparm/i386/modules/Memory/Makefile
1010
1111
1212
13
13
1414
1515
1616
......
9898
9999
100100
101
102
101103
102104
103105
BUNDLE_LIBS =
BUNDLE_INFO =
BUNDLE_ID = com.boot.SMBIOS.SMBIOSPLATFORM.MEMORY.memory
BUNDLE_COPYRIGHT =
BUNDLE_COPYRIGHT = GPL V2.0
BUNDLE_LICENCE =
BUNDLE_VERSION = 1.0
BUNDLE_ICON =
@mkdir $(SYMROOT)/$(BUNDLE_NAME).bundle/Contents/PlugIns
@mv $(SYMROOT)/$(BUNDLE_EXEC) $(SYMROOT)/$(BUNDLE_NAME).bundle/Contents/MacOS
@#mv $(SYMROOT)/$(SYMBOLS_BUNDLE_LIBS) $(SYMROOT)/$(BUNDLE_NAME).bundle/Contents/PlugIns
@cp GPL_V2_LICENSE $(SYMROOT)/$(BUNDLE_NAME).bundle/Contents/Resources
@cp MEMTEST86_LICENSE $(SYMROOT)/$(BUNDLE_NAME).bundle/Contents/Resources
@defaults write $(SYMROOT)/$(BUNDLE_NAME).bundle/Contents/Info "CFBundleGetInfoString" '$(BUNDLE_INFO)'
@defaults write $(SYMROOT)/$(BUNDLE_NAME).bundle/Contents/Info "NSHumanReadableCopyright" '$(BUNDLE_COPYRIGHT)'
branches/cparm/i386/modules/Memory/README
1
1
22
3
3
44
55
66
Memory.dylib is a module for Chameleon (the Darwin/XNU boot loader based on Apple's boot-132).
Memory is a module for Chameleon (the Darwin/XNU boot loader based on Apple's boot-132).
Memory.dylib can be freely distributed under the term of the GPL V2 license.
Memory can be freely distributed under the term of the GPL V2 license.
see GPL_V2_LICENSE and MEMTEST86_LICENSE for more informations.
branches/cparm/i386/modules/ACPICodec/acpi_codec.c
9494
9595
9696
97
97
9898
9999
100100
......
557557
558558
559559
560
560
561561
562562
563563
......
567567
568568
569569
570
570
571571
572572
573573
......
47434743
47444744
47454745
4746
4747
4748
4749
4746
4747
4748
4749
47504750
47514751
47524752
......
47824782
47834783
47844784
4785
4786
4785
47874786
4788
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
47894802
4790
4803
4804
4805
4806
47914807
47924808
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4809
4810
4811
4812
4813
48254814
4826
4827
4828
4829
4830
4815
48314816
4832
4833
4817
4818
48344819
4835
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
48364830
4837
4838
4839
4840
4841
4842
4843
4831
4832
4833
4834
4835
4836
4837
4838
4839
48444840
4841
4842
4843
4844
4845
4846
48454847
4846
4847
4848
4848
4849
4850
4851
4852
4853
4854
48494855
48504856
48514857
static ACPI_TABLE_RSDT * gen_alloc_rsdt_from_xsdt(ACPI_TABLE_XSDT *xsdt);
static ACPI_TABLE_XSDT * gen_alloc_xsdt_from_rsdt(ACPI_TABLE_RSDT *rsdt);
static void MakeAcpiSgn(void);
static void *loadACPITable(U32 *new_table_list, char *dirspec, char *filename );
static void *loadACPITable(U32 *new_table_list, char *dirspec, const char *filename );
static int generate_cpu_map_from_acpi(ACPI_TABLE_DSDT * DsdtPointer);
static ACPI_GENERIC_ADDRESS FillGASStruct(U32 Address, U8 Length);
static U32 process_xsdt (ACPI_TABLE_RSDP *rsdp_mod , U32 *new_table_list);
}
static void *loadACPITable(U32 *new_table_list, char *dirspec, char *filename )
static void *loadACPITable(U32 *new_table_list, char *dirspec, const char *filename )
{
int fd = -1;
char acpi_file[512];
sprintf(acpi_file, "%s%s",dirspec, filename);
HFSLoadVerbose = 0;
safe_set_env(envHFSLoadVerbose, 0);
fd=open(acpi_file);
if (fd<0)
}
{
char* name;
long flags;
long time;
long ret = -1;
long ret, length, flags, time;
long long index = 0;
const char * name;
U8 i = 0;
char dirspec[512];
bool acpidir_found = false;
if (acpidir_found == true)
{
struct dirstuff* AcpiDir = opendir(dirspec);
if (AcpiDir != NULL)
if (checkOem == true)
{
if (checkOem == true)
MakeAcpiSgn();
}
while (1) {
ret = GetDirEntry(dirspec, &index, &name, &flags, &time);
if (ret == -1) break;
#if DEBUG_ACPI
printf("testing %s\n", name);
#endif
// Make sure this is a directory.
if ((flags & kFileTypeMask) == kFileTypeDirectory) continue;
// Make sure this is a kext.
length = strlen(name);
if (strcmp(name + length - 4, ".aml"))
{
MakeAcpiSgn();
#if DEBUG_ACPI
printf("Ignoring %s\n", name);
#endif
continue;
}
while(readdir(AcpiDir, (const char**)&name, &flags, &time) >= 0)
{
if((strstr(name, ".aml")) && ((strlen(dirspec)+strlen(name)) < 512))
{
// Some simple verifications to save time in case of those tables simply named as follow:
if ((strncmp(name, "RSDT", 4) == 0) || (strncmp(name, "rsdt", 4) == 0) ||
(strncmp(name, "XSDT", 4) == 0) || (strncmp(name, "xsdt", 4) == 0) ||
(strncmp(name, "RSDP", 4) == 0) || (strncmp(name, "rsdp", 4) == 0))
{
continue;
}
if ((strncmp(name, "FACS", 4) == 0) || (strncmp(name, "facs", 4) == 0)) // FACS is not supported
{
continue;
}
DBG("* Attempting to load acpi table: %s\n", name);
if ( (new_table_list[i]=(U32)loadACPITable(new_table_list,dirspec,name)))
{
if (i < MAX_ACPI_TABLE)
{
i++;
}
else
{
DBG("Max nb of allowed aml files reached, exiting .");
break;
}
}
}
// Some simple verifications to save time in case of those tables simply named as follow:
if ((strncmp(name, "RSDT", 4) == 0) || (strncmp(name, "rsdt", 4) == 0) ||
(strncmp(name, "XSDT", 4) == 0) || (strncmp(name, "xsdt", 4) == 0) ||
(strncmp(name, "RSDP", 4) == 0) || (strncmp(name, "rsdp", 4) == 0))
{
#if DEBUG_ACPI
else
{
printf("Ignoring %s\n", name);
}
printf("Ignoring %s\n", name);
#endif
}
continue;
}
if (i)
if ((strncmp(name, "FACS", 4) == 0) || (strncmp(name, "facs", 4) == 0)) // FACS is not supported
{
#if DEBUG_ACPI
printf("Ignoring %s\n", name);
#endif
continue;
}
DBG("* Attempting to load acpi table: %s\n", name);
if ( (new_table_list[i]=(U32)loadACPITable(new_table_list,dirspec,name)))
{
//sanitize the new tables list
sanitize_new_table_list(new_table_list);
//move to kernel memory
move_table_list_to_kmem(new_table_list);
DBG("New ACPI tables Loaded in memory\n");
if (i < MAX_ACPI_TABLE)
{
i++;
}
else
{
DBG("Max nb of allowed aml files reached, exiting .");
break;
}
}
}
if (i)
{
//sanitize the new tables list
sanitize_new_table_list(new_table_list);
closedir(AcpiDir);
}
//move to kernel memory
move_table_list_to_kmem(new_table_list);
DBG("New ACPI tables Loaded in memory\n");
}
}
}
branches/cparm/i386/modules/Makefile
2626
2727
2828
29
29
3030
3131
3232
VPATH = $(OBJROOT):$(SYMROOT)
# The order of building is important.
SUBDIRS = HelloWorld KernelPatcher USBFix Networking HPET NetbookInstaller CPUfreq Keymapper YellowIconFixer ACPICodec ACPIPatcher GraphicsEnabler Memory RamDiskLoader SMBiosPatcher SMBiosGetters GUI HibernateEnabler
SUBDIRS = lua HelloWorld KernelPatcher USBFix Networking HPET NetbookInstaller CPUfreq Keymapper YellowIconFixer ACPICodec ACPIPatcher GraphicsEnabler Memory RamDiskLoader SMBiosPatcher SMBiosGetters GUI HibernateEnabler
all embedtheme tags debug install installhdrs:
@rm -rf $(OBJROOT)
@mkdir $(OBJROOT)
branches/cparm/i386/libsa/rand.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
*
* rand & srand implementation for chameleon by Cadet-petit Armel <armelcadetpetit@gmail.com>
*/
#include "libsa.h"
static long holdrand = 1L;
#defineRAND_MAX0x7fffffff
void srand (unsigned int seed)
{
holdrand = (long)seed;
}
int rand (void)
{
holdrand = holdrand * 214013L + 2531011L;
return ((holdrand >> 16) & RAND_MAX);
}
branches/cparm/i386/libsa/libsa.h
102102
103103
104104
105
106
107105
108106
109107
......
130128
131129
132130
133
134
135
136
131
132
133
134
137135
136
138137
139138
140139
extern unsigned long
adler32( unsigned char * buffer, long length );
extern void * bsearch(register const void *key,const void *base0,size_t nmemb,register size_t size,register int (*compar)(const void *, const void *));
extern int rand (void);
extern void srand (unsigned int seed);
/*
* strtol.c
*/
extern void free(void * start);
extern void * realloc(void * ptr, size_t size);
//#if SAFE_MALLOC
//extern size_t zalloced_size;
//#endif
#ifdef SAFE_MALLOC
extern size_t zalloced_size;
extern void malloc_init(char * start, int size, int nodes, void (*malloc_err_fn)(char *, size_t, const char *, int));
#else
extern void malloc_init(char * start, int size, int nodes, void (*malloc_error)(char *, size_t));
#endif
extern void * malloc(size_t size);
#endif /* !__BOOT_LIBSA_H */
branches/cparm/i386/libsa/string.c
206206
207207
208208
209
209
210210
211211
212212
......
219219
220220
221221
222
222
223223
224224
225225
......
239239
240240
241241
242
242
243243
244244
245245
......
276276
277277
278278
279
279
280280
281281
282282
......
351351
352352
353353
354
354
355355
356356
357357
......
371371
372372
373373
374
374
375375
376376
377377
......
406406
407407
408408
409
409410
410411
411412
......
564565
565566
566567
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581568
582569
583570
......
668655
669656
670657
671
658
bcopy(src, dst, ulen);
return dst;
}
#if UNUSED
int
ptol(const char *str)
{
else c = 0;
return c;
}
#endif
/*
* atoi:
*
return( number );
}
#if UNUSED
/*
* convert an integer to an ASCII string.
* inputs:
return str;
}
#endif
/*
* Appends src to string dst of size siz (unlike strncat, siz is the
* full size of dst, not space left). At most siz-1 characters
{
return (size_t)_mach_strlen(str);
}
#if UNUSED
/*
* Does the same thing as strlen, except only looks up
* to max chars inside the buffer.
return p - s;
}
#endif
/*
* Deprecation Warning:
*strcat() is being deprecated. Please use strlcat() instead.
* NULLIf MALLOC() fails.
*
*/
static char *
STRDUP(const char *string)
{
return result;
}
static long holdrand = 1L;
#defineRAND_MAX0x7fffffff
void srand (unsigned int seed)
{
holdrand = (long)seed;
}
int rand (void)
{
holdrand = holdrand * 214013L + 2531011L;
return ((holdrand >> 16) & RAND_MAX);
}
/*-
* For memcmp, bsearch.
* Copyright (c) 1990, 1993
}/* else move left */
}
return (NULL);
}
}
branches/cparm/i386/libsa/zalloc.c
399399
400400
401401
402
403
404
405402
406
403
407404
408405
409406
{
if (!start || !(newsize>0)) return NULL;
#ifdef SAFE_MALLOC
void * newstart = safe_malloc(newsize, __FILE__, __LINE__);
#else
void * newstart = malloc(newsize);
#endif
if (newstart) {
bcopy(start, newstart, newsize);
}
branches/cparm/i386/libsa/strtol.c
254254
255255
256256
257
257
258258
259259
260260
......
334334
335335
336336
337
return (acc);
}
#if UNUSED
/*
* Convert a string to an unsigned quad integer.
*
return (acc);
}
#endif
branches/cparm/i386/libsa/Makefile
1010
1111
1212
13
13
1414
1515
1616
......
4242
4343
4444
45
45
4646
4747
4848
OPTIM = -Os -Oz
CFLAGS= $(RC_CFLAGS) $(OPTIM) $(MORECPP) -arch i386 -g -Wmost -Werror -fno-stack-protector \
-fno-builtin -static $(OMIT_FRAME_POINTER_CFLAG) \
-march=pentium4 -msse2 -msoft-float -ffreestanding -mpreferred-stack-boundary=2 -fno-align-functions -mfpmath=sse
-march=pentium4 -msse2 -msoft-float -Qunused-arguments -ffreestanding -DBOOT_CORE -mpreferred-stack-boundary=2 -fno-align-functions -mfpmath=sse
INC = -I. -I$(SYMROOT) -I$(UTILDIR) -I$(LIBSAIODIR)
ifneq "" "$(wildcard /bin/mkdirs)"
LIBS = libsa.a
DIRS_NEEDED = $(OBJROOT) $(SYMROOT)
#CFLAGS += -DSAFE_MALLOC
CFLAGS += -DSAFE_MALLOC
all embedtheme: $(DIRS_NEEDED) $(LIBS)
branches/cparm/i386/util/rand-fbsd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*-
* Copyright (c) 1990, 1993
*The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Posix rand_r function added May 1999 by Wes Peters <wes@softweyr.com>.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)rand.c8.1 (Berkeley) 6/14/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: src/lib/libc/stdlib/rand.c,v 1.17 2007/12/11 20:39:32 ache Exp $");
#ifdef TEST
#include <stdio.h>
#else
#include "libsaio.h"
#endif /* TEST */
static int
do_rand(unsigned long *ctx)
{
#ifdef USE_WEAK_SEEDING
/*
* Historic implementation compatibility.
* The random sequences do not vary much with the seed,
* even with overflowing.
*/
return ((*ctx = *ctx * 1103515245 + 12345) % ((u_long)RAND_MAX + 1));
#else /* !USE_WEAK_SEEDING */
/*
* Compute x = (7^5 * x) mod (2^31 - 1)
* without overflowing 31 bits:
* (2^31 - 1) = 127773 * (7^5) + 2836
* From "Random number generators: good ones are hard to find",
* Park and Miller, Communications of the ACM, vol. 31, no. 10,
* October 1988, p. 1195.
*/
long hi, lo, x;
/* Can't be initialized with 0, so use another value. */
if (*ctx == 0)
*ctx = 123459876;
hi = *ctx / 127773;
lo = *ctx % 127773;
x = 16807 * lo - 2836 * hi;
if (x < 0)
x += 0x7fffffff;
return ((*ctx = x) % ((u_long)RAND_MAX + 1));
#endif /* !USE_WEAK_SEEDING */
}
int
rand_r(unsigned int *ctx)
{
u_long val = (u_long) *ctx;
int r = do_rand(&val);
*ctx = (unsigned int) val;
return (r);
}
static u_long next = 1;
int
rand()
{
return (do_rand(&next));
}
void
srand(seed)
u_int seed;
{
next = seed;
}
#ifdef TEST
main()
{
int i;
unsigned myseed;
printf("seeding rand with 0x19610910: \n");
srand(0x19610910);
printf("generating three pseudo-random numbers:\n");
for (i = 0; i < 3; i++)
{
printf("next random number = %d\n", rand());
}
printf("generating the same sequence with rand_r:\n");
myseed = 0x19610910;
for (i = 0; i < 3; i++)
{
printf("next random number = %d\n", rand_r(&myseed));
}
return 0;
}
#endif /* TEST */
branches/cparm/i386/util/utstring.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
Copyright (c) 2008-2012, Troy D. Hanson http://uthash.sourceforge.net
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* a dynamic string implementation using macros
* see http://uthash.sourceforge.net/utstring
*/
#ifndef UTSTRING_H
#define UTSTRING_H
#define UTSTRING_VERSION 1.9.6
#ifdef __GNUC__
#define _UNUSED_ __attribute__ ((__unused__))
#else
#define _UNUSED_
#endif
#include "libsaio.h"
#ifndef utstring_oom
#define utstring_oom() longjmp(THIS_BUF_ERROR,-1)
#endif
#ifndef __utstring_malloc
#define __utstring_malloc(sz) pool_alloc(THIS_POOL,sz) /* malloc fcn */
#endif
#ifndef __utstring_free
#define __utstring_free(ptr) pool_free(THIS_POOL,ptr) /* free fcn */
#endif
#ifndef __utarray_realloc
#define __utarray_realloc(ptr,sz) pool_realloc(THIS_POOL,nmemb,sz) /* realloc fcn */
#endif
#ifndef __utarray_calloc
#define __utarray_calloc(n,sz) pool_calloc(THIS_POOL,n,sz) /* calloc fcn */
#endif
typedef struct {
char *d;
size_t n; /* allocd size */
size_t i; /* index of first unused byte */
} UT_string;
#define utstring_reserve(s,amt) \
do { \
if (((s)->n - (s)->i) < (size_t)(amt)) { \
(s)->d = (char*)__utarray_realloc((s)->d, (s)->n + amt); \
if ((s)->d == NULL) utstring_oom(); \
(s)->n += amt; \
} \
} while(0)
#define utstring_init(s) \
do { \
(s)->n = 0; (s)->i = 0; (s)->d = NULL; \
utstring_reserve(s,100); \
(s)->d[0] = '\0'; \
} while(0)
#define utstring_done(s) \
do { \
if ((s)->d != NULL) __utstring_free((s)->d); \
(s)->n = 0; \
} while(0)
#define utstring_free(s) \
do { \
utstring_done(s); \
__utstring_free(s); \
} while(0)
#define utstring_new(s) \
do { \
s = (UT_string*)__utarray_calloc(sizeof(UT_string),1); \
if (!s) utstring_oom(); \
utstring_init(s); \
} while(0)
#define utstring_renew(s) \
do { \
if (s) { \
utstring_clear(s); \
} else { \
utstring_new(s); \
} \
} while(0)
#define utstring_clear(s) \
do { \
(s)->i = 0; \
(s)->d[0] = '\0'; \
} while(0)
#define utstring_bincpy(s,b,l) \
do { \
utstring_reserve((s),(l)+1); \
if (l) memcpy(&(s)->d[(s)->i], b, l); \
(s)->i += l; \
(s)->d[(s)->i]='\0'; \
} while(0)
#define utstring_concat(dst,src) \
do { \
utstring_reserve((dst),((src)->i)+1); \
if ((src)->i) memcpy(&(dst)->d[(dst)->i], (src)->d, (src)->i); \
(dst)->i += (src)->i; \
(dst)->d[(dst)->i]='\0'; \
} while(0)
#define utstring_len(s) ((unsigned)((s)->i))
#define utstring_body(s) ((s)->d)
_UNUSED_ static void utstring_printf_va(UT_string *s, const char *fmt, va_list ap) {
int n;
va_list cp;
while (1) {
#ifdef _WIN32
cp = ap;
#else
va_copy(cp, ap);
#endif
n = vsnprintf (&s->d[s->i], s->n-s->i, fmt, cp); // vsnprintf not implemented yet in chameleon
va_end(cp);
if ((n > -1) && (n < (int)(s->n-s->i))) {
s->i += n;
return;
}
/* Else try again with more space. */
if (n > -1) utstring_reserve(s,n+1); /* exact */
else utstring_reserve(s,(s->n)*2); /* 2x */
}
}
_UNUSED_ static void utstring_printf(UT_string *s, const char *fmt, ...) {
va_list ap;
va_start(ap,fmt);
utstring_printf_va(s,fmt,ap);
va_end(ap);
}
#endif /* UTSTRING_H */
branches/cparm/i386/util/smbios-fbsd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*-
* Copyright (c) 2005-2009 Jung-uk Kim <jkim@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Detect SMBIOS and export information about the SMBIOS into the
* environment.
*
* System Management BIOS Reference Specification, v2.6 Final
* http://www.dmtf.org/standards/published_documents/DSP0134_2.6.0.pdf
*/
/*
* 2.1.1 SMBIOS Structure Table Entry Point
*
* "On non-EFI systems, the SMBIOS Entry Point structure, described below, can
* be located by application software by searching for the anchor-string on
* paragraph (16-byte) boundaries within the physical memory address range
* 000F0000h to 000FFFFFh. This entry point encapsulates an intermediate anchor
* string that is used by some existing DMI browsers."
*/
#include "libsaio.h"
#define SMBIOS_START 0xf0000
#define SMBIOS_LENGTH 0x10000
#define SMBIOS_STEP 0x10
#define SMBIOS_SIG "_SM_"
#define SMBIOS_DMI_SIG "_DMI_"
#define SMBIOS_GET8(base, off) (*(uint8_t *)((base) + (off)))
#define SMBIOS_GET16(base, off) (*(uint16_t *)((base) + (off)))
#define SMBIOS_GET32(base, off) (*(uint32_t *)((base) + (off)))
#define SMBIOS_GETLEN(base) SMBIOS_GET8(base, 0x01)
#define SMBIOS_GETSTR(base) ((base) + SMBIOS_GETLEN(base))
static uint32_t smbios_enabled_memory = 0;
static uint32_t smbios_old_enabled_memory = 0;
static uint8_t smbios_enabled_sockets = 0;
static uint8_t smbios_populated_sockets = 0;
typedef char* caddr_t;
static uint8_t
smbios_checksum(const caddr_t addr, const uint8_t len)
{
uint8_t sum;
int i;
for (sum = 0, i = 0; i < len; i++)
sum += SMBIOS_GET8(addr, i);
return (sum);
}
static caddr_t
smbios_sigsearch(const caddr_t addr, const uint32_t len)
{
caddr_t cp;
/* Search on 16-byte boundaries. */
for (cp = addr; cp < addr + len; cp += SMBIOS_STEP)
if (strncmp(cp, SMBIOS_SIG, 4) == 0 &&
smbios_checksum(cp, SMBIOS_GET8(cp, 0x05)) == 0 &&
strncmp(cp + 0x10, SMBIOS_DMI_SIG, 5) == 0 &&
smbios_checksum(cp + 0x10, 0x0f) == 0)
return (cp);
return (NULL);
}
void
smbios_detect(void)
{
char buf[16];
caddr_t addr, dmi, smbios;
size_t count, length;
uint32_t paddr;
int i, major, minor, ver;
/* Search signatures and validate checksums. */
smbios = smbios_sigsearch(PTOV(SMBIOS_START), SMBIOS_LENGTH);
if (smbios == NULL)
return;
length = SMBIOS_GET16(smbios, 0x16); /* Structure Table Length */
paddr = SMBIOS_GET32(smbios, 0x18); /* Structure Table Address */
count = SMBIOS_GET16(smbios, 0x1c); /* No of SMBIOS Structures */
ver = SMBIOS_GET8(smbios, 0x1e); /* SMBIOS BCD Revision */
if (ver != 0) {
major = ver >> 4;
minor = ver & 0x0f;
if (major > 9 || minor > 9)
ver = 0;
}
if (ver == 0) {
major = SMBIOS_GET8(smbios, 0x06); /* SMBIOS Major Version */
minor = SMBIOS_GET8(smbios, 0x07); /* SMBIOS Minor Version */
}
ver = (major << 8) | minor;
addr = PTOV(paddr);
for (dmi = addr, i = 0; dmi < addr + length && i < count; i++)
dmi = smbios_parse_table(dmi, ver);
sprintf(buf, "%d.%d", major, minor);
setenv("smbios.version", buf, 1);
if (smbios_enabled_memory > 0 || smbios_old_enabled_memory > 0) {
sprintf(buf, "%u", smbios_enabled_memory > 0 ?
336 smbios_enabled_memory : smbios_old_enabled_memory);
setenv("smbios.memory.enabled", buf, 1);
}
if (smbios_enabled_sockets > 0) {
sprintf(buf, "%u", smbios_enabled_sockets);
setenv("smbios.socket.enabled", buf, 1);
}
if (smbios_populated_sockets > 0) {
sprintf(buf, "%u", smbios_populated_sockets);
setenv("smbios.socket.populated", buf, 1);
}
}
branches/cparm/i386/util/utlist.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
/*
Copyright (c) 2007-2012, Troy D. Hanson http://uthash.sourceforge.net
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UTLIST_H
#define UTLIST_H
#define UTLIST_VERSION 1.9.6
#include <assert.h>
/*
* This file contains macros to manipulate singly and doubly-linked lists.
*
* 1. LL_ macros: singly-linked lists.
* 2. DL_ macros: doubly-linked lists.
* 3. CDL_ macros: circular doubly-linked lists.
*
* To use singly-linked lists, your structure must have a "next" pointer.
* To use doubly-linked lists, your structure must "prev" and "next" pointers.
* Either way, the pointer to the head of the list must be initialized to NULL.
*
* ----------------.EXAMPLE -------------------------
* struct item {
* int id;
* struct item *prev, *next;
* }
*
* struct item *list = NULL:
*
* int main() {
* struct item *item;
* ... allocate and populate item ...
* DL_APPEND(list, item);
* }
* --------------------------------------------------
*
* For doubly-linked lists, the append and delete macros are O(1)
* For singly-linked lists, append and delete are O(n) but prepend is O(1)
* The sort macro is O(n log(n)) for all types of single/double/circular lists.
*/
/* These macros use decltype or the earlier __typeof GNU extension.
As decltype is only available in newer compilers (VS2010 or gcc 4.3+
when compiling c++ code), this code uses whatever method is needed
or, for VS2008 where neither is available, uses casting workarounds. */
#ifdef _MSC_VER /* MS compiler */
#if _MSC_VER >= 1600 && defined(__cplusplus) /* VS2010 or newer in C++ mode */
#define LDECLTYPE(x) decltype(x)
#else /* VS2008 or older (or VS2010 in C mode) */
#define NO_DECLTYPE
#define LDECLTYPE(x) char*
#endif
#else /* GNU, Sun and other compilers */
#define LDECLTYPE(x) __typeof(x)
#endif
/* for VS2008 we use some workarounds to get around the lack of decltype,
* namely, we always reassign our tmp variable to the list head if we need
* to dereference its prev/next pointers, and save/restore the real head.*/
#ifdef NO_DECLTYPE
#define _SV(elt,list) _tmp = (char*)(list); {char **_alias = (char**)&(list); *_alias = (elt); }
#define _NEXT(elt,list) ((char*)((list)->next))
#define _NEXTASGN(elt,list,to) { char **_alias = (char**)&((list)->next); *_alias=(char*)(to); }
#define _PREV(elt,list) ((char*)((list)->prev))
#define _PREVASGN(elt,list,to) { char **_alias = (char**)&((list)->prev); *_alias=(char*)(to); }
#define _RS(list) { char **_alias = (char**)&(list); *_alias=_tmp; }
#define _CASTASGN(a,b) { char **_alias = (char**)&(a); *_alias=(char*)(b); }
#else
#define _SV(elt,list)
#define _NEXT(elt,list) ((elt)->next)
#define _NEXTASGN(elt,list,to) ((elt)->next)=(to)
#define _PREV(elt,list) ((elt)->prev)
#define _PREVASGN(elt,list,to) ((elt)->prev)=(to)
#define _RS(list)
#define _CASTASGN(a,b) (a)=(b)
#endif
/******************************************************************************
* The sort macro is an adaptation of Simon Tatham's O(n log(n)) mergesort *
* Unwieldy variable names used here to avoid shadowing passed-in variables. *
*****************************************************************************/
#define LL_SORT(list, cmp) \
do { \
LDECLTYPE(list) _ls_p; \
LDECLTYPE(list) _ls_q; \
LDECLTYPE(list) _ls_e; \
LDECLTYPE(list) _ls_tail; \
LDECLTYPE(list) _ls_oldhead; \
LDECLTYPE(list) _tmp; \
int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \
if (list) { \
_ls_insize = 1; \
_ls_looping = 1; \
while (_ls_looping) { \
_CASTASGN(_ls_p,list); \
_CASTASGN(_ls_oldhead,list); \
list = NULL; \
_ls_tail = NULL; \
_ls_nmerges = 0; \
while (_ls_p) { \
_ls_nmerges++; \
_ls_q = _ls_p; \
_ls_psize = 0; \
for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \
_ls_psize++; \
_SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); \
if (!_ls_q) break; \
} \
_ls_qsize = _ls_insize; \
while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \
if (_ls_psize == 0) { \
_ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
} else if (_ls_qsize == 0 || !_ls_q) { \
_ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
} else if (cmp(_ls_p,_ls_q) <= 0) { \
_ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
} else { \
_ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
} \
if (_ls_tail) { \
_SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e); _RS(list); \
} else { \
_CASTASGN(list,_ls_e); \
} \
_ls_tail = _ls_e; \
} \
_ls_p = _ls_q; \
} \
_SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,NULL); _RS(list); \
if (_ls_nmerges <= 1) { \
_ls_looping=0; \
} \
_ls_insize *= 2; \
} \
} else _tmp=NULL; /* quiet gcc unused variable warning */ \
} while (0)
#define DL_SORT(list, cmp) \
do { \
LDECLTYPE(list) _ls_p; \
LDECLTYPE(list) _ls_q; \
LDECLTYPE(list) _ls_e; \
LDECLTYPE(list) _ls_tail; \
LDECLTYPE(list) _ls_oldhead; \
LDECLTYPE(list) _tmp; \
int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \
if (list) { \
_ls_insize = 1; \
_ls_looping = 1; \
while (_ls_looping) { \
_CASTASGN(_ls_p,list); \
_CASTASGN(_ls_oldhead,list); \
list = NULL; \
_ls_tail = NULL; \
_ls_nmerges = 0; \
while (_ls_p) { \
_ls_nmerges++; \
_ls_q = _ls_p; \
_ls_psize = 0; \
for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \
_ls_psize++; \
_SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); \
if (!_ls_q) break; \
} \
_ls_qsize = _ls_insize; \
while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \
if (_ls_psize == 0) { \
_ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
} else if (_ls_qsize == 0 || !_ls_q) { \
_ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
} else if (cmp(_ls_p,_ls_q) <= 0) { \
_ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
} else { \
_ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
} \
if (_ls_tail) { \
_SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e); _RS(list); \
} else { \
_CASTASGN(list,_ls_e); \
} \
_SV(_ls_e,list); _PREVASGN(_ls_e,list,_ls_tail); _RS(list); \
_ls_tail = _ls_e; \
} \
_ls_p = _ls_q; \
} \
_CASTASGN(list->prev, _ls_tail); \
_SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,NULL); _RS(list); \
if (_ls_nmerges <= 1) { \
_ls_looping=0; \
} \
_ls_insize *= 2; \
} \
} else _tmp=NULL; /* quiet gcc unused variable warning */ \
} while (0)
#define CDL_SORT(list, cmp) \
do { \
LDECLTYPE(list) _ls_p; \
LDECLTYPE(list) _ls_q; \
LDECLTYPE(list) _ls_e; \
LDECLTYPE(list) _ls_tail; \
LDECLTYPE(list) _ls_oldhead; \
LDECLTYPE(list) _tmp; \
LDECLTYPE(list) _tmp2; \
int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \
if (list) { \
_ls_insize = 1; \
_ls_looping = 1; \
while (_ls_looping) { \
_CASTASGN(_ls_p,list); \
_CASTASGN(_ls_oldhead,list); \
list = NULL; \
_ls_tail = NULL; \
_ls_nmerges = 0; \
while (_ls_p) { \
_ls_nmerges++; \
_ls_q = _ls_p; \
_ls_psize = 0; \
for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \
_ls_psize++; \
_SV(_ls_q,list); \
if (_NEXT(_ls_q,list) == _ls_oldhead) { \
_ls_q = NULL; \
} else { \
_ls_q = _NEXT(_ls_q,list); \
} \
_RS(list); \
if (!_ls_q) break; \
} \
_ls_qsize = _ls_insize; \
while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \
if (_ls_psize == 0) { \
_ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
if (_ls_q == _ls_oldhead) { _ls_q = NULL; } \
} else if (_ls_qsize == 0 || !_ls_q) { \
_ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
if (_ls_p == _ls_oldhead) { _ls_p = NULL; } \
} else if (cmp(_ls_p,_ls_q) <= 0) { \
_ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
if (_ls_p == _ls_oldhead) { _ls_p = NULL; } \
} else { \
_ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
if (_ls_q == _ls_oldhead) { _ls_q = NULL; } \
} \
if (_ls_tail) { \
_SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e); _RS(list); \
} else { \
_CASTASGN(list,_ls_e); \
} \
_SV(_ls_e,list); _PREVASGN(_ls_e,list,_ls_tail); _RS(list); \
_ls_tail = _ls_e; \
} \
_ls_p = _ls_q; \
} \
_CASTASGN(list->prev,_ls_tail); \
_CASTASGN(_tmp2,list); \
_SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_tmp2); _RS(list); \
if (_ls_nmerges <= 1) { \
_ls_looping=0; \
} \
_ls_insize *= 2; \
} \
} else _tmp=NULL; /* quiet gcc unused variable warning */ \
} while (0)
/******************************************************************************
* singly linked list macros (non-circular) *
*****************************************************************************/
#define LL_PREPEND(head,add) \
do { \
(add)->next = head; \
head = add; \
} while (0)
#define LL_CONCAT(head1,head2) \
do { \
LDECLTYPE(head1) _tmp; \
if (head1) { \
_tmp = head1; \
while (_tmp->next) { _tmp = _tmp->next; } \
_tmp->next=(head2); \
} else { \
(head1)=(head2); \
} \
} while (0)
#define LL_APPEND(head,add) \
do { \
LDECLTYPE(head) _tmp; \
(add)->next=NULL; \
if (head) { \
_tmp = head; \
while (_tmp->next) { _tmp = _tmp->next; } \
_tmp->next=(add); \
} else { \
(head)=(add); \
} \
} while (0)
#define LL_DELETE(head,del) \
do { \
LDECLTYPE(head) _tmp; \
if ((head) == (del)) { \
(head)=(head)->next; \
} else { \
_tmp = head; \
while (_tmp->next && (_tmp->next != (del))) { \
_tmp = _tmp->next; \
} \
if (_tmp->next) { \
_tmp->next = ((del)->next); \
} \
} \
} while (0)
/* Here are VS2008 replacements for LL_APPEND and LL_DELETE */
#define LL_APPEND_VS2008(head,add) \
do { \
if (head) { \
(add)->next = head; /* use add->next as a temp variable */ \
while ((add)->next->next) { (add)->next = (add)->next->next; } \
(add)->next->next=(add); \
} else { \
(head)=(add); \
} \
(add)->next=NULL; \
} while (0)
#define LL_DELETE_VS2008(head,del) \
do { \
if ((head) == (del)) { \
(head)=(head)->next; \
} else { \
char *_tmp = (char*)(head); \
while ((head)->next && ((head)->next != (del))) { \
head = (head)->next; \
} \
if ((head)->next) { \
(head)->next = ((del)->next); \
} \
{ \
char **_head_alias = (char**)&(head); \
*_head_alias = _tmp; \
} \
} \
} while (0)
#ifdef NO_DECLTYPE
#undef LL_APPEND
#define LL_APPEND LL_APPEND_VS2008
#undef LL_DELETE
#define LL_DELETE LL_DELETE_VS2008
#undef LL_CONCAT /* no LL_CONCAT_VS2008 */
#undef DL_CONCAT /* no DL_CONCAT_VS2008 */
#endif
/* end VS2008 replacements */
#define LL_FOREACH(head,el) \
for(el=head;el;el=(el)->next)
#define LL_FOREACH_SAFE(head,el,tmp) \
for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp)
#define LL_SEARCH_SCALAR(head,out,field,val) \
do { \
LL_FOREACH(head,out) { \
if ((out)->field == (val)) break; \
} \
} while(0)
#define LL_SEARCH(head,out,elt,cmp) \
do { \
LL_FOREACH(head,out) { \
if ((cmp(out,elt))==0) break; \
} \
} while(0)
/******************************************************************************
* doubly linked list macros (non-circular) *
*****************************************************************************/
#define DL_PREPEND(head,add) \
do { \
(add)->next = head; \
if (head) { \
(add)->prev = (head)->prev; \
(head)->prev = (add); \
} else { \
(add)->prev = (add); \
} \
(head) = (add); \
} while (0)
#define DL_APPEND(head,add) \
do { \
if (head) { \
(add)->prev = (head)->prev; \
(head)->prev->next = (add); \
(head)->prev = (add); \
(add)->next = NULL; \
} else { \
(head)=(add); \
(head)->prev = (head); \
(head)->next = NULL; \
} \
} while (0)
#define DL_CONCAT(head1,head2) \
do { \
LDECLTYPE(head1) _tmp; \
if (head2) { \
if (head1) { \
_tmp = (head2)->prev; \
(head2)->prev = (head1)->prev; \
(head1)->prev->next = (head2); \
(head1)->prev = _tmp; \
} else { \
(head1)=(head2); \
} \
} \
} while (0)
#define DL_DELETE(head,del) \
do { \
assert((del)->prev != NULL); \
if ((del)->prev == (del)) { \
(head)=NULL; \
} else if ((del)==(head)) { \
(del)->next->prev = (del)->prev; \
(head) = (del)->next; \
} else { \
(del)->prev->next = (del)->next; \
if ((del)->next) { \
(del)->next->prev = (del)->prev; \
} else { \
(head)->prev = (del)->prev; \
} \
} \
} while (0)
#define DL_FOREACH(head,el) \
for(el=head;el;el=(el)->next)
/* this version is safe for deleting the elements during iteration */
#define DL_FOREACH_SAFE(head,el,tmp) \
for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp)
/* these are identical to their singly-linked list counterparts */
#define DL_SEARCH_SCALAR LL_SEARCH_SCALAR
#define DL_SEARCH LL_SEARCH
/******************************************************************************
* circular doubly linked list macros *
*****************************************************************************/
#define CDL_PREPEND(head,add) \
do { \
if (head) { \
(add)->prev = (head)->prev; \
(add)->next = (head); \
(head)->prev = (add); \
(add)->prev->next = (add); \
} else { \
(add)->prev = (add); \
(add)->next = (add); \
} \
(head)=(add); \
} while (0)
#define CDL_DELETE(head,del) \
do { \
if ( ((head)==(del)) && ((head)->next == (head))) { \
(head) = 0L; \
} else { \
(del)->next->prev = (del)->prev; \
(del)->prev->next = (del)->next; \
if ((del) == (head)) (head)=(del)->next; \
} \
} while (0)
#define CDL_FOREACH(head,el) \
for(el=head;el;el=((el)->next==head ? 0L : (el)->next))
#define CDL_FOREACH_SAFE(head,el,tmp1,tmp2) \
for((el)=(head), ((tmp1)=(head)?((head)->prev):NULL); \
(el) && ((tmp2)=(el)->next, 1); \
((el) = (((el)==(tmp1)) ? 0L : (tmp2))))
#define CDL_SEARCH_SCALAR(head,out,field,val) \
do { \
CDL_FOREACH(head,out) { \
if ((out)->field == (val)) break; \
} \
} while(0)
#define CDL_SEARCH(head,out,elt,cmp) \
do { \
CDL_FOREACH(head,out) { \
if ((cmp(out,elt))==0) break; \
} \
} while(0)
#endif /* UTLIST_H */
branches/cparm/i386/util/amlsgn.m
238238
239239
240240
241
242
241
242
243243
244244
245245
......
258258
259259
260260
261
262
261
262
263263
264264
265265
......
290290
291291
292292
293
294
293
294
295295
296296
297297
......
308308
309309
310310
311
312
311
312
313313
314314
315315
NSMutableData * mem = [[NSMutableData alloc] initWithContentsOfFile : inStr ];
if (!mem) {
NSLog(@"Error while opening the file : %@ \n",inStr);
//CFRelease(data);
//data = NULL;
CFRelease(data);
data = NULL;
goto out;
}
ACPI_TABLE_HEADER * head = (ACPI_TABLE_HEADER *)[mem mutableBytes];
[mem release];
}
//CFRelease(data);
//data = NULL;
CFRelease(data);
data = NULL;
goto out;
}
NSMutableData * mem = [[NSMutableData alloc] initWithContentsOfFile : inStr ];
if (!mem) {
NSLog(@"Error while opening the file : %@\n",inStr);
//CFRelease(data);
//data = NULL;
CFRelease(data);
data = NULL;
goto out;
}
ACPI_TABLE_HEADER * head = (ACPI_TABLE_HEADER *)[mem mutableBytes];
[mem release];
}
//CFRelease(data);
//data = NULL;
CFRelease(data);
data = NULL;
goto out;
}
branches/cparm/i386/util/random-fbsd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
/*
* Copyright (c) 1983, 1993
*The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)random.c8.2 (Berkeley) 5/19/95";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: src/lib/libc/stdlib/random.c,v 1.25 2007/01/09 00:28:10 imp Exp $");
/*
* We always compile with __DARWIN_UNIX03 set to one, relying on the fact that
* (for non-LP64) sizeof(int) == sizeof(long) == sizeof(size_t), so that we
* don't have to have two different versions of the prototypes. For LP64,
* we only support the POSIX-compatible prototypes.
*/
#undef __DARWIN_UNIX03
#define__DARWIN_UNIX031
#include "namespace.h"
#include <sys/time.h> /* for srandomdev() */
#include <fcntl.h> /* for srandomdev() */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> /* for srandomdev() */
#include "un-namespace.h"
/*
* random.c:
*
* An improved random number generation package. In addition to the standard
* rand()/srand() like interface, this package also has a special state info
* interface. The initstate() routine is called with a seed, an array of
* bytes, and a count of how many bytes are being passed in; this array is
* then initialized to contain information for random number generation with
* that much state information. Good sizes for the amount of state
* information are 32, 64, 128, and 256 bytes. The state can be switched by
* calling the setstate() routine with the same array as was initiallized
* with initstate(). By default, the package runs with 128 bytes of state
* information and generates far better random numbers than a linear
* congruential generator. If the amount of state information is less than
* 32 bytes, a simple linear congruential R.N.G. is used.
*
* Internally, the state information is treated as an array of uint32_t's; the
* zeroeth element of the array is the type of R.N.G. being used (small
* integer); the remainder of the array is the state information for the
* R.N.G. Thus, 32 bytes of state information will give 7 ints worth of
* state information, which will allow a degree seven polynomial. (Note:
* the zeroeth word of state information also has some other information
* stored in it -- see setstate() for details).
*
* The random number generation technique is a linear feedback shift register
* approach, employing trinomials (since there are fewer terms to sum up that
* way). In this approach, the least significant bit of all the numbers in
* the state table will act as a linear feedback shift register, and will
* have period 2^deg - 1 (where deg is the degree of the polynomial being
* used, assuming that the polynomial is irreducible and primitive). The
* higher order bits will have longer periods, since their values are also
* influenced by pseudo-random carries out of the lower bits. The total
* period of the generator is approximately deg*(2**deg - 1); thus doubling
* the amount of state information has a vast influence on the period of the
* generator. Note: the deg*(2**deg - 1) is an approximation only good for
* large deg, when the period of the shift is the dominant factor.
* With deg equal to seven, the period is actually much longer than the
* 7*(2**7 - 1) predicted by this formula.
*
* Modified 28 December 1994 by Jacob S. Rosenberg.
* The following changes have been made:
* All references to the type u_int have been changed to unsigned long.
* All references to type int have been changed to type long. Other
* cleanups have been made as well. A warning for both initstate and
* setstate has been inserted to the effect that on Sparc platforms
* the 'arg_state' variable must be forced to begin on word boundaries.
* This can be easily done by casting a long integer array to char *.
* The overall logic has been left STRICTLY alone. This software was
* tested on both a VAX and Sun SpacsStation with exactly the same
* results. The new version and the original give IDENTICAL results.
* The new version is somewhat faster than the original. As the
* documentation says: "By default, the package runs with 128 bytes of
* state information and generates far better random numbers than a linear
* congruential generator. If the amount of state information is less than
* 32 bytes, a simple linear congruential R.N.G. is used." For a buffer of
* 128 bytes, this new version runs about 19 percent faster and for a 16
* byte buffer it is about 5 percent faster.
*/
/*
* For each of the currently supported random number generators, we have a
* break value on the amount of state information (you need at least this
* many bytes of state info to support this random number generator), a degree
* for the polynomial (actually a trinomial) that the R.N.G. is based on, and
* the separation between the two lower order coefficients of the trinomial.
*/
#defineTYPE_00/* linear congruential */
#defineBREAK_08
#defineDEG_00
#defineSEP_00
#defineTYPE_11/* x**7 + x**3 + 1 */
#defineBREAK_132
#defineDEG_17
#defineSEP_13
#defineTYPE_22/* x**15 + x + 1 */
#defineBREAK_264
#defineDEG_215
#defineSEP_21
#defineTYPE_33/* x**31 + x**3 + 1 */
#defineBREAK_3128
#defineDEG_331
#defineSEP_33
#defineTYPE_44/* x**63 + x + 1 */
#defineBREAK_4256
#defineDEG_463
#defineSEP_41
/*
* Array versions of the above information to make code run faster --
* relies on fact that TYPE_i == i.
*/
#defineMAX_TYPES5/* max number of types above */
#ifdef USE_WEAK_SEEDING
#define NSHUFF 0
#else /* !USE_WEAK_SEEDING */
#define NSHUFF 50 /* to drop some "seed -> 1st value" linearity */
#endif /* !USE_WEAK_SEEDING */
static const int degrees[MAX_TYPES] ={ DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 };
static const int seps [MAX_TYPES] ={ SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
/*
* Initially, everything is set up as if from:
*
*initstate(1, randtbl, 128);
*
* Note that this initialization takes advantage of the fact that srandom()
* advances the front and rear pointers 10*rand_deg times, and hence the
* rear pointer which starts at 0 will also end up at zero; thus the zeroeth
* element of the state information, which contains info about the current
* position of the rear pointer is just
*
*MAX_TYPES * (rptr - state) + TYPE_3 == TYPE_3.
*/
static uint32_t randtbl[DEG_3 + 1] = {
TYPE_3,
#ifdef USE_WEAK_SEEDING
/* Historic implementation compatibility */
/* The random sequences do not vary much with the seed */
0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, 0xde3b81e0, 0xdf0a6fb5,
0xf103bc02, 0x48f340fb, 0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd,
0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86, 0xda672e2a, 0x1588ca88,
0xe369735d, 0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc,
0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e, 0x8999220b,
0x27fb47b9,
#else /* !USE_WEAK_SEEDING */
0x991539b1, 0x16a5bce3, 0x6774a4cd, 0x3e01511e, 0x4e508aaa, 0x61048c05,
0xf5500617, 0x846b7115, 0x6a19892c, 0x896a97af, 0xdb48f936, 0x14898454,
0x37ffd106, 0xb58bff9c, 0x59e17104, 0xcf918a49, 0x09378c83, 0x52c7a471,
0x8d293ea9, 0x1f4fc301, 0xc3db71be, 0x39b44e1c, 0xf8a44ef9, 0x4c8b80b1,
0x19edc328, 0x87bf4bdd, 0xc9b240e5, 0xe9ee4b1b, 0x4382aee7, 0x535b6b41,
0xf3bec5da
#endif /* !USE_WEAK_SEEDING */
};
/*
* fptr and rptr are two pointers into the state info, a front and a rear
* pointer. These two pointers are always rand_sep places aparts, as they
* cycle cyclically through the state information. (Yes, this does mean we
* could get away with just one pointer, but the code for random() is more
* efficient this way). The pointers are left positioned as they would be
* from the call
*
*initstate(1, randtbl, 128);
*
* (The position of the rear pointer, rptr, is really 0 (as explained above
* in the initialization of randtbl) because the state table pointer is set
* to point to randtbl[1] (as explained below).
*/
static uint32_t *fptr = &randtbl[SEP_3 + 1];
static uint32_t *rptr = &randtbl[1];
/*
* The following things are the pointer to the state information table, the
* type of the current generator, the degree of the current polynomial being
* used, and the separation between the two pointers. Note that for efficiency
* of random(), we remember the first location of the state information, not
* the zeroeth. Hence it is valid to access state[-1], which is used to
* store the type of the R.N.G. Also, we remember the last location, since
* this is more efficient than indexing every time to find the address of
* the last element to see if the front and rear pointers have wrapped.
*/
static uint32_t *state = &randtbl[1];
static int rand_type = TYPE_3;
static int rand_deg = DEG_3;
static int rand_sep = SEP_3;
static uint32_t *end_ptr = &randtbl[DEG_3 + 1];
static inline uint32_t good_rand(int32_t) __attribute__((always_inline));
static inline uint32_t good_rand (x)
int32_t x;
{
#ifdef USE_WEAK_SEEDING
/*
* Historic implementation compatibility.
* The random sequences do not vary much with the seed,
* even with overflowing.
*/
return (1103515245 * x + 12345);
#else /* !USE_WEAK_SEEDING */
/*
* Compute x = (7^5 * x) mod (2^31 - 1)
* wihout overflowing 31 bits:
* (2^31 - 1) = 127773 * (7^5) + 2836
* From "Random number generators: good ones are hard to find",
* Park and Miller, Communications of the ACM, vol. 31, no. 10,
* October 1988, p. 1195.
*/
int32_t hi, lo;
/* Can't be initialized with 0, so use another value. */
if (x == 0)
x = 123459876;
hi = x / 127773;
lo = x % 127773;
x = 16807 * lo - 2836 * hi;
if (x < 0)
x += 0x7fffffff;
return (x);
#endif /* !USE_WEAK_SEEDING */
}
/*
* srandom:
*
* Initialize the random number generator based on the given seed. If the
* type is the trivial no-state-information type, just remember the seed.
* Otherwise, initializes state[] based on the given "seed" via a linear
* congruential generator. Then, the pointers are set to known locations
* that are exactly rand_sep places apart. Lastly, it cycles the state
* information a given number of times to get rid of any initial dependencies
* introduced by the L.C.R.N.G. Note that the initialization of randtbl[]
* for default usage relies on values produced by this routine.
*/
void
srandom(x)
unsigned x;
{
int i, lim;
state[0] = (uint32_t)x;
if (rand_type == TYPE_0)
lim = NSHUFF;
else {
for (i = 1; i < rand_deg; i++)
state[i] = good_rand(state[i - 1]);
fptr = &state[rand_sep];
rptr = &state[0];
lim = 10 * rand_deg;
}
for (i = 0; i < lim; i++)
(void)random();
}
/*
* srandomdev:
*
* Many programs choose the seed value in a totally predictable manner.
* This often causes problems. We seed the generator using the much more
* secure random(4) interface. Note that this particular seeding
* procedure can generate states which are impossible to reproduce by
* calling srandom() with any value, since the succeeding terms in the
* state buffer are no longer derived from the LC algorithm applied to
* a fixed seed.
*/
void
srandomdev()
{
int fd, done;
size_t len;
if (rand_type == TYPE_0)
len = sizeof state[0];
else
len = rand_deg * sizeof state[0];
done = 0;
fd = _open("/dev/random", O_RDONLY, 0);
if (fd >= 0) {
if (_read(fd, (void *) state, len) == (ssize_t) len)
done = 1;
_close(fd);
}
if (!done) {
struct timeval tv;
unsigned long junk;
gettimeofday(&tv, NULL);
srandom((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk);
return;
}
if (rand_type != TYPE_0) {
fptr = &state[rand_sep];
rptr = &state[0];
}
}
/*
* initstate:
*
* Initialize the state information in the given array of n bytes for future
* random number generation. Based on the number of bytes we are given, and
* the break values for the different R.N.G.'s, we choose the best (largest)
* one we can and set things up for it. srandom() is then called to
* initialize the state information.
*
* Note that on return from srandom(), we set state[-1] to be the type
* multiplexed with the current value of the rear pointer; this is so
* successive calls to initstate() won't lose this information and will be
* able to restart with setstate().
*
* Note: the first thing we do is save the current state, if any, just like
* setstate() so that it doesn't matter when initstate is called.
*
* Returns a pointer to the old state.
*
* Note: The Sparc platform requires that arg_state begin on an int
* word boundary; otherwise a bus error will occur. Even so, lint will
* complain about mis-alignment, but you should disregard these messages.
*/
char *
initstate(seed, arg_state, n)
unsigned seed;/* seed for R.N.G. */
char *arg_state;/* pointer to state array */
size_t n;/* # bytes of state info */
{
char *ostate = (char *)(&state[-1]);
uint32_t *int_arg_state = (uint32_t *)arg_state;
if (rand_type == TYPE_0)
state[-1] = rand_type;
else
state[-1] = MAX_TYPES * (rptr - state) + rand_type;
if (n < BREAK_0) {
(void)fprintf(stderr,
"random: not enough state (%ld bytes); ignored.\n", n);
return(0);
}
if (n < BREAK_1) {
rand_type = TYPE_0;
rand_deg = DEG_0;
rand_sep = SEP_0;
} else if (n < BREAK_2) {
rand_type = TYPE_1;
rand_deg = DEG_1;
rand_sep = SEP_1;
} else if (n < BREAK_3) {
rand_type = TYPE_2;
rand_deg = DEG_2;
rand_sep = SEP_2;
} else if (n < BREAK_4) {
rand_type = TYPE_3;
rand_deg = DEG_3;
rand_sep = SEP_3;
} else {
rand_type = TYPE_4;
rand_deg = DEG_4;
rand_sep = SEP_4;
}
state = int_arg_state + 1; /* first location */
end_ptr = &state[rand_deg];/* must set end_ptr before srandom */
srandom(seed);
if (rand_type == TYPE_0)
int_arg_state[0] = rand_type;
else
int_arg_state[0] = MAX_TYPES * (rptr - state) + rand_type;
return(ostate);
}
/*
* setstate:
*
* Restore the state from the given state array.
*
* Note: it is important that we also remember the locations of the pointers
* in the current state information, and restore the locations of the pointers
* from the old state information. This is done by multiplexing the pointer
* location into the zeroeth word of the state information.
*
* Note that due to the order in which things are done, it is OK to call
* setstate() with the same state as the current state.
*
* Returns a pointer to the old state information.
*
* Note: The Sparc platform requires that arg_state begin on an int
* word boundary; otherwise a bus error will occur. Even so, lint will
* complain about mis-alignment, but you should disregard these messages.
*/
char *
setstate(arg_state)
const char *arg_state;/* pointer to state array */
{
uint32_t *new_state = (uint32_t *)arg_state;
uint32_t type = new_state[0] % MAX_TYPES;
uint32_t rear = new_state[0] / MAX_TYPES;
char *ostate = (char *)(&state[-1]);
if (rand_type == TYPE_0)
state[-1] = rand_type;
else
state[-1] = MAX_TYPES * (rptr - state) + rand_type;
switch(type) {
case TYPE_0:
case TYPE_1:
case TYPE_2:
case TYPE_3:
case TYPE_4:
rand_type = type;
rand_deg = degrees[type];
rand_sep = seps[type];
break;
default:
(void)fprintf(stderr,
"random: state info corrupted; not changed.\n");
}
state = new_state + 1;
if (rand_type != TYPE_0) {
rptr = &state[rear];
fptr = &state[(rear + rand_sep) % rand_deg];
}
end_ptr = &state[rand_deg];/* set end_ptr too */
return(ostate);
}
/*
* random:
*
* If we are using the trivial TYPE_0 R.N.G., just do the old linear
* congruential bit. Otherwise, we do our fancy trinomial stuff, which is
* the same in all the other cases due to all the global variables that have
* been set up. The basic operation is to add the number at the rear pointer
* into the one at the front pointer. Then both pointers are advanced to
* the next location cyclically in the table. The value returned is the sum
* generated, reduced to 31 bits by throwing away the "least random" low bit.
*
* Note: the code takes advantage of the fact that both the front and
* rear pointers can't wrap on the same call by not testing the rear
* pointer if the front one has wrapped.
*
* Returns a 31-bit random number.
*/
long
random()
{
uint32_t i;
uint32_t *f, *r;
if (rand_type == TYPE_0) {
i = state[0];
state[0] = i = (good_rand(i)) & 0x7fffffff;
} else {
/*
* Use local variables rather than static variables for speed.
*/
f = fptr; r = rptr;
*f += *r;
i = (*f >> 1) & 0x7fffffff;/* chucking least random bit */
if (++f >= end_ptr) {
f = state;
++r;
}
else if (++r >= end_ptr) {
r = state;
}
fptr = f; rptr = r;
}
return((long)i);
}

Archive Download the corresponding diff file

Revision: 1972