Chameleon

Chameleon Commit Details

Date:2011-08-06 20:10:27 (8 years 3 months ago)
Author:Evan Lojewski
Commit:1302
Parents: 1301
Message:Clean up libsaio
Changes:
D/branches/xZenu/src/arch/i386/libsaio/sl.h
A/branches/xZenu/src/arch/i386/libsaio/memory.h
M/branches/xZenu/src/arch/i386/libsaio/console.c
M/branches/xZenu/src/arch/i386/libsaio/saio_types.h
M/branches/xZenu/src/arch/i386/libsaio/xml.h
M/branches/xZenu/src/arch/i386/libsaio/libsaio.h
M/branches/xZenu/src/arch/i386/libsaio/misc.c
M/branches/xZenu/src/arch/i386/libsaio/saio_internal.h
M/branches/xZenu/src/arch/i386/libsaio/load.c
M/branches/xZenu/src/arch/i386/libsaio/biosfn.c
M/branches/xZenu/src/arch/i386/libsaio/xml.c

File differences

branches/xZenu/src/arch/i386/libsaio/sl.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
/*
* 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@
*/
#ifndef __LIBSAIO_SL_H
#define __LIBSAIO_SL_H
#include <sys/types.h>
#include <sys/param.h>
#include <mach/i386/thread_status.h>
#include "libsaio.h"
#define SWAP_BE16(x) OSSwapBigToHostInt16(x)
#define SWAP_LE16(x) OSSwapLittleToHostInt16(x)
#define SWAP_BE32(x) OSSwapBigToHostInt32(x)
#define SWAP_LE32(x) OSSwapLittleToHostInt32(x)
#define SWAP_BE64(x) OSSwapBigToHostInt64(x)
#define SWAP_LE64(x) OSSwapLittleToHostInt64(x)
// File Permissions and Types
enum {
kPermOtherExecute = 1 << 0,
kPermOtherWrite = 1 << 1,
kPermOtherRead = 1 << 2,
kPermGroupExecute = 1 << 3,
kPermGroupWrite = 1 << 4,
kPermGroupRead = 1 << 5,
kPermOwnerExecute = 1 << 6,
kPermOwnerWrite = 1 << 7,
kPermOwnerRead = 1 << 8,
kPermMask = 0x1FF,
kOwnerNotRoot = 1 << 9,
kFileTypeUnknown = 0x0 << 16,
kFileTypeFlat = 0x1 << 16,
kFileTypeDirectory = 0x2 << 16,
kFileTypeLink = 0x3 << 16,
kFileTypeMask = 0x3 << 16
};
#define Seek(c, p) diskSeek(c, p);
#define Read(c, a, l) diskRead(c, a, l);
extern void * gFSLoadAddress;
extern cpu_type_t archCpuType;
cpu_type_t detectCpuType ();
#endif /* !__LIBSAIO_SL_H */
branches/xZenu/src/arch/i386/libsaio/xml.c
2222
2323
2424
25
26
27
2528
26
2729
2830
2931
* @APPLE_LICENSE_HEADER_END@
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "libsaio.h"
#include "sl.h"
#include "xml.h"
string_ref *ref_strings = NULL;
branches/xZenu/src/arch/i386/libsaio/console.c
4646
4747
4848
49
50
5149
52
5350
5451
5552
#include "libsaio.h"
bool gVerboseMode;
bool gErrors;
/*
* write one character to console
*/
branches/xZenu/src/arch/i386/libsaio/xml.h
2525
2626
2727
28
29
30
31
2832
2933
3034
#ifndef __LIBSAIO_XML_H
#define __LIBSAIO_XML_H
typedef char bool;
#define false 0
#define true 1
enum xmltype {
kTagTypeNone = 0,
kTagTypeDict,
branches/xZenu/src/arch/i386/libsaio/memory.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
/*
* 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@
*/
#ifndef __BOOT_MEMORY_H
#define __BOOT_MEMORY_H
/* Memory addresses used by booter and friends */
/* DFE 2007-12-21: Changed BASE_SEG to be conditional
This allows boot1u and other planned first-stage booters to avoid
maintaining their own copies of asm.s and bios.s and instead
simply build the files from libsaio with the right preprocessor
definitions.
This affects BASE_ADDR and OFFSET16() thus obviating the need for
separate BASE1U_ADDR and OFFSET1U16() macros.
Be careful though as changing these values with preprocessor macros
obviously requires rebuilding the source files. That means in particular
that libsaio.a is only suitable for boot2.
*/
#if defined(BASE_SEG)
/* assume user knows what he's doing */
#elif defined(BOOT1)
# define BASE_SEG BOOT1U_SEG
#else
# define BASE_SEG BOOT2_SEG
#endif
#define STACK_SEG0x1000// zef: old STACK_SEG 0x5000
#define STACK_OFS0xFFF0// stack pointer
#define BOOT1U_SEG0x1000
#define BOOT1U_OFS0x0200
#define BOOT2_SEG0x2000
#define BOOT2_OFS0x0200// 512 byte disk sector offset
#define BOOT2_MAX_LENGTH0x6FE00// Maximum size for boot2 is currentl 447kb
#define BIOS_ADDR0x8000// BIOS disk I/O buffer
#define BIOS_LEN0x8000// 32K - divisible by 512 and 2048
#define BOOT0_ADDR0x7E00// boot0 gets loaded here
/* These are all "virtual" addresses...
* which are physical addresses plus MEMBASE.
*/
#define ADDR32(seg, ofs) (((seg) << 4 ) + (ofs))
#define MEMBASE 0x0
#define BOOTSTRUCT_ADDR 0x00011000 // it's slightly smaller
#define BOOTSTRUCT_LEN 0x0000F000
#define BASE_ADDR ADDR32(BASE_SEG, 0)
#define BOOT1U_ADDR ADDR32(BOOT1U_SEG, BOOT1U_OFS)
#define BOOT2_ADDR ADDR32(BOOT2_SEG, BOOT2_OFS)
// TODO: BOOT_ADDR ?
#define HIB_ADDR 0x00040000 // special hibernation area
#define HIB_LEN 0x00060000
#define VIDEO_ADDR 0x000A0000 // unusable space
#define VIDEO_LEN 0x00060000
#define KERNEL_ADDR 0x00100000 // 128M kernel + drivers
#define KERNEL_LEN 0x08000000
#define ZALLOC_ADDR 0x08100000 // 256M zalloc area
#define ZALLOC_LEN 0x10000000
#define LOAD_ADDR 0x18100000 // 64M File load buffer
#define LOAD_LEN 0x04000000
// Location of data fed to boot2 by the prebooter
#define PREBOOT_DATA 0x1C100000 // Still have enough room for a 63M ramdisk image
// in case of 512MB system memory.
#define TFTP_ADDR LOAD_ADDR // tftp download buffer
#define TFTP_LEN LOAD_LEN
#define kLoadAddr LOAD_ADDR
#define kLoadSize LOAD_LEN
#define CONVENTIONAL_LEN 0x0A0000 // 640k
#define EXTENDED_ADDR 0x100000 // 1024k
#define ptov(paddr) ((paddr) - MEMBASE)
#define vtop(vaddr) ((vaddr) + MEMBASE)
/*
* Extract segment/offset from a linear address.
*/
#define OFFSET16(addr) ((addr) - BASE_ADDR)
#define OFFSET(addr) ((addr) & 0xFFFF)
#define SEGMENT(addr) (((addr) & 0xF0000) >> 4)
/* Extract segment/offset in normalized form so that the resulting far pointer
will point to something that is very unlikely to straddle a segment.
This is sometimes known as a "huge" pointer.
*/
#define NORMALIZED_OFFSET(addr) ((addr) & 0x000F)
#define NORMALIZED_SEGMENT(addr) (((addr) & 0xFFFF0) >> 4)
/*
* We need a minimum of 32MB of system memory.
*/
#define MIN_SYS_MEM_KB (32 * 1024)
/*
* The number of descriptor entries in the GDT.
*/
#define NGDTENT 7
/*
* The total size of the GDT in bytes.
* Each descriptor entry require 8 bytes.
*/
#define GDTLIMIT ( NGDTENT * 8 )
#endif /* !__BOOT_MEMORY_H */
branches/xZenu/src/arch/i386/libsaio/load.c
3030
3131
3232
33
3433
35
3634
3735
3836
#include <mach-o/loader.h>
#include <mach/machine/thread_status.h>
#include <sl.h>
bool gHaveKernelCache;/* XXX aserebln: uninitialized? and only set to true, never to false */
cpu_type_t archCpuType=CPU_TYPE_I386;
// Public Functions
branches/xZenu/src/arch/i386/libsaio/biosfn.c
3939
4040
4141
42
42
4343
4444
4545
......
246246
247247
248248
249
249
250250
251251
252252
......
488488
489489
490490
491
491
492492
493493
494494
......
721721
722722
723723
724
724
725725
726726
727727
2007-12-29 dfe
- Added ebiosEjectMedia
*/
#include <string.h>
#include "libsaio.h"
#endif
// Copy out data
bcopy((char *)BIOS_ADDR, rangeArray, ((char *)range - (char *)BIOS_ADDR));
memcpy((char *)BIOS_ADDR, rangeArray, ((char *)range - (char *)BIOS_ADDR));
#if DEBUG
{
} __attribute__((packed));
static struct packet pkt;
bzero(&pkt, sizeof(pkt));
memset(&pkt, 0, sizeof(pkt));
pkt.packet_size = 0x13;
bb.intno= 0x13;
#endif /* APM_SUPPORT */
#ifdef EISA_SUPPORT
bool eisa_present(void)
char eisa_present(void)
{
static bool checked = false;
static bool isEISA;
branches/xZenu/src/arch/i386/libsaio/saio_types.h
6262
6363
6464
65
66
67
68
69
7065
7166
7267
......
112107
113108
114109
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
142110
143111
144112
};
typedef struct Tag Tag, *TagPtr;
typedef struct {
charplist[4096];// buffer for plist
TagPtrdictionary;// buffer for xml dictionary
boolcanOverride;// flag to mark a dictionary can be overriden
} config_file_t;
typedef struct FinderInfo {
unsigned char data[16];
#define BVSTRLEN 32
struct BootVolume {
BVRef next; /* list linkage pointer */
int biosdev; /* BIOS device number */
int type; /* device type (floppy, hd, network) */
unsigned int flags; /* attribute flags */
BVGetDescription description; /* BVGetDescription function */
int part_no; /* partition number (1 based) */
unsigned int part_boff; /* partition block offset */
unsigned int part_type; /* partition type */
unsigned int fs_boff; /* 1st block # of next read */
unsigned int fs_byteoff; /* Byte offset for read within block */
FSLoadFile fs_loadfile; /* FSLoadFile function */
FSReadFile fs_readfile; /* FSReadFile function */
FSGetDirEntry fs_getdirentry; /* FSGetDirEntry function */
FSGetFileBlock fs_getfileblock; /* FSGetFileBlock function */
FSGetUUID fs_getuuid; /* FSGetUUID function */
unsigned int bps; /* bytes per sector for this device */
char name[BVSTRLEN]; /* (name of partition) */
char type_name[BVSTRLEN]; /* (type of partition, eg. Apple_HFS) */
BVFree bv_free; /* BVFree function */
uint32_t modTime;
char label[BVSTRLEN]; /* partition volume label */
char altlabel[BVSTRLEN]; /* partition volume label */
bool filtered; /* newFilteredBVChain() will set to TRUE */
bool visible; /* will shown in the device list */
};
enum {
kBVFlagPrimary= 0x01,
kBVFlagNativeBoot= 0x02,
branches/xZenu/src/arch/i386/libsaio/libsaio.h
2626
2727
2828
29
29
3030
3131
3232
#ifndef __LIBSAIO_LIBSAIO_H
#define __LIBSAIO_LIBSAIO_H
#include "libsa.h"
#include <stdint.h>
#include "memory.h"
#include "io_inline.h"
#include "saio_types.h"
branches/xZenu/src/arch/i386/libsaio/misc.c
4343
4444
4545
46
46
4747
4848
4949
* Copyright 1993 NeXT, Inc.
* All rights reserved.
*/
#include <string.h>
#include "libsaio.h"
/*
branches/xZenu/src/arch/i386/libsaio/saio_internal.h
3939
4040
4141
42
42
4343
4444
4545
......
7171
7272
7373
74
75
76
77
78
79
8074
81
82
8375
8476
8577
......
9284
9385
9486
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
12287
123
12488
12589
12690
......
12892
12993
13094
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
15995
16096
16197
......
191127
192128
193129
194
195130
196131
197132
/* biosfn.c */
#ifdef EISA_SUPPORT
extern bool eisa_present(void);
extern char eisa_present(void);
#endif
extern int bgetc(void);
extern int biosread(int dev, int cyl, int head, int sec, int num);
extern unsigned long getConventionalMemorySize();
extern void sleep(int n);
/* cache.c */
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 msglog(const char * format, ...);
extern void setupBooterLog(void);
//Azi: replace getc/getchar with ? console.c
extern void pause();
/* disk.c */
extern void rescanBIOSDevice(int biosdev);
extern struct DiskBVMap* diskResetBootVolumes(int biosdev);
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);
extern int diskRead(BVRef bvr, long addr, long length);
extern int diskIsCDROM(BVRef bvr);
extern int biosDevIsCDROM(int biosdev);
extern BVRef getBVChainForBIOSDev(int biosdev);
extern BVRef newFilteredBVChain(int minBIOSDev, int maxBIOSDev, unsigned int allowFlags, unsigned int denyFlags, int *count);
extern int freeFilteredBVChain(const BVRef chain);
extern int rawDiskRead(BVRef bvr, unsigned int secno, void *buffer, unsigned int len);
extern int rawDiskWrite(BVRef bvr, unsigned int secno, void *buffer, unsigned int len);
extern int readBootSector(int biosdev, unsigned int secno, void *buffer);
extern void turnOffFloppy(void);
extern int testFAT32EFIBootSector( int biosdev, unsigned int secno, void * buffer );
/* hfs_compare.c */
extern int32_t FastUnicodeCompare(u_int16_t *uniStr1, u_int32_t len1,
u_int16_t *uniStr2, u_int32_t len2, int byte_order);
extern void utf_encodestr( const u_int16_t * ucsp, int ucslen,
u_int8_t * utf8p, u_int32_t bufsize, int byte_order );
extern void utf_decodestr(const u_int8_t *utf8p, u_int16_t *ucsp,
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);
long AllocateKernelMemory( long inSize );
long AllocateMemoryRange(char * rangeName, long start, long length, long type);
/* misc.c */
extern void enableA20(void);
extern int checkForSupportedHardware();
extern int isLaptop();
extern void getPlatformName(char *nameBuf);
/* stringTable.c */
extern char * newStringFromList(char **list, int *size);
extern int stringLength(const char *table, int compress);
extern bool getValueForConfigTableKey(config_file_t *config, const char *key, const char **val, int *size);
extern bool removeKeyFromTable(const char *key, char *table);
extern char * newStringForStringTableKey(config_file_t *config, char *key);
extern char * newStringForKey(char *key, config_file_t *configBuff);
extern bool getValueForBootKey(const char *line, const char *match, const char **matchval, int *len);
extern bool getValueForKey(const char *key, const char **val, int *size, config_file_t *configBuff);
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 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 );
extern int loadConfigFile(const char *configFile, config_file_t *configBuff);
extern int loadSystemConfig(config_file_t *configBuff);
extern int loadHelperConfig(config_file_t *configBuff);
extern int loadOverrideConfig(config_file_t *configBuff);
extern char * newString(const char *oldString);
extern char * getNextArg(char ** ptr, char * val);
extern int ParseXMLFile( char * buffer, TagPtr * dict );
/* sys.c */
extern BVRef getBootVolumeRef( const char * path, const char ** outPath );
extern long LoadVolumeFile(BVRef bvr, const char *fileSpec);
extern void scanBootVolumes(int biosdev, int *count);
extern void scanDisks(int biosdev, int *count);
extern BVRef selectBootVolume(BVRef chain);
extern void getBootVolumeDescription(BVRef bvr, char *str, long strMaxLen, bool verbose);
extern void setRootVolume(BVRef volume);
extern void setBootGlobals(BVRef chain);
extern int getDeviceDescription(BVRef volume, char *str);

Archive Download the corresponding diff file

Revision: 1302