Chameleon

Chameleon Commit Details

Date:2012-05-29 14:51:26 (11 years 11 months ago)
Author:armel cadet-petit
Commit:1984
Parents: 1983
Message:implemented snprintf and __doprnt, bug fix in device_inject.c
Changes:
D/branches/cparm/i386/libsa/prf.c
M/branches/cparm/i386/libsaio/stringTable.c
M/branches/cparm/i386/libsaio/pci.h
M/branches/cparm/i386/libsaio/msdos.c
M/branches/cparm/i386/modules/GraphicsEnabler/nvidia.c
M/branches/cparm/i386/modules/YellowIconFixer/YellowIconFixer.c
M/branches/cparm/i386/libsaio/device_inject.c
M/branches/cparm/i386/modules/GraphicsEnabler/ati.c
M/branches/cparm/i386/libsaio/saio_internal.h
M/branches/cparm/i386/libsaio/Makefile
M/branches/cparm/i386/libsaio/xml.c
M/branches/cparm/i386/libsaio/device_inject.h
M/branches/cparm/i386/libsaio/console.c
M/branches/cparm/i386/modules/GUI/GUI_module.c
M/branches/cparm/i386/libsa/Makefile
M/branches/cparm/i386/libsaio/xml.h
M/branches/cparm/CHANGES
M/branches/cparm/i386/modules/USBFix/usb.c
M/branches/cparm/i386/libsaio/befs.c
M/branches/cparm/i386/modules/SMBiosGetters/smbios_decode.c
M/branches/cparm/i386/MakeInc.dir
M/branches/cparm/xcode3_sym.zip
M/branches/cparm/i386/modules/GraphicsEnabler/gma.c
M/branches/cparm/i386/libsaio/openbsd.c
M/branches/cparm/i386/modules/Resolution/915resolution.c
M/branches/cparm/i386/modules/GUI/gui.c
M/branches/cparm/i386/modules/Resolution/edid.c
M/branches/cparm/i386/boot2/Makefile
M/branches/cparm/i386/modules/Networking/Networking.c
M/branches/cparm/i386/libsa/libsa.h
M/branches/cparm/i386/libsaio/modules.c
M/branches/cparm/TODO
M/branches/cparm/i386/libsaio/freebsd.c
M/branches/cparm/i386/libsa/printf.c
M/branches/cparm/i386/libsaio/pci.c
M/branches/cparm/i386/libsaio/ext2fs.c

File differences

