Chameleon

Chameleon Commit Details

Date:2012-05-21 15:18:17 (2 years 6 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;