branches/cparm/TODO
11
22
33
4
5
46
57
68
79
8
910
1011
1112
......
1415
1516
1617
17
18
19
2018
2119
2220
TODO List for Chameleon Boot Loader
====================================
- 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 (almost done !!)
- split nvidia, gma and ati code into separate modules
- move device_inject, MBR (OSX works better on Guid partition theme anyway), 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
- update project with corehash
- 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
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/CHANGES
11
2
3
4
5
6
7
28
39
410
- security and stability fixes
- Fixed a bug where prf may return a wrong string len (for ex : in the previous versions newStringWithformat("%02x%02x%02x%02x%02x%02x",101,117,104,113,103,100) may not return the entire string)
- Fixed a bug in xml.c
- Fixed a bug in device_inject.c (inspired from the dmazar's patch)
- security and stability fixes
- Removed useless codes in efistring modules
- Fixed bugs related to device_inject.c
- Fixed bugs related to device_tree.c
branches/cparm/i386/libsaio/xml.c
4444
4545
4646
47
47
4848
4949
5050
......
5252
5353
5454
55
55
56
57
58
5659
57
60
5861
5962
6063
6164
6265
66
67
68
6369
70
71
72
73
6474
6575
6676
6777
78
6879
6980
7081
......
249260
250261
251262
263
264
265
252266
253267
254268
......
342356
343357
344358
345
359
346360
347361
348362
......
415429
416430
417431
418
432
419433
420434
421435
/// TODO: remove below
static char* buffer_start = NULL;
// TODO: redo the next two functions
static void SaveRefString(char* string, int id)
static int SaveRefString(char* string, int id)
{
//printf("Adding Ref String %d (%s)\n", id, string);
string_ref* tmp = ref_strings;
{
if(tmp->id == id)
{
tmp->string = malloc(strlen(string+1));
tmp->string = malloc(strlen(string)+1);
if (!tmp->string) {
return -1;
}
sprintf(tmp->string, "%s", string);
return;
return 0;
}
tmp = tmp->next;
}
string_ref* new_ref = malloc(sizeof(string_ref));
if (!new_ref) {
return -1;
}
new_ref->string = malloc(strlen(string)+1);
if (!new_ref->string) {
free(new_ref);
return -1;
}
sprintf(new_ref->string, "%s", string);
new_ref->id = id;
new_ref->next = ref_strings;
ref_strings = new_ref;
return 0;
}
static char* GetRefString(int id)
configBuffer = malloc(strlen(buffer)+1);
if (!configBuffer) {
return -1;
}
strcpy(configBuffer, buffer);
buffer_start = configBuffer;
}
length = ParseTagString(buffer + pos, tag);
SaveRefString(buffer + pos, id);
if (SaveRefString(buffer + pos, id) != 0) return -1;
}
else if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringIDRef, strlen(kXMLStringIDRef)))
{
}
length = ParseTagInteger(buffer + pos, tag);
SaveRefString((*tag)->string, id);
if (SaveRefString((*tag)->string, id) != 0) return -1;
}
else if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringIDRef, strlen(kXMLStringIDRef)))
{
branches/cparm/i386/libsaio/console.c
5252
5353
5454
55
55
56
57
58
5659
57
60
5861
59
60
62
63
6164
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
7865
7966
8067
8168
8269
83
70
8471
8572
8673
8774
88
75
8976
9077
9178
92
79
80
9381
94
82
83
84
85
9586
96
97
98
99
100
101
102
103
104
105
106
107
10887
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
12888
12989
13090
......
141101
142102
143103
144
104
145105
146106
147107
......
181141
182142
183143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
184165
185166
186167
187168
188169
189
170
190171
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206172
207173
208174
209175
210176
177
178
179
180
181
182
183
184
185
186
211187
212188
213189
214
190
215191
216192
217193
218
194
219195
220196
221
222
223
224
225
226
227
228
229
230
231
232
233
234
197
235198
236199
237200
......
241204
242205
243206
244
245207
246208
247209
248210
249
211
212
213
214
215
250216
251217
252218
253219
254
255
256
257
258
259
260
220
221
261222
262223
263224
......
276237
277238
278239
279
240
280241
281242
282243
......
294255
295256
296257
297
298258
299259
300260
301261
302
262
303263
304264
305265
306266
307
308
309
310
311
312
313
267
268
314269
315270
316271
#define BOOTER_LOG_SIZE (128 * 1024)
#define SAFE_LOG_SIZE 134
struct LOG {
#define LOG 1
#define PRINT 2
struct log_t {
char *buf;
char *cursor;
char *ptr;
};
typedef struct LOG LOG;
static LOG booterlog;
typedef struct log_t log_t;
static log_t booterlog;
struct putc_info {
char * str;
char * last_str;
};
void sputc(int c, struct putc_info * pi)
{
if (pi->last_str)
if (pi->str == pi->last_str)
{
*(pi->str) = '\0';
return;
}
*(pi->str)++ = c;
}
void initBooterLog(void)
{
booterlog.buf = malloc(BOOTER_LOG_SIZE);
if (!booterlog.buf) {
printf("Couldn't allocate buffer for booter log\n");
booterlog.cursor = 0;
booterlog.ptr = 0;
booterlog.buf = 0;
return;
}
bzero(booterlog.buf, BOOTER_LOG_SIZE);
booterlog.cursor = booterlog.buf;
booterlog.ptr = booterlog.buf;
}
char *getConsoleMsg(void)
void
debug_putc(char c)
{
return booterlog.buf;
if (((booterlog.ptr-booterlog.buf) < (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) {
*booterlog.ptr=c;
booterlog.ptr++;
}
}
char *getConsoleCursor(void)
{
return booterlog.cursor;
}
void setConsoleMsg(char *p)
{
booterlog.buf = p;
}
void setConsoleCursor(char *p)
{
booterlog.cursor = p;
}
void msglog(const char * fmt, ...)
{
va_list ap;
struct putc_info pi;
if (!booterlog.buf)
return;
if (((booterlog.cursor - booterlog.buf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
return;
va_start(ap, fmt);
pi.str = booterlog.cursor;
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
va_end(ap);
booterlog.cursor += strlen((char *)booterlog.cursor);
}
void setupBooterLog(void)
{
if (!booterlog.buf)
/*
* write one character to console
*/
void putchar(int c)
void putchar(char c)
{
if ( c == '\t' )
{
return (c);
}
int
reallyVPrint(const char *format, va_list ap, int flag)
{
if (flag & PRINT) prf(format, ap, putchar);
if (flag & LOG)
{
/* Kabyl: BooterLog */
prf(format, ap, debug_putc);
}
return 0;
}
int localVPrintf(const char *format, va_list ap, int flag)
{
/**/
reallyVPrint(format, ap, flag);
return 0;
}
int printf(const char * fmt, ...)
{
va_list ap;
va_start(ap, fmt);
prf(fmt, ap, putchar, 0);
localVPrintf(fmt, ap, LOG | PRINT);
{
/* Kabyl: BooterLog */
struct putc_info pi;
if (!booterlog.buf)
return 0;
if (((booterlog.cursor - booterlog.buf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
return 0;
pi.str = booterlog.cursor;
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
booterlog.cursor += strlen((char *)booterlog.cursor);
}
va_end(ap);
return 0;
}
void msglog(const char * fmt, ...)
{
va_list ap;
va_start(ap, fmt);
localVPrintf(fmt, ap, LOG);
va_end(ap);
}
int verbose(const char * fmt, ...)
{
va_list ap;
int flag = 0;
va_start(ap, fmt);
if (get_env(envgVerboseMode))
{
prf(fmt, ap, putchar, 0);
flag = PRINT;
}
{
/* Kabyl: BooterLog */
struct putc_info pi;
if (!booterlog.buf)
return 0;
if (((booterlog.cursor - booterlog.buf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
return 0;
pi.str = booterlog.cursor;
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
booterlog.cursor += strlen((char *)booterlog.cursor);
}
localVPrintf(fmt, ap, LOG | flag);
va_end(ap);
int error(const char * fmt, ...)
{
va_list ap;
struct putc_info pi;
int len;
char *str = NULL;
va_start(ap, fmt);
len = prf(fmt, ap, 0, 0);
localVPrintf(fmt, ap, 0);
len = prf(fmt, ap, 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';
{
vsnprintf(str,len,fmt,ap);
}
}
printf("\n");
va_start(ap, fmt);
prf(fmt, ap, putchar, 0);
localVPrintf(fmt, ap, PRINT);
va_end(ap);
printf("\nThis is a non recoverable error! System HALTED!!!");
char * newStringWithFormat(const char * fmt, ...)
{
va_list ap;
struct putc_info pi;
int len;
char *str = NULL;
va_start(ap, fmt);
len = prf(fmt, ap, 0, 0);
len = prf(fmt, ap, 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';
{
vsnprintf(str,len,fmt,ap);
}
}
branches/cparm/i386/libsaio/xml.h
8282
8383
8484
85
8586
8687
8788
#define kPropIOClass ("IOClass")
#define kPropIOProviderClass ("IOProviderClass")
#define kPropOSBundleWorkspace ("OSBundleWorkspace")
#define kPropCFBundleLocalizations("CFBundleLocalizations")
#define DEFAULT_BOOT_CONFIG_DICT (TagPtr)0
#define DEFAULT_SYSTEM_CONFIG_DICT (TagPtr)1
branches/cparm/i386/libsaio/ext2fs.c
2020
2121
2222
23
2423
2524
25
2626
2727
2828
void EX2GetDescription(CICell ih, char *str, long strMaxLen)
{
char * buf=malloc (EX2ProbeSize);
str[0]=0;
if (!buf)
return;
str[0]=0;
Seek(ih, 0);
Read(ih, (long)buf, EX2ProbeSize);
if (!EX2Probe (buf))
branches/cparm/i386/libsaio/Makefile
1212
1313
1414
15
16
15
16
1717
1818
1919
CFLAGS= $(RC_CFLAGS) $(OPTIM) $(MORECPP) -arch i386 -g -Wmost -fno-stack-protector \
-D__ARCHITECTURE__=\"i386\" \
$(DEBUG) \
-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
-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
GFLAGS=
DEFINES=
CONFIG = hd
INC = -I. -I$(SYMROOT) -I$(UTILDIR) -I$(LIBSADIR) -I$(BOOT2DIR)
branches/cparm/i386/libsaio/modules.c
14251425
14261426
14271427
1428
1429
1430
14281431
14291432
14301433
......
20542057
20552058
20562059
2057
2058
2060
2061
20592062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
20602095
20612096
20622097
long willLoad;
TagPtr dict;
TagPtr personalities;
#if 0
config_file_t *LanguageConfig; // we will use an xml file instead of pure txt file ... it's easier to parse
#endif
//pool_t workspace;
char *plistAddr;
long plistLength;
}
}
}
tmpModule->willLoad = BundlePriorityNormalPriority;
#if 0
prop = XMLGetProperty(moduleDict, kPropCFBundleLocalizations);
if ((prop != 0) && prop->string)
{
char * path = newStringWithFormat("%s%s",module->bundlePath,prop->string);
if (path == NULL) {
break;
}
if (loadConfigFile(path, module->LanguageConfig) != 0)
{
free(path);
path = NULL;
const char * default_local;
if ((default_local = getStringForKey(kPropCFBundleLocalizations, DEFAULT_BOOT_CONFIG)))
{
path = newStringWithFormat("%s%s",module->bundlePath,default_local);
if (path == NULL) {
break;
}
loadConfigFile(path, module->LanguageConfig);
}
}
if (path) {
free(path);
}
}
#endif
} while (0);
branches/cparm/i386/libsaio/befs.c
2727
2828
2929
30
3130
3231
32
3333
3434
3535
void BeFSGetDescription(CICell ih, char *str, long strMaxLen)
{
char * buf=malloc (BeFSProbeSize);
str[0]=0;
if (!buf)
return;
str[0]=0;
Seek(ih, 0);
Read(ih, (long)buf, BeFSProbeSize);
if (!BeFSProbe (buf))
branches/cparm/i386/libsaio/device_inject.c
8888
8989
9090
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
91193
92194
93195
......
103205
104206
105207
106
208
107209
108210
109211
......
111213
112214
113215
114
115
216
217
218
116219
220
117221
118222
223
119224
120225
121226
122227
123228
124
125
126
127
128
129
130
131
132
133
134
135
136
137
229
230
231
232
233
234
235
236
237
238
138239
139240
241
242
140243
141244
142245
143
144
145
146
147
148
149
150
151
152
153
154
155
156
246
247
248
249
250
251
252
253
254
255
157256
158257
159258
......
162261
163262
164263
264
165265
166266
167267
......
197297
198298
199299
300
301
200302
201303
202304
......
209311
210312
211313
314
212315
213316
214317
return string;
}
struct DevPropDevice *devprop_make_device(pci_dt_t *pci_dt)
{
struct DevPropDevice*device;
int numpaths = 0;
pci_dt_t*current;
pci_dt_t*end;
end = root_pci_dev;
device = malloc(sizeof(struct DevPropDevice));
if (!device) {
return NULL;
}
memset(device, 0, sizeof(struct DevPropDevice));
device->acpi_dev_path._UID = getPciRootUID();
while (end != pci_dt)
{
current = pci_dt;
while (current->parent != end)
current = current->parent;
end = current;
{
device->pci_dev_path[numpaths].device =(uint8_t)current->dev.bits.dev;
device->pci_dev_path[numpaths].function = (uint8_t)current->dev.bits.func;
numpaths++;
}
}
if(!numpaths)
{
printf("ERROR parsing device path\n");
free(device);
return NULL;
}
device->numentries = 0x00;
device->acpi_dev_path.length = 0x0c;
device->acpi_dev_path.type = 0x02;
device->acpi_dev_path.subtype = 0x01;
device->acpi_dev_path._HID = 0xd041030a;
device->num_pci_devpaths = numpaths;
device->length = 24 + (6*numpaths);
inti;
for(i = 0; i < numpaths; i++)
{
device->pci_dev_path[i].length = 0x06;
device->pci_dev_path[i].type = 0x01;
device->pci_dev_path[i].subtype = 0x01;
}
device->path_end.length = 0x04;
device->path_end.type = 0x7f;
device->path_end.subtype = 0xff;
device->data = NULL;
return device;
}
struct DevPropDevice *devprop_add_device(struct DevPropString *string, pci_dt_t * pci_dt)
{
struct DevPropDevice*device;
if (string == NULL || pci_dt == NULL) {
return NULL;
}
device = devprop_make_device(pci_dt);
if (!device) {
return NULL;
}
device->string = string;
string->length += device->length;
if(!string->entries)
{
if((string->entries = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice) * MAX_STRING_NUM_ENTRIES))== NULL)
{
printf("ERROR parsing device path 2\n");
free(device);
return NULL;
}
}
struct DevPropDevice **string_entries_arrey = (struct DevPropDevice **) string->entries;
string->numentries++;
string_entries_arrey[string->numentries-1] = device;
return device;
}
#if 0
struct DevPropDevice *devprop_add_device(struct DevPropString *string, char *path)
{
struct DevPropDevice*device;
}
if (strncmp(path, pciroot_string, strlen(pciroot_string))) {
free(device);
printf("ERROR parsing device path\n");
printf("ERROR parsing device path 1\n");
return NULL;
}
device->acpi_dev_path._UID = getPciRootUID();
int numpaths = 0;
intx, curr = 0;
charbuff[] = "00";
intx, curr = 0, w = 0;
charbuff[16];
for (x = 0; x < strlen(path); x++)
{
if (!strncmp(&path[x], pci_device_string, strlen(pci_device_string)))
{
x+=strlen(pci_device_string);
curr=x;
while(path[++x] != ',');
if(x-curr == 2)
{
sprintf(buff, "%c%c", path[curr], path[curr+1]);
}
else if(x-curr == 1)
{
sprintf(buff, "%c", path[curr]);
}
else
{
printf("ERROR parsing device path\n");
numpaths = 0;
break;
}
w = x-curr;
if ((w > 4) || /*(w > sizeof(buff)) ||*/ (w == 0)) {
printf("ERROR parsing device path 2\n");
break;
}
snprintf(buff, x-curr, "%s",&path[curr]);
device->pci_dev_path[numpaths].device =(uint8_t)strtoul(buff, NULL, 16);
bzero(buff, sizeof(buff));
x += 3; // 0x
curr = x;
while(path[++x] != ')');
if(x-curr == 2)
{
sprintf(buff, "%c%c", path[curr], path[curr+1]);
}
else if(x-curr == 1)
{
sprintf(buff, "%c", path[curr]);
}
else
{
printf("ERROR parsing device path\n");
numpaths = 0;
break;
}
w = x-curr;
if ((w > 4) || /*(w > sizeof(buff)) ||*/ (w == 0)) {
printf("ERROR parsing device path 3\n");
break;
}
snprintf(buff, x-curr, "%s",&path[curr]);
device->pci_dev_path[numpaths].function = (uint8_t)strtoul(buff, NULL, 16); // TODO: find dev from char *path
numpaths++;
if(!numpaths)
{
printf("ERROR parsing device path 4\n");
free(device);
return NULL;
}
{
if((string->entries = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice) * MAX_STRING_NUM_ENTRIES))== NULL)
{
printf("ERROR parsing device path 6\n");
free(device);
return NULL;
}
return device;
}
#endif
int devprop_add_value(struct DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len)
{
branches/cparm/i386/libsaio/device_inject.h
88
99
1010
11
12
1113
1214
1315
......
7072
7173
7274
73
75
76
7477
7578
7679
#ifndef __LIBSAIO_DEVICE_INJECT_H
#define __LIBSAIO_DEVICE_INJECT_H
#include "pci.h"
#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
char*efi_inject_get_devprop_string(uint32_t *len);
struct DevPropString*devprop_create_string(void);
struct DevPropDevice*devprop_add_device(struct DevPropString *string, char *path);
struct DevPropDevice *devprop_add_device(struct DevPropString *string, pci_dt_t * pci_dt);
struct DevPropDevice *devprop_make_device(pci_dt_t *pci_dt);
intdevprop_add_value(struct DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len);
char*devprop_generate_string(struct DevPropString *string);
voiddevprop_free_string(struct DevPropString *string);
branches/cparm/i386/libsaio/openbsd.c
1111
1212
1313
14
1514
1615
16
1717
1818
1919
void OpenBSDGetDescription(CICell ih, char *str, long strMaxLen)
{
char * buf=malloc(OpenBSDProbeSize);
str[0]=0;
if (!buf)
return;
str[0]=0;
Seek(ih, 0);
Read(ih, (long)buf, OpenBSDProbeSize);
if (!OpenBSDProbe (buf))
branches/cparm/i386/libsaio/freebsd.c
1111
1212
1313
14
1514
1615
16
1717
1818
1919
void FreeBSDGetDescription(CICell ih, char *str, long strMaxLen)
{
char * buf=malloc(FreeBSDProbeSize);
str[0]=0;
if (!buf)
return;
str[0]=0;
Seek(ih, 0);
Read(ih, (long)buf, FreeBSDProbeSize);
if (!FreeBSDProbe (buf))
branches/cparm/i386/libsaio/pci.c
164164
165165
166166
167
167168
168169
169170
......
200201
201202
202203
204
203205
204206
205207
......
222224
223225
224226
225
227
226228
227
228
229
229230
230231
231232
#endif
}
#if 0
char *get_pci_dev_path(pci_dt_t *pci_dt)
{
char* buffer = malloc(sizeof(char) * 256);
}
return buffer;
}
#endif
void setup_pci_devs(pci_dt_t *pci_dt)
{
current = pci_dt;
while (current)
{
printf("%02x:%02x.%x [%04x] [%04x:%04x] :: %s\n",
printf("%02x:%02x.%x [%04x] [%04x:%04x] \n",
current->dev.bits.bus, current->dev.bits.dev, current->dev.bits.func,
current->class_id, current->vendor_id, current->device_id,
get_pci_dev_path(current));
current->class_id, current->vendor_id, current->device_id);
dump_pci_dt(current->children);
current = current->next;
}
branches/cparm/i386/libsaio/stringTable.c
114114
115115
116116
117
117
118
119
118120
119121
120122
......
172174
173175
174176
177
178
179
175180
176181
177182
......
251256
252257
253258
259
260
261
254262
255263
256264
......
290298
291299
292300
301
302
303
293304
294305
295306
len = strlen(key);
tab = (char *)table;
buf = (char *)malloc(len + 3);
if (!buf) {
return false;
}
sprintf(buf, "\"%s\"", key);
len = strlen(buf);
return 0;
bufsize = end - begin + 1;
newstr = malloc(bufsize);
if (!newstr) {
return 0;
}
strlcpy(newstr, begin, bufsize);
*list = end;
*size = newsize;
if (getValueForConfigTableKey(config, key, &val, &size)) {
newstr = (char *)malloc(size+1);
if (!newstr) {
return 0;
}
for (p = newstr; size; size--, p++, val++) {
if ((*p = *val) == '\\') {
switch (*++val) {
if (getValueForKey(key, &val, &size, config) && size) {
newstr = (char *)malloc(size + 1);
if (!newstr) {
return 0;
}
strlcpy(newstr, val, size + 1);
return newstr;
} else {
branches/cparm/i386/libsaio/pci.h
6060
6161
6262
63
63
6464
6565
6666
extern voidpci_config_write8(uint32_t, uint8_t, uint8_t);
extern voidpci_config_write16(uint32_t, uint8_t, uint16_t);
extern voidpci_config_write32(uint32_t, uint8_t, uint32_t);
extern char*get_pci_dev_path(pci_dt_t *);
//extern char*get_pci_dev_path(pci_dt_t *);
extern voidbuild_pci_dt(void);
extern voiddump_pci_dt(pci_dt_t *);
extern voidsetup_pci_devs(pci_dt_t *pci_dt);
branches/cparm/i386/libsaio/msdos.c
183183
184184
185185
186
187
188
189
186190
187191
188192
......
267271
268272
269273
274
275
276
277
270278
271279
272280
......
327335
328336
329337
330
338
331339
332340
333341
......
673681
674682
675683
684
685
686
687
676688
677689
678690
691
692
693
694
695
679696
680697
681698
......
708725
709726
710727
728
729
730
731
732
733
711734
712735
713736
......
715738
716739
717740
741
742
743
744
745
746
718747
719748
720749
......
770799
771800
772801
802
803
804
773805
774806
775807
......
824856
825857
826858
859
860
861
827862
828863
829864
......
920955
921956
922957
958
959
960
923961
924962
925963
......
941979
942980
943981
982
983
984
944985
945986
946987
......
9611002
9621003
9631004
1005
1006
1007
9641008
9651009
9661010
}
buf=malloc (512);
if (!buf)
{
return -1;
}
/*
* Read the boot sector of the filesystem, and then check the
* boot signature. If not a dos boot sector then error out.
char *cacheBuffer;
cacheBuffer = malloc(MSDOS_CACHE_BLOCKSIZE);
if (!cacheBuffer)
{
return -1;
}
CacheRead(ih, cacheBuffer, sectorOffset, MSDOS_CACHE_BLOCKSIZE, true);
bcopy(cacheBuffer + relOffset, buf, size);
free(cacheBuffer);
readOffset += ((uint64_t)*cluster * (uint64_t)msdosfatbits) / 8;
/* Read one sector of the FAT */
readSector(ih, readOffset, tmpbuf, 4);
if (readSector(ih, readOffset, tmpbuf, 4) != 0) return 0;
switch (msdosfatbits) {
case 32:
if (!st)
{
st=malloc (sizeof (struct msdosdirstate));
if (!st)
{
return -1;
}
if (dirPath[0])
{
uint8_t *buf=malloc(msdosclustersize);
if (!buf)
{
free (st);
return -1;
}
dirp = getdirpfrompath (ih, dirPath, buf);
if (!dirp || !(dirp->deAttributes & ATTR_DIRECTORY))
{
int i;
for (i=0;vfatname[i];i++);
*name = malloc (256);
if (!*name)
{
free (st->buf);
free (st);
return -1;
}
utf_encodestr(vfatname, i, (u_int8_t *)*name, 255, OSLittleEndian );
}
else
int i, j, k;
uint16_t tmp[13];
*name = malloc (26);
if (!*name)
{
free (st->buf);
free (st);
return -1;
}
for (i=7;i>=0;i--)
if (dirp->deName[i]!=' ')
break;
if (filePath[0] == '/')
filePath++;
buf = malloc(msdosclustersize);
if (!buf) {
return -1;
}
dirp = getdirpfrompath (ih, filePath, buf);
if (!dirp || (dirp->deAttributes & ATTR_DIRECTORY))
if (filePath[0] == '/')
filePath++;
buf = malloc(msdosclustersize);
if (!buf) {
return -1;
}
dirp = getdirpfrompath (ih, filePath, buf);
if (!dirp || (dirp->deAttributes & ATTR_DIRECTORY))
{
initRoot (&st);
st.buf = malloc(msdosclustersize);
if (!st.buf) {
return;
}
while ((dirp = getnextdirent (ih, vfatlabel, &st)))
if (dirp->deAttributes & ATTR_VOLUME) {
strncpy((char *)label, (char *)dirp->deName, LABEL_LENGTH);
/* else look in the boot blocks */
if (!labelfound || str[0] == '\0') {
char *buf = malloc (512);
if (!buf) {
return;
}
union bootsector *bsp = (union bootsector *)buf;
Seek(ih, 0);
Read(ih, (long)buf, 512);
MSDOSGetUUID(CICell ih, char *uuidStr)
{
char *buf = malloc (512);
if (!buf) {
return -1;
}
union bootsector *bsp = (union bootsector *)buf;
if (MSDOSInitPartition (ih)<0)
branches/cparm/i386/libsaio/saio_internal.h
109109
110110
111111
112
112
113
113114
115
116
114117
115118
116119
/* console.c */
extern void initBooterLog(void);
extern void setupBooterLog(void);
extern void putchar(int ch);
extern void putchar(char ch);
extern void debug_putc(char c);
extern int getchar(void);
extern int localVPrintf(const char *format, va_list ap, int flag);
extern int reallyVPrint(const char *format, va_list ap, int flag);
extern void msglog(const char * format, ...);
extern int printf(const char *format, ...);
extern int error(const char *format, ...);
branches/cparm/i386/MakeInc.dir
4040
4141
4242
43
43
4444
4545
46
46
4747
4848
49
49
5050
5151
5252
5353
5454
55
55
5656
5757
5858
.SUFFIXES: .s .i .c .o
.c.o .m.o:
$(CC) $(CPPFLAGS) $(GFLAGS) $(CFLAGS) $(DEFINES) -c $(INC) $< -o $(OBJROOT)/$*.o
$(CC) $(CPPFLAGS) $(GFLAGS) $(CFLAGS) $(DEFINES) -no-integrated-as -c $(INC) $< -o $(OBJROOT)/$*.o
$(OBJROOT)/%.o: %.c
$(CC) $(CPPFLAGS) $(GFLAGS) $(CFLAGS) $(DEFINES) -c $(INC) $< -o $(OBJROOT)/$*.o
$(CC) $(CPPFLAGS) $(GFLAGS) $(CFLAGS) $(DEFINES) -no-integrated-as -c $(INC) $< -o $(OBJROOT)/$*.o
$(OBJROOT)/%.o: %.m
$(CC) $(CPPFLAGS) $(GFLAGS) $(CFLAGS) $(DEFINES) -c $(INC) $< -o $(OBJROOT)/$*.o
$(CC) $(CPPFLAGS) $(GFLAGS) $(CFLAGS) $(DEFINES) -no-integrated-as -c $(INC) $< -o $(OBJROOT)/$*.o
.s.o:
$(CC) $(CPPFLAGS) $(GFLAGS) -no-integrated-as -c $(INC) -arch i386 -o $(OBJROOT)/$(@F) $<
boot2.o:
$(CC) $(CPPFLAGS)$(GFLAGS) -Wa,-n -c $(INC) -no-integrated-as -arch i386 -o $(OBJROOT)/$(@F) boot2.s
$(CC) $(CPPFLAGS)$(GFLAGS) -no-integrated-as -Wa,-n -c $(INC) -arch i386 -o $(OBJROOT)/$(@F) boot2.s
$(OBJROOT)/%.o: %.s
$(CC) $(CPPFLAGS) $(GFLAGS) -no-integrated-as -c $(INC) -arch i386 -o $(OBJROOT)/$(@F) $<
branches/cparm/i386/boot2/Makefile
2929
3030
3131
32
32
3333
3434
3535
......
7171
7272
7373
74
75
74
75
7676
7777
7878
-mpreferred-stack-boundary=2 -fno-align-functions \
-march=pentium4 -msse2 -mfpmath=sse -msoft-float -Qunused-arguments -ffreestanding -DBOOT_CORE
GFLAGS=
GFLAGS=
DEFINES=
CONFIG = hd
SYMDIR = $(SYMROOT)
CFLAGS += -DSAFE_MALLOC
#GFLAGS += -DNO_MULTIBOOT_SUPPORT
OBJS += mboot.o
GFLAGS += -DNO_MULTIBOOT_SUPPORT
#OBJS += mboot.o
# CFLAGS += -DBOOT_HELPER_SUPPORT # +992 bytes
branches/cparm/i386/modules/YellowIconFixer/YellowIconFixer.c
3131
3232
3333
34
3534
3635
3736
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
37
38
39
40
41
42
43
44
45
46
47
5348
54
55
56
57
58
49
50
51
52
53
5954
60
61
55
56
6257
63
64
65
66
58
59
6760
6861
6962
{
pci_dt_t* current = arg1;
struct DevPropDevice*device;
char*devicepath;
struct DevPropString *string;
if (current && current->class_id == PCI_CLASS_STORAGE_SATA)
{
devicepath = get_pci_dev_path(current);
if (devicepath)
{
string = (struct DevPropString *)(uint32_t)get_env(envEFIString);
if (!string)
{
string = devprop_create_string();
if (!string) return;
safe_set_env(envEFIString,(uint32_t)string);
}
device = devprop_add_device(string, devicepath);
if (!device) return;
string = (struct DevPropString *)(uint32_t)get_env(envEFIString);
if (!string)
{
string = devprop_create_string();
if (!string) return;
safe_set_env(envEFIString,(uint32_t)string);
}
device = devprop_add_device(string, current);
if (!device) return;
#if PROOFOFCONCEPT
uint16_t vendor_id = current->vendor_id & 0xFFFF;
uint16_t device_id = current->device_id & 0xFFFF;
devprop_add_value(device, "vendor-id", (uint8_t*)&vendor_id, 4);
devprop_add_value(device, "device-id", (uint8_t*)&device_id, 4);
uint16_t vendor_id = current->vendor_id & 0xFFFF;
uint16_t device_id = current->device_id & 0xFFFF;
devprop_add_value(device, "vendor-id", (uint8_t*)&vendor_id, 4);
devprop_add_value(device, "device-id", (uint8_t*)&device_id, 4);
#else
devprop_add_value(device, "device-id", default_SATA_ID, SATA_ID_LEN);
devprop_add_value(device, "device-id", default_SATA_ID, SATA_ID_LEN);
#endif
verbose("SATA device : [%04x:%04x :: %04x] :: %s\n",
current->vendor_id, current->device_id,current->class_id,
devicepath);
}
verbose("SATA device : [%04x:%04x :: %04x]\n",
current->vendor_id, current->device_id,current->class_id);
}
}
branches/cparm/i386/modules/GUI/gui.c
6969
7070
7171
72
73
74
75
7672
7773
7874
......
8884
8985
9086
91
9287
9388
9489
......
17501745
17511746
17521747
1748
1749
1750
1751
17531752
1754
1753
17551754
1756
1757
1758
1759
1760
1761
1755
1756
1757
1758
1759
1760
17621761
17631762
17641763
17651764
17661765
1767
1766
1767
17681768
1769
1770
1771
1769
17721770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
17731782
1774
17751783
17761784
1777
1785
17781786
1787
17791788
17801789
1781
1782
1783
1784
1785
17861790
17871791
17881792
......
18491853
18501854
18511855
1852
1856
1857
1858
18531859
18541860
1855
1856
18571861
1862
1863
1864
1865
1866
1867
1868
1869
18581870
1859
18601871
18611872
1862
1873
18631874
1875
18641876
18651877
1866
1867
1868
1869
1870
18711878
18721879
18731880
......
19291936
19301937
19311938
1939
19321940
19331941
19341942
19351943
1944
19361945
19371946
19381947
1939
19401948
19411949
19421950
19431951
1944
1952
1953
19451954
1946
1947
1948
1949
1955
1956
1957
1958
19501959
19511960
19521961
......
19541963
19551964
19561965
1957
1966
19581967
19591968
19601969
#include "art.h"
#endif
struct putc_info {
char * str;
char * last_str;
};
static int loadThemeImage(char *src, const char *image, int alt_image);
static void loadBootGraphics(char *src);
#if DEBUG_GUI
static int dprintf( window_t * window, const char * fmt, ...);
#endif
static void sputc(int c, struct putc_info * pi);
static inline
void vramwrite (void *data, int width);
}
}
struct putc_info {
char * str;
char * last_str;
};
static void
sputc(int c, struct putc_info * pi)
sputc(int c, void * pi)
{
if (pi->last_str)
if (pi->str == pi->last_str) {
*(pi->str) = '\0';
return;
}
*(pi->str)++ = c;
if (((struct putc_info*)pi)->last_str)
if (((struct putc_info*)pi)->str == ((struct putc_info*)pi)->last_str) {
*(((struct putc_info*)pi)->str) = '\0';
return;
}
*(((struct putc_info*)pi)->str)++ = c;
}
int gprintf( window_t * window, const char * fmt, ...)
{
char *formattedtext;
struct putc_info pi;
va_list ap;
struct putc_info pi;
if ((formattedtext = malloc(1024)) != NULL) {
position_torigin, cursor, bounds;
int i;
int character;
va_start(ap, fmt);
localVPrintf(fmt, ap, 0);
// format the text
va_start(ap, fmt);
pi.str = formattedtext;
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
__doprnt(fmt, ap, sputc, &pi, 10);
*pi.str = '\0';
va_end(ap);
position_torigin, cursor, bounds;
int i;
int character;
origin.x = MAX( window->cursor.x, window->hborder );
origin.y = MAX( window->cursor.y, window->vborder );
char *formattedtext;
va_list ap;
struct putc_info pi;
//window = &gui.debug;
struct putc_info pi;
if ((formattedtext = malloc(1024)) != NULL) {
position_torigin, cursor, bounds;
int i;
int character;
va_start(ap, fmt);
// format the text
va_start(ap, fmt);
pi.str = formattedtext;
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
__doprnt(fmt, ap, sputc, &pi, 10);
*pi.str = '\0';
va_end(ap);
position_torigin, cursor, bounds;
int i;
int character;
origin.x = MAX( gui.debug.cursor.x, window->hborder );
origin.y = MAX( gui.debug.cursor.y, window->vborder );
return 1;
}
#endif
int vprf(const char * fmt, va_list ap)
{
int i;
int character;
struct putc_info pi;
char *formattedtext;
window_t *window = &gui.screen;
struct putc_info pi;
position_torigin, cursor, bounds;
font_t *font = &font_console;
if ((formattedtext = malloc(1024)) != NULL) {
if ((formattedtext = malloc(1024)) != NULL){
// format the text
pi.str = formattedtext;
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
*pi.str = '\0';
pi.str = formattedtext;
pi.last_str = 0;
__doprnt(fmt, ap, sputc, &pi, 10);
*pi.str = '\0';
origin.x = MAX( window->cursor.x, window->hborder );
origin.y = MAX( window->cursor.y, window->vborder );
bounds.y = ( window->height - ( window->vborder * 2 ) );
cursor = origin;
for( i=0; i< strlen(formattedtext); i++ )
for( i=0; i< strlen(formattedtext) ; i++ )
{
character = formattedtext[i];
character -= 32;
branches/cparm/i386/modules/GUI/GUI_module.c
9393
9494
9595
96
96
9797
9898
9999
100
101
102
100103
101
102
103
104
105
106
107
108
109104
110105
111106
......
212207
213208
214209
215
210
216211
217212
218213
......
241236
242237
243238
244
245
246
247
239
240
241
242
243
248244
249
250245
251246
252247
......
12001195
12011196
12021197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
12031228
12041229
12051230
......
12101235
12111236
12121237
1213
1238
12141239
12151240
12161241
......
12181243
12191244
12201245
1221
1222
1246
1247
1248
1249
12231250
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
12351251
12361252
12371253
......
12451261
12461262
12471263
1248
1264
12491265
12501266
12511267
12521268
12531269
12541270
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1271
1272
1273
1274
1275
12681276
12691277
12701278
......
12781286
12791287
12801288
1281
1289
12821290
12831291
12841292
......
12901298
12911299
12921300
1293
1301
12941302
12951303
12961304
static int GUI_updateMenu( int key, void ** paramPtr );
static void GUI_showHelp(void);
static void GUI_showMessage(char *message);
/*
int GUI_printf(const char * fmt, ...);
int GUI_verbose(const char * fmt, ...);
void GUI_stop(const char * fmt, ...);
*/
int
GUI_reallyVPrint(const char *format, va_list ap, int flag);
/* console.c */
struct putc_info {
char * str;
char * last_str;
};
void sputc(int c, struct putc_info * pi);
static void (*showTextBuffer)(char *, int ) = NULL;
static char *(*getMemoryInfoString)(void) = NULL;
static BVRef (*getBvChain)(void) = NULL;
if(!get_env(envgVerboseMode))
{
// Disable outputs, they will still show in the boot log.
replace_system_function("_printf", &GUI_verbose);
replace_system_function("_printf", &verbose);
//drawBootGraphics();
}
replace_system_function("_addBootArg", &GUI_addBootArg);
replace_system_function("_showHelp", &GUI_showHelp);
replace_system_function("_printf", &GUI_printf);
replace_system_function("_verbose", &GUI_verbose);
replace_system_function("_stop", &GUI_stop);
replace_system_function("_reallyVPrint", &GUI_reallyVPrint);
//replace_system_function("_printf", &GUI_printf);
//replace_system_function("_verbose", &GUI_verbose);
//replace_system_function("_stop", &GUI_stop);
replace_system_function("_showMessage", &GUI_showMessage);
// Hook for the boot screen
register_hook_callback("GUI_ExecKernel", &GUI_ExecKernel_hook);
return 0;
}
int
GUI_reallyVPrint(const char *format, va_list ap, int flag)
{
#define LOG 1
#define PRINT 2
if (KernelStart == false)
{
if (flag & PRINT) {
if (getVideoMode() == VGA_TEXT_MODE)
{
prf(format, ap, putchar);
}
else
{
vprf(format, ap);
}
}
}
if (flag & LOG)
{
/* Kabyl: BooterLog */
prf(format, ap, debug_putc);
}
return 0;
}
#if 0
int GUI_verbose(const char * fmt, ...)
{
va_list ap;
{
if (getVideoMode() == VGA_TEXT_MODE)
{
prf(fmt, ap, putchar, 0);
prf(fmt, ap, putchar);
}
else
{
}
}
/* Kabyl: BooterLog */
struct putc_info pi;
{
/* Kabyl: BooterLog */
prf(fmt, ap, debug_putc);
}
if (!getConsoleMsg())
return 0;
if (((getConsoleCursor() - getConsoleMsg()) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
return 0;
pi.str = getConsoleCursor();
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
setConsoleCursor(getConsoleCursor() + strlen(getConsoleCursor()));
va_end(ap);
return(0);
}
if (getVideoMode() == VGA_TEXT_MODE)
{
prf(fmt, ap, putchar, 0);
prf(fmt, ap, putchar);
}
else
{
vprf(fmt, ap);
}
}
/* Kabyl: BooterLog */
struct putc_info pi;
if (!getConsoleMsg())
return 0;
if (((getConsoleCursor() - getConsoleMsg()) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
return 0;
pi.str = getConsoleCursor();
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
setConsoleCursor(getConsoleCursor() + strlen(getConsoleCursor()));
{
/* Kabyl: BooterLog */
prf(fmt, ap, debug_putc);
}
va_end(ap);
return 0;
}
if (getVideoMode() == VGA_TEXT_MODE)
{
prf(fmt, ap, putchar, 0);
prf(fmt, ap, putchar);
}
else
{
halt();
while (1);
}
#endif
void GUI_showHelp(void)
{
if (getVideoMode() == GRAPHICS_MODE) {
branches/cparm/i386/modules/Networking/Networking.c
104104
105105
106106
107
108
109
110
111
107
112108
113109
114110
115
111
116112
117113
118114
......
121117
122118
123119
124
120
125121
126122
127123
......
148144
149145
150146
151
152
153
154
155
147
156148
157149
158150
159
151
160152
161153
162154
......
165157
166158
167159
168
160
169161
170162
171163
}
static void set_eth_builtin(pci_dt_t *eth_dev)
{
char *devicepath = get_pci_dev_path(eth_dev);
if (!devicepath) {
return ;
}
{
struct DevPropDevice *device;
struct DevPropString *string = (struct DevPropString *)(uint32_t)get_env(envEFIString);
verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath);
verbose("LAN Controller [%04x:%04x]\n", eth_dev->vendor_id, eth_dev->device_id);
if (!string)
{
safe_set_env(envEFIString,(uint32_t)string);
}
device = devprop_add_device(string, devicepath);
device = devprop_add_device(string, eth_dev);
if(device)
{
verbose("Setting up lan keys\n");
static void set_wifi_airport(pci_dt_t *wlan_dev)
{
char tmp[16];
char *devicepath = get_pci_dev_path(wlan_dev);
if (!devicepath) {
return ;
}
struct DevPropDevice *device ;
struct DevPropString *string = (struct DevPropString *)(uint32_t)get_env(envEFIString);
verbose("Wifi Controller [%04x:%04x] :: %s\n", wlan_dev->vendor_id, wlan_dev->device_id, devicepath);
verbose("Wifi Controller [%04x:%04x]\n", wlan_dev->vendor_id, wlan_dev->device_id);
if (!string)
{
safe_set_env(envEFIString,(uint32_t)string);
}
device = devprop_add_device(string, devicepath);
device = devprop_add_device(string, wlan_dev);
if(device)
{
sprintf(tmp, "Airport");
branches/cparm/i386/modules/GraphicsEnabler/gma.c
9090
9191
9292
93
9493
9594
9695
......
9998
10099
101100
102
103
104
105
106101
107102
108103
109104
110105
111106
112
113
107
108
114109
115110
116111
......
120115
121116
122117
123
118
124119
125120
126121
bool setup_gma_devprop(pci_dt_t *gma_dev)
{
//intlen;
char *devicepath;
#if UNUSED
volatile uint8_t *regs;
#endif
uint8_t BuiltIn = 0x00;
uint8_t ClassFix[4] = { 0x00, 0x00, 0x03, 0x00 };
devicepath = get_pci_dev_path(gma_dev);
if (!devicepath) {
return false;
}
bar[0] = pci_config_read32(gma_dev->dev.addr, 0x10);
#if UNUSED
regs = (uint8_t *) (bar[0] & ~0x0f);
#endif
model = get_gma_model((gma_dev->vendor_id << 16) | gma_dev->device_id);
verbose("Intel %s [%04x:%04x] :: %s\n",
model, gma_dev->vendor_id, gma_dev->device_id, devicepath);
verbose("Intel %s [%04x:%04x]\n",
model, gma_dev->vendor_id, gma_dev->device_id);
struct DevPropString *string = (struct DevPropString *)(uint32_t)get_env(envEFIString);
if (!string)
safe_set_env(envEFIString,(uint32_t)string);
}
struct DevPropDevice *device = devprop_add_device(string, devicepath);
struct DevPropDevice *device = devprop_add_device(string, gma_dev);
if(!device)
{
branches/cparm/i386/modules/GraphicsEnabler/nvidia.c
12801280
12811281
12821282
1283
12841283
12851284
12861285
......
13101309
13111310
13121311
1313
1314
1315
1316
1317
1312
13181313
13191314
13201315
......
13291324
13301325
13311326
1332
1327
13331328
1334
1335
1329
13361330
13371331
13381332
......
14241418
14251419
14261420
1427
1421
14281422
14291423
14301424
......
14791473
14801474
14811475
1482
1476
14831477
14841478
14851479
bool setup_nvidia_devprop(pci_dt_t *nvda_dev)
{
struct DevPropDevice*device;
char*devicepath;
struct pci_rom_pci_header_t*rom_pci_header;
volatile uint8_t*regs;
uint8_t*rom;
dcfg_t default_dcfg_1;
bool dcfg0_set = false;
bool dcfg1_set = false;
devicepath = get_pci_dev_path(nvda_dev);
if (!devicepath) {
return false;
}
bar[0] = pci_config_read32(nvda_dev->dev.addr, 0x10 );
regs = (uint8_t *) (bar[0] & ~0x0f);
model = get_nvidia_model((nvda_dev->vendor_id << 16) | nvda_dev->device_id);
verbose("nVidia %s %dMB NV%02x [%04x:%04x] :: %s\n",
verbose("nVidia %s %dMB NV%02x [%04x:%04x]\n",
model, (uint32_t)(videoRam / 1024 / 1024),
(REG32(0) >> 20) & 0x1ff, nvda_dev->vendor_id, nvda_dev->device_id,
devicepath);
(REG32(0) >> 20) & 0x1ff, nvda_dev->vendor_id, nvda_dev->device_id);
rom = malloc(NVIDIA_ROM_SIZE);
if (!rom) {
safe_set_env(envEFIString,(uint32_t)string);
}
device = devprop_add_device(string, devicepath);
device = devprop_add_device(string, nvda_dev);
/* FIXME: for primary graphics card only */
boot_display = 1;
uint8_tnew_NVCAP[NVCAP_LEN];
if (hex2bin(value, new_NVCAP, NVCAP_LEN) == 0) {
verbose("Using user supplied NVCAP for %s :: %s\n", model, devicepath);
verbose("Using user supplied NVCAP for %s \n", model);
memcpy(default_NVCAP, new_NVCAP, NVCAP_LEN);
}
}
branches/cparm/i386/modules/GraphicsEnabler/ati.c
927927
928928
929929
930
930
931931
932932
933933
......
10261026
10271027
10281028
1029
1030
10291031
1032
1033
1034
10301035
10311036
10321037
10331038
1034
10351039
1036
1037
10381040
10391041
10401042
......
10971099
10981100
10991101
1100
1102
11011103
11021104
1105
1106
1107
11031108
11041109
11051110
......
11551160
11561161
11571162
1163
11581164
11591165
11601166
......
12391245
12401246
12411247
1242
1248
1249
1250
1251
1252
12431253
12441254
1255
1256
12451257
1258
12461259
1247
1248
1249
1250
12511260
12521261
12531262
......
15341543
15351544
15361545
1537
1538
15391546
15401547
15411548
......
15441551
15451552
15461553
1547
1548
1549
1550
1551
1552
1554
1555
15531556
15541557
15551558
1556
1559
15571560
15581561
15591562
......
15671570
15681571
15691572
1570
1573
15711574
1572
1575
15731576
15741577
15751578
1576
1577
1579
15781580
15791581
15801582
bool load_vbios_file(const char *key, uint16_t vendor_id, uint16_t device_id, uint32_t subsys_id);
void free_val(value_t *val);
void devprop_add_list(dev_prop_t devprop_list[]);
int devprop_add_list(dev_prop_t devprop_list[]);
bool get_bootdisplay_val(value_t *val)
{
uint8_t *rev;
if (!card->rom)
return false;
val->data = malloc(val->size);
if (!val->data)
return false;
rev = card->rom + *(uint8_t *)(card->rom + OFFSET_TO_GET_ATOMBIOS_STRINGS_START);
val->type = kPtr;
val->size = strlen((char *)rev);
val->data = malloc(val->size);
if (!val->data)
return false;
memcpy(val->data, rev, val->size);
bzero(val, sizeof(value_t));
}
void devprop_add_list(dev_prop_t devprop_list[])
int devprop_add_list(dev_prop_t devprop_list[])
{
value_t *val = malloc(sizeof(value_t));
if (!val) {
return -1;
}
int i, pnum;
for (i = 0; devprop_list[i].name != NULL; i++)
}
free(val);
return 0;
}
bool validate_rom(struct pci_rom_bios_t *rom_header, pci_dt_t *pci_dev)
if (!validate_rom(rom_addr, card->pci_dev))
return false;
card->rom = malloc(card->rom_size);
if (!card->rom)
return false;
card->rom_size = rom_addr->size * 512;
if (!card->rom_size)
{
free(card->rom);
return false;
}
card->rom = malloc(card->rom_size);
if (!card->rom)
return false;
memcpy(card->rom, (void *)rom_addr, card->rom_size);
return true;
bool setup_ati_devprop(pci_dt_t *ati_dev)
{
char *devicepath;
struct DevPropString *string = (struct DevPropString *)(uint32_t)get_env(envEFIString);
if (!string)
{
safe_set_env(envEFIString,(uint32_t)string);
}
devicepath = get_pci_dev_path(ati_dev);
if (!devicepath) {
return false;
}
verbose("ATI VGA Controller [%04x:%04x] :: %s \n",
ati_dev->vendor_id, ati_dev->device_id, devicepath);
verbose("ATI VGA Controller [%04x:%04x] \n",
ati_dev->vendor_id, ati_dev->device_id);
if (!init_card(ati_dev))
return false;
card->device = devprop_add_device(string, devicepath);
card->device = devprop_add_device(string, ati_dev);
if (!card->device)
return false;
// -------------------------------------------------
devprop_add_value(card->device, "ATY,IOSpaceOffset", &io, 8);
#endif
devprop_add_list(ati_devprop_list);
if (devprop_add_list(ati_devprop_list) == -1) return false; //fix me : remove all properties for this device
verbose("%s %dMB [%04x:%04x] (subsys [%04x:%04x]) (%s:%s) :: %s\n",
verbose("%s %dMB [%04x:%04x] (subsys [%04x:%04x]) (%s:%s) \n",
card->info->model_name, (uint32_t)(card->vram_size / (1024 * 1024)),
ati_dev->vendor_id, ati_dev->device_id,
ati_dev->subsys_id.subsys.vendor_id, ati_dev->subsys_id.subsys.device_id,
chip_family_name[card->info->chip_family], card->cfg_name,
devicepath);
chip_family_name[card->info->chip_family], card->cfg_name);
free(card);
branches/cparm/i386/modules/SMBiosGetters/smbios_decode.c
1414
1515
1616
17
18
1719
1820
21
22
1923
2024
2125
......
6670
6771
6872
69
70
71
73
74
75
7276
7377
7478
......
7882
7983
8084
81
82
83
84
85
86
87
88
8589
8690
8791
8892
89
93
94
9095
9196
9297
9398
9499
95
100
101
102
96103
97104
98105
99
100
106
107
101108
102109
103110
......
107114
108115
109116
110
111
112
113
114
115
116
117
118
119
120
121
122
123
117124
118125
119126
......
123130
124131
125132
126
127
128
129
130
133
134
135
136
137
131138
132139
133140
......
137144
138145
139146
140
141
142
143
144
145
146
147
148
147
148
149
150
151
152
153
154
155
149156
150157
151158
152
153
154
159
160
161
155162
156163
157164
......
161168
162169
163170
164
165
166
171
172
173
167174
168175
169176
170
171
172
173
174
177
178
179
180
181
175182
176183
177184
......
181188
182189
183190
184
191
185192
186193
187194
#if DEBUG_SMBIOS
#define DBG(x...)printf(x)
#define DBGSMBIOS(x,y)if(y) printf(x,y)
#else
#define DBG(x...)msglog(x)
#define DBGSMBIOS(x,y)if(y) msglog(x,y)
#endif
static void decodeBIOSInformation(SMBBIOSInformation *structHeader)
{
DBG("BIOSInformation:\n");
DBG("\tvendor: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->vendor));
DBG("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version));
DBG("\treleaseDate: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->releaseDate));
DBGSMBIOS("\tvendor: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->vendor));
DBGSMBIOS("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version));
DBGSMBIOS("\treleaseDate: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->releaseDate));
DBG("\n");
}
static void decodeSystemInformation(SMBSystemInformation *structHeader)
{
DBG("SystemInformation:\n");
DBG("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
DBG("\tproductName: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->productName));
DBG("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version));
DBG("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
DBGSMBIOS("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
DBGSMBIOS("\tproductName: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->productName));
DBGSMBIOS("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version));
DBGSMBIOS("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
if (minorVersion < 1 || structHeader->header.length < 25)
return;
uint8_t *uuid = structHeader->uuid;
DBG("\tuuid: %02X%02X%02X%02X-%02X%02X-%02X%02X-%02x%02X-%02X%02X%02X%02X%02X%02X\n",
if (uuid) {
DBG("\tuuid: %02X%02X%02X%02X-%02X%02X-%02X%02X-%02x%02X-%02X%02X%02X%02X%02X%02X\n",
uuid[0], uuid[1], uuid[2], uuid[3],
uuid[4], uuid[5],
uuid[6], uuid[7],
uuid[8], uuid[9],
uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
DBG("\twakeupReason: 0x%x\n", structHeader->wakeupReason);
}
DBGSMBIOS("\twakeupReason: 0x%x\n", structHeader->wakeupReason);
if (minorVersion < 4 || structHeader->header.length < 27)
return;
DBG("\tskuNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->skuNumber));
DBG("\tfamily: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->family));
DBGSMBIOS("\tskuNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->skuNumber));
DBGSMBIOS("\tfamily: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->family));
DBG("\n");
}
static void decodeBaseBoard(SMBBaseBoard *structHeader)
{
DBG("BaseBoard:\n");
DBG("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
DBG("\tproduct: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->product));
DBG("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version));
DBG("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
DBG("\tassetTagNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTagNumber));
DBG("\tlocationInChassis: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->locationInChassis));
DBG("\tboardType: 0x%X\n", structHeader->boardType);
DBGSMBIOS("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
DBGSMBIOS("\tproduct: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->product));
DBGSMBIOS("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version));
DBGSMBIOS("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
DBGSMBIOS("\tassetTagNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTagNumber));
DBGSMBIOS("\tlocationInChassis: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->locationInChassis));
DBGSMBIOS("\tboardType: 0x%X\n", structHeader->boardType);
DBG("\n");
}
static void decodeSystemEnclosure(SMBSystemEnclosure *structHeader)
{
DBG("SystemEnclosure:\n");
DBG("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
DBG("\ttype: %d\n", structHeader->type);
DBG("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version));
DBG("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
DBG("\tassetTagNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTagNumber));
DBGSMBIOS("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
DBGSMBIOS("\ttype: %d\n", structHeader->type);
DBGSMBIOS("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version));
DBGSMBIOS("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
DBGSMBIOS("\tassetTagNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTagNumber));
DBG("\n");
}
static void decodeProcessorInformation(SMBProcessorInformation *structHeader)
{
DBG("ProcessorInformation:\n");
DBG("\tsocketDesignation: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->socketDesignation));
DBG("\tprocessorType: %d\n", structHeader->processorType);
DBG("\tprocessorFamily: 0x%X\n", structHeader->processorFamily);
DBG("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
DBG("\tprocessorID: 0x%llX\n", structHeader->processorID);
DBG("\tprocessorVersion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->processorVersion));
DBG("\texternalClock: %dMHz\n", structHeader->externalClock);
DBG("\tmaximumClock: %dMHz\n", structHeader->maximumClock);
DBG("\tcurrentClock: %dMHz\n", structHeader->currentClock);
DBGSMBIOS("\tsocketDesignation: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->socketDesignation));
DBGSMBIOS("\tprocessorType: %d\n", structHeader->processorType);
DBGSMBIOS("\tprocessorFamily: 0x%X\n", structHeader->processorFamily);
DBGSMBIOS("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
DBGSMBIOS("\tprocessorID: 0x%llX\n", structHeader->processorID);
DBGSMBIOS("\tprocessorVersion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->processorVersion));
DBGSMBIOS("\texternalClock: %dMHz\n", structHeader->externalClock);
DBGSMBIOS("\tmaximumClock: %dMHz\n", structHeader->maximumClock);
DBGSMBIOS("\tcurrentClock: %dMHz\n", structHeader->currentClock);
if (minorVersion < 3 || structHeader->header.length < 35)
return;
DBG("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
DBG("\tassetTag: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag));
DBG("\tpartNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->partNumber));
DBGSMBIOS("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
DBGSMBIOS("\tassetTag: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag));
DBGSMBIOS("\tpartNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->partNumber));
DBG("\n");
}
static void decodeMemoryDevice(SMBMemoryDevice *structHeader)
{
DBG("MemoryDevice:\n");
DBG("\tdeviceLocator: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->deviceLocator));
DBG("\tbankLocator: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->bankLocator));
DBG("\tmemoryType: %s\n", SMBMemoryDeviceTypes[structHeader->memoryType]);
DBGSMBIOS("\tdeviceLocator: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->deviceLocator));
DBGSMBIOS("\tbankLocator: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->bankLocator));
DBGSMBIOS("\tmemoryType: %s\n", SMBMemoryDeviceTypes[structHeader->memoryType]);
if (minorVersion < 3 || structHeader->header.length < 27)
return;
DBG("\tmemorySpeed: %dMHz\n", structHeader->memorySpeed);
DBG("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
DBG("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
DBG("\tassetTag: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag));
DBG("\tpartNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->partNumber));
DBGSMBIOS("\tmemorySpeed: %dMHz\n", structHeader->memorySpeed);
DBGSMBIOS("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
DBGSMBIOS("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
DBGSMBIOS("\tassetTag: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag));
DBGSMBIOS("\tpartNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->partNumber));
DBG("\n");
}
static void decodeOemProcessorType(SMBOemProcessorType *structHeader)
{
DBG("AppleProcessorType:\n");
DBG("\tProcessorType: 0x%x\n", ((SMBOemProcessorType *)structHeader)->ProcessorType);
DBGSMBIOS("\tProcessorType: 0x%x\n", ((SMBOemProcessorType *)structHeader)->ProcessorType);
DBG("\n");
}
branches/cparm/i386/modules/USBFix/usb.c
4343
4444
4545
46
47
48
4649
4750
4851
......
5457
5558
5659
60
61
62
5763
5864
5965
if(!usbList)
{
usbList = (struct pciList*)malloc(sizeof(struct pciList));
if (!usbList) {
return;
}
usbList->next = NULL;
usbList->pciDev = pci_dev;
current = current->next;
}
current->next = (struct pciList*)malloc(sizeof(struct pciList));
if (!current) {
return;
}
current = current->next;
current->pciDev = pci_dev;
branches/cparm/i386/modules/Resolution/915resolution.c
247247
248248
249249
250
251
252
253
250254
251255
252256
{
UInt32 z;
vbios_map * map = malloc(sizeof(vbios_map));
if (!map) {
return 0;
}
for(z=0; z<sizeof(vbios_map); z++) ((char*)map)[z]=0;
/*
* Determine chipset
branches/cparm/i386/modules/Resolution/edid.c
141141
142142
143143
144
145
146
144147
145148
146149
} while(blocks_left);
char* ret = malloc(sizeof(edidInfo));
if (!ret) {
return 0;
}
memcpy(ret, edidInfo, sizeof(edidInfo));
return ret;
}
branches/cparm/i386/libsa/prf.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
/*
* Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
* Reserved. This file contains Original Code and/or Modifications of
* Original Code as defined in and that are subject to the Apple Public
* Source License Version 2.0 (the "License"). You may not use this file
* except in compliance with the License. Please obtain a copy of the
* License at http://www.apple.com/publicsource and read it before using
* this file.
*
* The Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* Mach Operating System
* Copyright (c) 1990 Carnegie-Mellon University
* Copyright (c) 1989 Carnegie-Mellon University
* Copyright (c) 1988 Carnegie-Mellon University
* Copyright (c) 1987 Carnegie-Mellon University
* All rights reserved. The CMU software License Agreement specifies
* the terms and conditions for use and redistribution.
*/
/*
* Copyright (c) 1982, 1986 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*
*@(#)prf.c7.1 (Berkeley) 6/5/86
*/
#include <sys/param.h>
#define SPACE1
#define ZERO2
#define UCASE 16
/*
* Scaled down version of C Library printf.
* Used to print diagnostic information directly on console tty.
* Since it is not interrupt driven, all system activities are
* suspended.
*
*/
/*
* Printn prints a number n in base b.
* We don't use recursion to avoid deep kernel stacks.
*/
static void
printn(n, b, flag, minwidth, putfn_p, putfn_arg)
u_long n;
int b, flag, minwidth;
void (*putfn_p)();
void *putfn_arg;
{
char prbuf[11];
register char *cp;
int width = 0, neg = 0;
if (b == 10 && (int)n < 0) {
neg = 1;
n = (unsigned)(-(int)n);
}
cp = prbuf;
do {
*cp++ = "0123456789abcdef0123456789ABCDEF"[(flag & UCASE) + n%b];
n /= b;
width++;
} while (n);
if (neg) {
(*putfn_p)('-', putfn_arg);
width++;
}
while (width++ < minwidth)
(*putfn_p)( (flag & ZERO) ? '0' : ' ', putfn_arg);
do
(*putfn_p)(*--cp, putfn_arg);
while (cp > prbuf);
}
int prf(
char *fmt,
unsigned int *adx,
void (*putfn_p)(),
void *putfn_arg
);
int prf(
char *fmt,
unsigned int *adx,
void (*putfn_p)(),
void *putfn_arg
)
{
int b, c, len =0;
char *s;
int flag = 0, width = 0;
int minwidth;
loop:
while ((c = *fmt++) != '%') {
if(c == '\0')
return len;
if (putfn_p) {
(*putfn_p)(c, putfn_arg);
}
len++;
}
minwidth = 0;
again:
c = *fmt++;
switch (c) {
case 'l':
goto again;
case ' ':
flag |= SPACE;
goto again;
case '0':
if (minwidth == 0) {
/* this is a flag */
flag |= ZERO;
goto again;
} /* fall through */
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
minwidth *= 10;
minwidth += c - '0';
goto again;
case 'X':
flag |= UCASE;
/* fall through */
case 'x':
b = 16;
goto number;
case 'd':
b = 10;
goto number;
case 'o': case 'O':
b = 8;
number:
if (putfn_p) {
printn((u_long)*adx, b, flag, minwidth, putfn_p, putfn_arg);
}
len++;
break;
case 's':
s = (char *)*adx;
while ((c = *s++)) {
if (putfn_p) {
(*putfn_p)(c, putfn_arg);
}
len++;
width++;
}
while (width++ < minwidth) {
if (putfn_p) {
(*putfn_p)(' ', putfn_arg);
}
len++;
}
break;
case 'c':
if (putfn_p) {
(*putfn_p)((char)*adx, putfn_arg);
}
len++;
break;
default:
break;
}
adx++;
goto loop;
}
branches/cparm/i386/libsa/libsa.h
112112
113113
114114
115
116
115
116
117117
118118
119119
120120
121121
122
122
123
124
125
126
127
128
129
130
123131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
124148
125149
126150
/*
* prf.c
*/
extern int prf(const char * fmt, va_list ap, void (*putfn_p)(),
void * putfn_arg);
//extern int prf(const char * fmt, va_list ap, void (*putfn_p)(),
// void * putfn_arg);
/*
* printf.c
*/
extern int sprintf(char *s, const char * format, ...);
extern int slvprintf(char * buffer, int len, const char * fmt, va_list arg);
extern int snprintf(char *str, size_t size, const char *format, ...);
extern int vsnprintf(char *str, size_t size, const char *format, va_list ap);
extern void
_doprnt(
register const char *fmt,
va_list argp,
/* character output routine */
void (*putc)(char),
int radix); /* default radix - for '%r' */
extern int
prf(
const char*fmt,
va_listap,
/* character output routine */
void(*putc)(char));
extern int
__doprnt(
const char*fmt,
va_listargp,
/* character output routine */
void(*putc)(int ch, void *arg),
void *arg,
intradix);
/*
* zalloc.c
*/
branches/cparm/i386/libsa/printf.c
11
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
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
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
2656
3657
4658
......
21675
22676
23677
678
679
680
681
682
683
684
685
686
24687
25
26
688
689
690
691
692
27693
694
28695
29
696
697
698
30699
31
32
33
34
700
701
702
703
704
705
706
35707
36
37
38
39
708
709
710
711
712
713
40714
41
42
43
44
45
46
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
47749
48750
49
50
51
751
752
753
754
755
756
757
52758
53
54
55
56
57
58
59
60
61
62
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
63841
64
65
66
67
68
69
70
71
72
73
74
842
/*
* Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
/*-
* Copyright (c) 1986, 1988, 1991, 1993
* The Regents of the University of California. All rights reserved.
* (c) UNIX System Laboratories, Inc.
* All or some portions of this file are derived from material licensed
* to the University of California by American Telephone and Telegraph
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)subr_prf.c 8.4 (Berkeley) 5/4/95
*/
/*
* @OSF_COPYRIGHT@
*/
/*
* Mach Operating System
* Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*/
#include "libsa.h"
struct snprintf_arg {
char *str;
size_t remain;
};
static void
dummy_putc(int ch, void *arg)
{
void (*real_putc)() = arg;
if (real_putc) real_putc(ch);
}
#if 0
void
_doprnt(
register const char *fmt,
va_list argp,
/* character output routine */
void (*putc)(),
int radix) /* default radix - for '%r' */
{
__doprnt(fmt, argp, dummy_putc, putc, radix);
}
#define Ctod(c) ((c) - '0')
#define MAXBUF (sizeof(long long int) * 8)/* enough for binary */
static char digs[] = "0123456789abcdef";
static int
printnum(
unsigned long long intu,/* number to print */
intbase,
void(*putc)(int, void *),
void *arg)
{
charbuf[MAXBUF];/* build number here */
char *p = &buf[MAXBUF-1];
int nprinted = 0;
do {
*p-- = digs[u % base];
u /= base;
} while (u != 0);
while (++p != &buf[MAXBUF]) {
if (putc) (*putc)(*p, arg);
nprinted++;
}
return nprinted;
}
bool_doprnt_truncates = false;
int
__doprnt(
const char*fmt,
va_listargp,
/* character output routine */
void(*putc)(int ch, void *arg),
void *arg,
intradix)/* default radix - for '%r' */
{
intlength;
intprec;
boolladjust;
charpadc;
long longn;
unsigned long longu;
intplus_sign;
intsign_char;
boolaltfmt, truncate;
intbase;
charc;
intcapitals;
intlong_long;
int nprinted = 0;
while ((c = *fmt) != '\0') {
if (c != '%') {
if (putc) {
(*putc)(c, arg);
}
nprinted++;
fmt++;
continue;
}
fmt++;
long_long = 0;
length = 0;
prec = -1;
ladjust = false;
padc = ' ';
plus_sign = 0;
sign_char = 0;
altfmt = false;
while (true) {
c = *fmt;
if (c == '#') {
altfmt = true;
}
else if (c == '-') {
ladjust = true;
}
else if (c == '+') {
plus_sign = '+';
}
else if (c == ' ') {
if (plus_sign == 0)
plus_sign = ' ';
}
else
break;
fmt++;
}
if (c == '0') {
padc = '0';
c = *++fmt;
}
if (isdigit(c)) {
while(isdigit(c)) {
length = 10 * length + Ctod(c);
c = *++fmt;
}
}
else if (c == '*') {
length = va_arg(argp, int);
c = *++fmt;
if (length < 0) {
ladjust = !ladjust;
length = -length;
}
}
if (c == '.') {
c = *++fmt;
if (isdigit(c)) {
prec = 0;
while(isdigit(c)) {
prec = 10 * prec + Ctod(c);
c = *++fmt;
}
}
else if (c == '*') {
prec = va_arg(argp, int);
c = *++fmt;
}
}
if (c == 'l') {
c = *++fmt;/* need it if sizeof(int) < sizeof(long) */
if (sizeof(int)<sizeof(long))
long_long = 1;
if (c == 'l') {
long_long = 1;
c = *++fmt;
}
} else if (c == 'q' || c == 'L') {
long_long = 1;
c = *++fmt;
}
truncate = false;
capitals=0;/* Assume lower case printing */
switch(c) {
case 'b':
case 'B':
{
register char *p;
boolean_t any;
register int i;
if (long_long) {
u = va_arg(argp, unsigned long long);
} else {
u = va_arg(argp, unsigned int);
}
p = va_arg(argp, char *);
base = *p++;
nprinted += printnum(u, base, putc, arg);
if (u == 0)
break;
any = false;
while ((i = *p++) != '\0') {
if (*fmt == 'B')
i = 33 - i;
if (*p <= 32) {
/*
* Bit field
*/
register int j;
if (any)
if (putc) (*putc)(',', arg);
else {
if (putc) (*putc)('<', arg);
any = true;
}
nprinted++;
j = *p++;
if (*fmt == 'B')
j = 32 - j;
for (; (c = *p) > 32; p++) {
if (putc) (*putc)(c, arg);
nprinted++;
}
nprinted += printnum((unsigned)( (u>>(j-1)) & ((2<<(i-j))-1)),
base, putc, arg);
}
else if (u & (1<<(i-1))) {
if (any)
if (putc) (*putc)(',', arg);
else {
if (putc) (*putc)('<', arg);
any = true;
}
nprinted++;
for (; (c = *p) > 32; p++) {
if (putc) (*putc)(c, arg);
nprinted++;
}
}
else {
for (; *p > 32; p++)
continue;
}
}
if (any) {
if (putc) (*putc)('>', arg);
nprinted++;
}
break;
}
case 'c':
c = va_arg(argp, int);
if (putc) (*putc)(c, arg);
nprinted++;
break;
case 's':
{
register const char *p;
register const char *p2;
if (prec == -1)
prec = 0x7fffffff;/* MAXINT */
p = va_arg(argp, char *);
if (p == NULL)
p = "";
if (length > 0 && !ladjust) {
n = 0;
p2 = p;
for (; *p != '\0' && n < prec; p++)
n++;
p = p2;
while (n < length) {
if (putc) (*putc)(' ', arg);
n++;
nprinted++;
}
}
n = 0;
while ((n < prec) && (!(length > 0 && n >= length))) {
if (*p == '\0') {
break;
}
if (putc) (*putc)(*p++, arg);
nprinted++;
n++;
}
if (n < length && ladjust) {
while (n < length) {
if (putc) (*putc)(' ', arg);
n++;
nprinted++;
}
}
break;
}
case 'o':
truncate = _doprnt_truncates;
case 'O':
base = 8;
goto print_unsigned;
case 'D': {
unsigned char *up;
char *q, *p;
up = (unsigned char *)va_arg(argp, unsigned char *);
p = (char *)va_arg(argp, char *);
if (length == -1)
length = 16;
while(length--) {
if (putc) (*putc)(digs[(*up >> 4)], arg);
if (putc) (*putc)(digs[(*up & 0x0f)], arg);
nprinted += 2;
up++;
if (length) {
for (q=p;*q;q++) {
if (putc) (*putc)(*q, arg);
nprinted++;
}
}
}
break;
}
case 'd':
truncate = _doprnt_truncates;
base = 10;
goto print_signed;
case 'u':
truncate = _doprnt_truncates;
case 'U':
base = 10;
goto print_unsigned;
case 'p':
altfmt = true;
if (sizeof(int)<sizeof(void *)) {
long_long = 1;
}
case 'x':
truncate = _doprnt_truncates;
base = 16;
goto print_unsigned;
case 'X':
base = 16;
capitals=16;/* Print in upper case */
goto print_unsigned;
case 'z':
truncate = _doprnt_truncates;
base = 16;
goto print_signed;
case 'Z':
base = 16;
capitals=16;/* Print in upper case */
goto print_signed;
case 'r':
truncate = _doprnt_truncates;
case 'R':
base = radix;
goto print_signed;
case 'n':
truncate = _doprnt_truncates;
case 'N':
base = radix;
goto print_unsigned;
print_signed:
if (long_long) {
n = va_arg(argp, long long);
} else {
n = va_arg(argp, int);
}
if (n >= 0) {
u = n;
sign_char = plus_sign;
}
else {
u = -n;
sign_char = '-';
}
goto print_num;
print_unsigned:
if (long_long) {
u = va_arg(argp, unsigned long long);
} else {
u = va_arg(argp, unsigned int);
}
goto print_num;
print_num:
{
charbuf[MAXBUF];/* build number here */
register char *p = &buf[MAXBUF-1];
static char digits[] = "0123456789abcdef0123456789ABCDEF";
const char *prefix = NULL;
if (truncate) u = (long long)((int)(u));
if (u != 0 && altfmt) {
if (base == 8)
prefix = "0";
else if (base == 16)
prefix = "0x";
}
do {
/* Print in the correct case */
*p-- = digits[(u % base)+capitals];
u /= base;
} while (u != 0);
length -= (int)(&buf[MAXBUF-1] - p);
if (sign_char)
length--;
if (prefix)
length -= (int)strlen(prefix);
if (padc == ' ' && !ladjust) {
/* blank padding goes before prefix */
while (--length >= 0) {
if (putc) (*putc)(' ', arg);
nprinted++;
}
}
if (sign_char) {
if (putc) (*putc)(sign_char, arg);
nprinted++;
}
if (prefix) {
while (*prefix) {
if (putc) (*putc)(*prefix++, arg);
nprinted++;
}
}
if (padc == '0') {
/* zero padding goes after sign and prefix */
while (--length >= 0) {
if (putc) (*putc)('0', arg);
nprinted++;
}
}
while (++p != &buf[MAXBUF]) {
(*putc)(*p, arg);
nprinted++;
}
if (ladjust) {
while (--length >= 0) {
if (putc) (*putc)(' ', arg);
nprinted++;
}
}
break;
}
case '\0':
fmt--;
break;
default:
if (putc) (*putc)(c, arg);
nprinted++;
}
fmt++;
}
return nprinted;
}
#endif
int
prf(
const char*fmt,
va_listap,
/* character output routine */
void(*putc)(char))
{
return __doprnt(fmt, ap, dummy_putc, putc, 10);
}
static char *copybyte_str;
static void
copybyte(
char byte)
{
*copybyte_str++ = byte;
*copybyte_str = '\0';
}
int
sprintf(char *buf, const char *fmt, ...)
{
va_list listp;
va_start(listp, fmt);
copybyte_str = buf;
prf(fmt, listp, copybyte);
va_end(listp);
return strlen(buf);
}
static void
snprintf_func(int ch, void *arg)
{
struct snprintf_arg *const info = arg;
if (info->remain >= 2) {
*info->str++ = ch;
info->remain--;
}
}
/*
* Scaled down version of vsnprintf(3).
*/
int
vsnprintf(char *str, size_t size, const char *format, va_list ap)
{
struct snprintf_arg info;
int retval;
info.str = str;
info.remain = size;
retval = __doprnt(format, ap, snprintf_func, &info, 10);
if (info.remain >= 1)
*info.str++ = '\0';
return retval;
}
/*
* Scaled down version of snprintf(3).
*/
int
snprintf(char *str, size_t size, const char *format, ...)
{
int retval;
va_list ap;
va_start(ap, format);
retval = vsnprintf(str, size, format, ap);
va_end(ap);
return(retval);
}
#if 1
/*
* Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* Mach Operating System
* Copyright (c) 1990 Carnegie-Mellon University
* Copyright (c) 1989 Carnegie-Mellon University
* Copyright (c) 1988 Carnegie-Mellon University
* Copyright (c) 1987 Carnegie-Mellon University
* All rights reserved. The CMU software License Agreement specifies
* the terms and conditions for use and redistribution.
*/
/*
* Copyright 1993 NeXT, Inc.
* All rights reserved.
* Copyright (c) 1982, 1986 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*
*@(#)prf.c7.1 (Berkeley) 6/5/86
*/
#include <sys/param.h>
#include "libsa.h"
#define SPACE1
#define ZERO2
#define UCASE 16
struct putc_info {
char * str;
char * last_str;
};
/*
* Scaled down version of C Library printf.
* Used to print diagnostic information directly on console tty.
* Since it is not interrupt driven, all system activities are
* suspended.
*
*/
static void
sputc(int c, struct putc_info * pi);
static void
sputc(int c, struct putc_info * pi)
/*
* Printn prints a number n in base b.
* We don't use recursion to avoid deep kernel stacks.
*/
static int
printn(u_long n, int b, int flag, int minwidth, void (*putfn_p)(int ch, void *arg), void *putfn_arg)
{
if (pi->last_str)
if (pi->str == pi->last_str) {
*(pi->str) = '\0';
return;
}
*(pi->str)++ = c;
char prbuf[11];
register char *cp;
int width = 0, neg = 0, len = 0;
if (b == 10 && (int)n < 0) {
neg = 1;
n = (unsigned)(-(int)n);
}
cp = prbuf;
do {
*cp++ = "0123456789abcdef0123456789ABCDEF"[(flag & UCASE) + n%b];
n /= b;
width++;
} while (n);
if (neg) {
(*putfn_p)('-', putfn_arg);
width++;
len++;
}
while (width++ < minwidth)
{
(*putfn_p)( (flag & ZERO) ? '0' : ' ', putfn_arg);
len++;
}
do
{
(*putfn_p)(*--cp, putfn_arg);
len++;
} while (cp > prbuf);
return len;
}
/*VARARGS1*/
/* now slprintf() return the length of the string as in man sprintf()*/
int sprintf(char * str, const char * fmt, ...)
int __doprnt(
const char *fmt,
va_list argp,
void (*putfn_p)(int ch, void *arg),
void *putfn_arg,
int radix
)
{
va_list ap;
struct putc_info pi;
va_start(ap, fmt);
pi.str = str;
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
*pi.str = '\0';
va_end(ap);
return (pi.str - str);
int b, c, len =0;
char *s;
int flag = 0, width = 0;
int minwidth;
unsigned int *adx = (unsigned int*)argp;
loop:
while ((c = *fmt++) != '%') {
if(c == '\0')
return len;
if (putfn_p) {
(*putfn_p)(c, putfn_arg);
}
len++;
}
minwidth = 0;
again:
c = *fmt++;
switch (c) {
case 'l':
goto again;
case ' ':
flag |= SPACE;
goto again;
case '0':
if (minwidth == 0) {
/* this is a flag */
flag |= ZERO;
goto again;
} /* fall through */
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
minwidth *= 10;
minwidth += c - '0';
goto again;
case 'X':
flag |= UCASE;
/* fall through */
case 'x':
b = 16;
goto number;
case 'd':
b = 10;
goto number;
case 'o': case 'O':
b = 8;
number:
len += printn((u_long)*adx, b, flag, minwidth, putfn_p, putfn_arg);
break;
case 's':
s = (char *)*adx;
while ((c = *s++)) {
if (putfn_p) {
(*putfn_p)(c, putfn_arg);
}
len++;
width++;
}
while (width++ < minwidth) {
if (putfn_p) {
(*putfn_p)(' ', putfn_arg);
}
len++;
}
break;
case 'c':
if (putfn_p) {
(*putfn_p)((char)*adx, putfn_arg);
}
len++;
break;
default:
break;
}
adx++;
goto loop;
}
/*VARARGS1*/
int slvprintf(char * str, int len, const char * fmt, va_list ap)
{
struct putc_info pi;
pi.str = str;
pi.last_str = str + len - 1;
prf(fmt, ap, sputc, &pi);
*pi.str = '\0';
return (pi.str - str);
}
#endif
branches/cparm/i386/libsa/Makefile
1010
1111
1212
13
14
13
14
1515
1616
1717
......
2525
2626
2727
28
28
2929
3030
3131
OPTIM = -Os -Oz
CFLAGS= $(RC_CFLAGS) $(OPTIM) $(MORECPP) -arch i386 -g -Wmost -Werror -fno-stack-protector \
-fno-builtin -static $(OMIT_FRAME_POINTER_CFLAG) \
-march=pentium4 -msse2 -msoft-float -Qunused-arguments -ffreestanding -DBOOT_CORE -mpreferred-stack-boundary=2 -fno-align-functions -mfpmath=sse
-march=pentium4 -msse2 -msoft-float -Qunused-arguments -ffreestanding -DBOOT_CORE -mpreferred-stack-boundary=2 -fno-align-functions -mfpmath=sse
GFLAGS=
INC = -I. -I$(SYMROOT) -I$(UTILDIR) -I$(LIBSAIODIR)
ifneq "" "$(wildcard /bin/mkdirs)"
MKDIRS = /bin/mkdirs
VPATH = $(OBJROOT):$(SYMROOT)
SA_OBJS = qdivrem.o umoddi3.o udivdi3.o divdi3.o moddi3.o bzero.o bcopy.o prf.o printf.o zalloc.o\
SA_OBJS = qdivrem.o umoddi3.o udivdi3.o divdi3.o moddi3.o bzero.o bcopy.o printf.o zalloc.o\
string.o strtol.o \
setjmp.o qsort.o efi_tables.o

Archive Download the corresponding diff file

Revision: 1984