Chameleon

Chameleon Commit Details

Date:2014-01-20 14:03:17 (5 years 7 months ago)
Author:ErmaC
Commit:2344
Parents: 2343
Message:Fix error introduced with rev 2327. Update changelog. Typos...
Changes:
M/trunk/i386/libsaio/hda.h
M/trunk/i386/cdboot/cdboothdd.s
M/trunk/i386/config/confdata.c
M/trunk/i386/boot2/resume.c
M/trunk/i386/libsa/libsa.h
M/trunk/i386/libsaio/freebsd.c
M/trunk/i386/libsaio/nvidia.c
M/trunk/i386/boot2/boot.h
M/trunk/i386/libsaio/pci.c
M/trunk/i386/include/string.h
M/trunk/CHANGES
M/trunk/i386/libsaio/vbe.c
M/trunk/i386/libsa/string.c
M/trunk/i386/libsaio/device_tree.c
M/trunk/i386/libsaio/stringTable.c
M/trunk/i386/libsaio/nvidia.h
M/trunk/i386/libsaio/convert.c
M/trunk/i386/cdboot/cdboot.s
M/trunk/i386/boot2/mboot.c
M/trunk/i386/libsaio/saio_types.h
M/trunk/i386/include/mach/mach.h
M/trunk/i386/libsaio/cpu.c
M/trunk/i386/boot2/gui.c
M/trunk/i386/libsaio/platform.h
M/trunk/i386/config/lex.zconf.c
M/trunk/i386/libsaio/device_inject.c
M/trunk/i386/config/nconf.h
M/trunk/i386/boot2/gui.h
M/trunk/i386/boot2/options.c
M/trunk/i386/libsa/strtol.c
M/trunk/i386/libsaio/device_inject.h

File differences

trunk/i386/libsaio/vbe.c
2929
3030
3131
32
33
34
32
33
34
35
36
37
3538
3639
3740
3841
3942
4043
44
4145
4246
4347
......
4549
4650
4751
52
53
4854
4955
5056
......
5258
5359
5460
61
62
5563
56
64
5765
5866
5967
6068
6169
62
63
64
65
70
6671
6772
6873
......
7479
7580
7681
82
83
7784
7885
7986
......
8592
8693
8794
95
96
8897
8998
9099
......
95104
96105
97106
107
108
98109
99110
100111
#include "libsaio.h"
#include "vbe.h"
/*
* Various inline routines for video I/O
*/
// Various inline routines for video I/O
static biosBuf_t bb;
//==============================================================================
static inline void
outi (int port, int index, int val)
{
outw (port, (val << 8) | index);
}
//==============================================================================
static inline void
outib (int port, int index, int val)
{
outb (port + 1, val);
}
//==============================================================================
static inline int
ini (int port, int index)
{
return inb (port + 1);
}
//==============================================================================
static inline void
rmwi (int port, int index, int clear, int set)
rmwi(int port, int index, int clear, int set)
{
outb (port, index);
outb (port + 1, (inb (port + 1) & ~clear) | set);
}
/*
* Globals
*/
static biosBuf_t bb;
//==============================================================================
int getVBEInfo( void * infoBlock )
{
return(bb.eax.r.h);
}
//==============================================================================
int getVBEModeInfo( int mode, void * minfo_p )
{
bb.intno = 0x10;
return(bb.eax.r.h);
}
//==============================================================================
int getVBEDACFormat(unsigned char *format)
{
bb.intno = 0x10;
return(bb.eax.r.h);
}
//==============================================================================
int setVBEDACFormat(unsigned char format)
{
bb.intno = 0x10;
trunk/i386/libsaio/device_tree.c
297297
298298
299299
300
300
301301
302302
303303
for (count = 0, prop = node->properties; prop != 0; count++, prop = prop->next)
{
flatProp = (DeviceTreeNodeProperty *)buffer;
strcpy(flatProp->name, prop->name);
strncpy(flatProp->name, prop->name, kPropNameLength);
flatProp->length = prop->length;
buffer += sizeof(DeviceTreeNodeProperty);
bcopy(prop->value, buffer, prop->length);
trunk/i386/libsaio/device_inject.c
160160
161161
162162
163
164
163
165164
166165
167166
......
197196
198197
199198
200
201
202
203
204199
205
206
207
208
209
210
211
212
213
214
200
201
202
215203
216
217
218
219
220
221
222
223
224
204
205
206
207
208
209
210
211
212
225213
214
215
216
217
218
219
220
221
222
226223
227224
228225
......
316313
317314
318315
319
320
321
322
323
324
316
317
318
325319
326320
327321
......
347341
348342
349343
350
351
344
352345
353346
354347
......
356349
357350
358351
359
360
361
362
352
353
363354
364355
365356
inti;
for(i = 0; i < numpaths; i++)
{
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;
}
uint32_t length = ((strlen(nm) * 2) + len + (2 * sizeof(uint32_t)) + 2);
uint8_t *data = (uint8_t*)malloc(length);
{
if(!data) {
return 0;
}
memset(data, 0, length);
uint32_t off= 0;
data[off+1] = ((strlen(nm) * 2) + 6) >> 8;
data[off] = ((strlen(nm) * 2) + 6) & 0x00FF;
off += 4;
uint32_t i=0, l = strlen(nm);
for(i = 0 ; i < l ; i++, off += 2) {
data[off] = *nm++;
}
if(!data) {
return 0;
}
off += 2;
l = len;
uint32_t *datalength = (uint32_t*)&data[off];
*datalength = (uint32_t)(l + 4);
off += 4;
for(i = 0 ; i < l ; i++, off++)
{
data[off] = *vl++;
}
memset(data, 0, length);
uint32_t off= 0;
data[off+1] = ((strlen(nm) * 2) + 6) >> 8;
data[off] = ((strlen(nm) * 2) + 6) & 0x00FF;
off += 4;
uint32_t i=0, l = strlen(nm);
for(i = 0 ; i < l ; i++, off += 2) {
data[off] = *nm++;
}
off += 2;
l = len;
uint32_t *datalength = (uint32_t*)&data[off];
*datalength = (uint32_t)(l + 4);
off += 4;
for(i = 0 ; i < l ; i++, off++) {
data[off] = *vl++;
}
uint32_t offset = device->length - (24 + (6 * device->num_pci_devpaths));
}
int i;
for(i = 0; i < string->numentries; i++)
{
if(string->entries[i])
{
if(string->entries[i]->data)
{
for(i = 0; i < string->numentries; i++) {
if(string->entries[i]) {
if(string->entries[i]->data) {
free(string->entries[i]->data);
string->entries[i]->data = NULL;
}
inti;
charbuf[3];
if (hex == NULL || bin == NULL || len <= 0 || strlen(hex) != len * 2)
{
if (hex == NULL || bin == NULL || len <= 0 || strlen(hex) != len * 2) {
printf("[ERROR] bin2hex input error\n");
return -1;
}
buf[2] = '\0';
p = (char *) hex;
for (i = 0; i < len; i++)
{
if (p[0] == '\0' || p[1] == '\0' || !isxdigit(p[0]) || !isxdigit(p[1]))
{
for (i = 0; i < len; i++) {
if (p[0] == '\0' || p[1] == '\0' || !isxdigit(p[0]) || !isxdigit(p[1])) {
printf("[ERROR] bin2hex '%s' syntax error\n", hex);
return -2;
}
trunk/i386/libsaio/device_inject.h
2222
2323
2424
25
26
2527
2628
2729
uint16_tlength;// = 0x0c
uint32_t_HID;// = 0xD041030A ?
uint32_t_UID;// = 0x00000000 PCI ROOT
uint32_t_CID;// = Optional variable length
};
struct PCIDevPath {
trunk/i386/libsaio/hda.h
675675
676676
677677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
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
749
750
751
752
753
754
755
756
757
758
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
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
678914
#define HDA_CODEC_INTELCL HDA_CODEC_CONSTRUCT(INTEL, 0x29fb)
#define HDA_CODEC_INTELXXXX HDA_CODEC_CONSTRUCT(INTEL, 0xffff)
/****************************************************************************
* HDA Controller Register Set
****************************************************************************/
#define HDAC_GCAP0x00/* 2 - Global Capabilities*/
#define HDAC_VMIN0x02/* 1 - Minor Version */
#define HDAC_VMAJ0x03/* 1 - Major Version */
#defineHDAC_OUTPAY0x04/* 2 - Output Payload Capability */
#define HDAC_INPAY0x06/* 2 - Input Payload Capability */
#define HDAC_GCTL0x08/* 4 - Global Control */
#define HDAC_WAKEEN0x0c/* 2 - Wake Enable */
#define HDAC_STATESTS0x0e/* 2 - State Change Status */
#define HDAC_GSTS0x10/* 2 - Global Status */
#define HDAC_OUTSTRMPAY0x18/* 2 - Output Stream Payload Capability */
#define HDAC_INSTRMPAY0x1a/* 2 - Input Stream Payload Capability */
#define HDAC_INTCTL0x20/* 4 - Interrupt Control */
#define HDAC_INTSTS0x24/* 4 - Interrupt Status */
#define HDAC_WALCLK0x30/* 4 - Wall Clock Counter */
#define HDAC_SSYNC0x38/* 4 - Stream Synchronization */
#define HDAC_CORBLBASE0x40/* 4 - CORB Lower Base Address */
#define HDAC_CORBUBASE0x44/* 4 - CORB Upper Base Address */
#define HDAC_CORBWP0x48/* 2 - CORB Write Pointer */
#define HDAC_CORBRP0x4a/* 2 - CORB Read Pointer */
#define HDAC_CORBCTL0x4c/* 1 - CORB Control */
#define HDAC_CORBSTS0x4d/* 1 - CORB Status */
#define HDAC_CORBSIZE0x4e/* 1 - CORB Size */
#define HDAC_RIRBLBASE0x50/* 4 - RIRB Lower Base Address */
#define HDAC_RIRBUBASE0x54/* 4 - RIRB Upper Base Address */
#define HDAC_RIRBWP0x58/* 2 - RIRB Write Pointer */
#define HDAC_RINTCNT0x5a/* 2 - Response Interrupt Count */
#define HDAC_RIRBCTL0x5c/* 1 - RIRB Control */
#define HDAC_RIRBSTS0x5d/* 1 - RIRB Status */
#define HDAC_RIRBSIZE0x5e/* 1 - RIRB Size */
#define HDAC_ICOI0x60/* 4 - Immediate Command Output Interface */
#define HDAC_ICII0x64/* 4 - Immediate Command Input Interface */
#define HDAC_ICIS0x68/* 2 - Immediate Command Status */
#define HDAC_DPIBLBASE0x70/* 4 - DMA Position Buffer Lower Base */
#define HDAC_DPIBUBASE0x74/* 4 - DMA Position Buffer Upper Base */
#define HDAC_SDCTL00x80/* 3 - Stream Descriptor Control */
#define HDAC_SDCTL10x81/* 3 - Stream Descriptor Control */
#define HDAC_SDCTL20x82/* 3 - Stream Descriptor Control */
#define HDAC_SDSTS0x83/* 1 - Stream Descriptor Status */
#define HDAC_SDLPIB0x84/* 4 - Link Position in Buffer */
#define HDAC_SDCBL0x88/* 4 - Cyclic Buffer Length */
#define HDAC_SDLVI0x8C/* 2 - Last Valid Index */
#define HDAC_SDFIFOS0x90/* 2 - FIFOS */
#define HDAC_SDFMT0x92/* 2 - fmt */
#define HDAC_SDBDPL0x98/* 4 - Buffer Descriptor Pointer Lower Base */
#define HDAC_SDBDPU0x9C/* 4 - Buffer Descriptor Pointer Upper Base */
#define _HDAC_ISDOFFSET(n, iss, oss)(0x80 + ((n) * 0x20))
#define _HDAC_ISDCTL(n, iss, oss)(0x00 + _HDAC_ISDOFFSET(n, iss, oss))
#define _HDAC_ISDSTS(n, iss, oss)(0x03 + _HDAC_ISDOFFSET(n, iss, oss))
#define _HDAC_ISDPICB(n, iss, oss)(0x04 + _HDAC_ISDOFFSET(n, iss, oss))
#define _HDAC_ISDCBL(n, iss, oss)(0x08 + _HDAC_ISDOFFSET(n, iss, oss))
#define _HDAC_ISDLVI(n, iss, oss)(0x0c + _HDAC_ISDOFFSET(n, iss, oss))
#define _HDAC_ISDFIFOD(n, iss, oss)(0x10 + _HDAC_ISDOFFSET(n, iss, oss))
#define _HDAC_ISDFMT(n, iss, oss)(0x12 + _HDAC_ISDOFFSET(n, iss, oss))
#define _HDAC_ISDBDPL(n, iss, oss)(0x18 + _HDAC_ISDOFFSET(n, iss, oss))
#define _HDAC_ISDBDPU(n, iss, oss)(0x1c + _HDAC_ISDOFFSET(n, iss, oss))
#define _HDAC_OSDOFFSET(n, iss, oss)(0x80 + ((iss) * 0x20) + ((n) * 0x20))
#define _HDAC_OSDCTL(n, iss, oss)(0x00 + _HDAC_OSDOFFSET(n, iss, oss))
#define _HDAC_OSDSTS(n, iss, oss)(0x03 + _HDAC_OSDOFFSET(n, iss, oss))
#define _HDAC_OSDPICB(n, iss, oss)(0x04 + _HDAC_OSDOFFSET(n, iss, oss))
#define _HDAC_OSDCBL(n, iss, oss)(0x08 + _HDAC_OSDOFFSET(n, iss, oss))
#define _HDAC_OSDLVI(n, iss, oss)(0x0c + _HDAC_OSDOFFSET(n, iss, oss))
#define _HDAC_OSDFIFOD(n, iss, oss)(0x10 + _HDAC_OSDOFFSET(n, iss, oss))
#define _HDAC_OSDFMT(n, iss, oss)(0x12 + _HDAC_OSDOFFSET(n, iss, oss))
#define _HDAC_OSDBDPL(n, iss, oss)(0x18 + _HDAC_OSDOFFSET(n, iss, oss))
#define _HDAC_OSDBDPU(n, iss, oss)(0x1c + _HDAC_OSDOFFSET(n, iss, oss))
#define _HDAC_BSDOFFSET(n, iss, oss)(0x80 + ((iss) * 0x20) + ((oss) * 0x20) + ((n) * 0x20))
#define _HDAC_BSDCTL(n, iss, oss)(0x00 + _HDAC_BSDOFFSET(n, iss, oss))
#define _HDAC_BSDSTS(n, iss, oss)(0x03 + _HDAC_BSDOFFSET(n, iss, oss))
#define _HDAC_BSDPICB(n, iss, oss)(0x04 + _HDAC_BSDOFFSET(n, iss, oss))
#define _HDAC_BSDCBL(n, iss, oss)(0x08 + _HDAC_BSDOFFSET(n, iss, oss))
#define _HDAC_BSDLVI(n, iss, oss)(0x0c + _HDAC_BSDOFFSET(n, iss, oss))
#define _HDAC_BSDFIFOD(n, iss, oss)(0x10 + _HDAC_BSDOFFSET(n, iss, oss))
#define _HDAC_BSDFMT(n, iss, oss)(0x12 + _HDAC_BSDOFFSET(n, iss, oss))
#define _HDAC_BSDBDPL(n, iss, oss)(0x18 + _HDAC_BSDOFFSET(n, iss, oss))
#define _HDAC_BSDBDBU(n, iss, oss)(0x1c + _HDAC_BSDOFFSET(n, iss, oss))
/****************************************************************************
* HDA Controller Register Fields
****************************************************************************/
/* GCAP - Global Capabilities */
#define HDAC_GCAP_64OK0x0001
#define HDAC_GCAP_NSDO_MASK0x0006
#define HDAC_GCAP_NSDO_SHIFT1
#define HDAC_GCAP_BSS_MASK0x00f8
#define HDAC_GCAP_BSS_SHIFT3
#define HDAC_GCAP_ISS_MASK0x0f00
#define HDAC_GCAP_ISS_SHIFT8
#define HDAC_GCAP_OSS_MASK0xf000
#define HDAC_GCAP_OSS_SHIFT12
#define HDAC_GCAP_NSDO_1SDO0x00
#define HDAC_GCAP_NSDO_2SDO0x02
#define HDAC_GCAP_NSDO_4SDO0x04
#define HDAC_GCAP_BSS(gcap)\
(((gcap) & HDAC_GCAP_BSS_MASK) >> HDAC_GCAP_BSS_SHIFT)
#define HDAC_GCAP_ISS(gcap)\
(((gcap) & HDAC_GCAP_ISS_MASK) >> HDAC_GCAP_ISS_SHIFT)
#define HDAC_GCAP_OSS(gcap)\
(((gcap) & HDAC_GCAP_OSS_MASK) >> HDAC_GCAP_OSS_SHIFT)
#define HDAC_GCAP_NSDO(gcap)\
(((gcap) & HDAC_GCAP_NSDO_MASK) >> HDAC_GCAP_NSDO_SHIFT)
/* GCTL - Global Control */
#define HDAC_GCTL_CRST0x00000001
#define HDAC_GCTL_FCNTRL0x00000002
#define HDAC_GCTL_UNSOL0x00000100
/* WAKEEN - Wake Enable */
#define HDAC_WAKEEN_SDIWEN_MASK0x7fff
#define HDAC_WAKEEN_SDIWEN_SHIFT0
/* STATESTS - State Change Status */
#define HDAC_STATESTS_SDIWAKE_MASK0x7fff
#define HDAC_STATESTS_SDIWAKE_SHIFT0
#define HDAC_STATESTS_SDIWAKE(statests, n)\
(((((statests) & HDAC_STATESTS_SDIWAKE_MASK) >>\
HDAC_STATESTS_SDIWAKE_SHIFT) >> (n)) & 0x0001)
/* GSTS - Global Status */
#define HDAC_GSTS_FSTS0x0002
/* INTCTL - Interrut Control */
#define HDAC_INTCTL_SIE_MASK0x3fffffff
#define HDAC_INTCTL_SIE_SHIFT0
#define HDAC_INTCTL_CIE0x40000000
#define HDAC_INTCTL_GIE0x80000000
/* INTSTS - Interrupt Status */
#define HDAC_INTSTS_SIS_MASK0x3fffffff
#define HDAC_INTSTS_SIS_SHIFT0
#define HDAC_INTSTS_CIS0x40000000
#define HDAC_INTSTS_GIS0x80000000
/* SSYNC - Stream Synchronization */
#define HDAC_SSYNC_SSYNC_MASK0x3fffffff
#define HDAC_SSYNC_SSYNC_SHIFT0
/* CORBWP - CORB Write Pointer */
#define HDAC_CORBWP_CORBWP_MASK0x00ff
#define HDAC_CORBWP_CORBWP_SHIFT0
/* CORBRP - CORB Read Pointer */
#define HDAC_CORBRP_CORBRP_MASK0x00ff
#define HDAC_CORBRP_CORBRP_SHIFT0
#define HDAC_CORBRP_CORBRPRST0x8000
/* CORBCTL - CORB Control */
#define HDAC_CORBCTL_CMEIE0x01
#define HDAC_CORBCTL_CORBRUN0x02
/* CORBSTS - CORB Status */
#define HDAC_CORBSTS_CMEI0x01
/* CORBSIZE - CORB Size */
#define HDAC_CORBSIZE_CORBSIZE_MASK0x03
#define HDAC_CORBSIZE_CORBSIZE_SHIFT0
#define HDAC_CORBSIZE_CORBSZCAP_MASK0xf0
#define HDAC_CORBSIZE_CORBSZCAP_SHIFT4
#define HDAC_CORBSIZE_CORBSIZE_20x00
#define HDAC_CORBSIZE_CORBSIZE_160x01
#define HDAC_CORBSIZE_CORBSIZE_2560x02
#define HDAC_CORBSIZE_CORBSZCAP_20x10
#define HDAC_CORBSIZE_CORBSZCAP_160x20
#define HDAC_CORBSIZE_CORBSZCAP_2560x40
#define HDAC_CORBSIZE_CORBSIZE(corbsize)\
(((corbsize) & HDAC_CORBSIZE_CORBSIZE_MASK) >> HDAC_CORBSIZE_CORBSIZE_SHIFT)
/* RIRBWP - RIRB Write Pointer */
#define HDAC_RIRBWP_RIRBWP_MASK0x00ff
#define HDAC_RIRBWP_RIRBWP_SHIFT0
#define HDAC_RIRBWP_RIRBWPRST0x8000
/* RINTCTN - Response Interrupt Count */
#define HDAC_RINTCNT_MASK0x00ff
#define HDAC_RINTCNT_SHIFT0
/* RIRBCTL - RIRB Control */
#define HDAC_RIRBCTL_RINTCTL0x01
#define HDAC_RIRBCTL_RIRBDMAEN0x02
#define HDAC_RIRBCTL_RIRBOIC0x04
/* RIRBSTS - RIRB Status */
#define HDAC_RIRBSTS_RINTFL0x01
#define HDAC_RIRBSTS_RIRBOIS0x04
/* RIRBSIZE - RIRB Size */
#define HDAC_RIRBSIZE_RIRBSIZE_MASK0x03
#define HDAC_RIRBSIZE_RIRBSIZE_SHIFT0
#define HDAC_RIRBSIZE_RIRBSZCAP_MASK0xf0
#define HDAC_RIRBSIZE_RIRBSZCAP_SHIFT4
#define HDAC_RIRBSIZE_RIRBSIZE_20x00
#define HDAC_RIRBSIZE_RIRBSIZE_160x01
#define HDAC_RIRBSIZE_RIRBSIZE_2560x02
#define HDAC_RIRBSIZE_RIRBSZCAP_20x10
#define HDAC_RIRBSIZE_RIRBSZCAP_160x20
#define HDAC_RIRBSIZE_RIRBSZCAP_2560x40
#define HDAC_RIRBSIZE_RIRBSIZE(rirbsize)\
(((rirbsize) & HDAC_RIRBSIZE_RIRBSIZE_MASK) >> HDAC_RIRBSIZE_RIRBSIZE_SHIFT)
/* DPLBASE - DMA Position Lower Base Address */
#define HDAC_DPLBASE_DPLBASE_MASK0xffffff80
#define HDAC_DPLBASE_DPLBASE_SHIFT7
#define HDAC_DPLBASE_DPLBASE_DMAPBE0x00000001
/* SDCTL - Stream Descriptor Control */
#define HDAC_SDCTL_SRST0x000001
#define HDAC_SDCTL_RUN0x000002
#define HDAC_SDCTL_IOCE0x000004
#define HDAC_SDCTL_FEIE0x000008
#define HDAC_SDCTL_DEIE0x000010
#define HDAC_SDCTL2_STRIPE_MASK0x03
#define HDAC_SDCTL2_STRIPE_SHIFT0
#define HDAC_SDCTL2_TP0x04
#define HDAC_SDCTL2_DIR0x08
#define HDAC_SDCTL2_STRM_MASK0xf0
#define HDAC_SDCTL2_STRM_SHIFT4
#define HDAC_SDSTS_DESE(1 << 4)
#define HDAC_SDSTS_FIFOE(1 << 3)
#define HDAC_SDSTS_BCIS(1 << 2)
#endif /* !__LIBSAIO_HDA_H */
trunk/i386/libsaio/nvidia.c
7777
7878
7979
80
8081
8182
8283
......
16391640
16401641
16411642
1642
16431643
16441644
16451645
......
16521652
16531653
16541654
1655
1656
1655
16571656
1657
16581658
16591659
16601660
......
16651665
16661666
16671667
1668
1668
16691669
1670
1670
16711671
16721672
16731673
#define WRITE_LE_SHORT(data) (((data) << 8 & 0xff00) | ((data) >> 8 & 0x00ff ))
#define WRITE_LE_INT(data) (WRITE_LE_SHORT(data) << 16 | WRITE_LE_SHORT(data >> 16))
char generic_name[128];
extern uint32_t devices_number;
const char *nvidia_compatible_0[] ={ "@0,compatible","NVDA,NVMac" };
static char *get_nvidia_model(uint32_t device_id, uint32_t subsys_id)
{
int i, j;
static char name_model[128];
// First check in the plist, (for e.g this can override any hardcoded devices)
cardList_t * nvcard = FindCardWithIds(device_id, subsys_id);
// Then check the exceptions table
if (subsys_id) {
for (i = 0; i < (sizeof(nvidia_card_exceptions) / sizeof(nvidia_card_exceptions[0])); i++) {
if ((nvidia_card_exceptions[i].device == device_id) && (nvidia_card_exceptions[i].subdev == subsys_id))
{
if ((nvidia_card_exceptions[i].device == device_id) && (nvidia_card_exceptions[i].subdev == subsys_id)) {
return nvidia_card_exceptions[i].name;
break;
}
}
}
if (subsys_id) {
for (j = 0; j < (sizeof(nvidia_card_vendors) / sizeof(nvidia_card_vendors[0])); j++) {
if (nvidia_card_vendors[j].device == (subsys_id & 0xffff0000)) {
snprintf(name_model, sizeof(name_model), "%s %s",
snprintf(generic_name, 128, "%s %s", // sizeof(generic_name), "%s %s",
nvidia_card_vendors[j].name, nvidia_card_generic[i].name);
return name_model;
return &generic_name[0];
}
}
}
trunk/i386/libsaio/nvidia.h
6969
7070
7171
72
72
73
7374
7475
7576
......
8788
8889
8990
90
91
92
93
91
92
93
94
9495
96
9597
9698
9799
......
108110
109111
110112
113
114
111115
112116
113117
#define DCB_MAX_NUM_ENTRIES 16
#define DCB_MAX_NUM_I2C_ENTRIES 16
#define DCB_MAX_NUM_GPIO_ENTRIES 32
#define DCB_MAX_NUM_CONNECTOR_ENTRIES 16
#define DCB_LOC_ON_CHIP 0
struct bios {
#define NV_PRAMIN_OFFSET0x00700000
#define NV_PRAMIN_SIZE0x00100000
#define NV04_PFB_FIFO_DATA0x0010020c
#define NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_MASK0xfff00000
#define NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_SHIFT20
#define NVC0_MEM_CTRLR_COUNT0x00121c74
#define NVC0_MEM_CTRLR_RAM_AMOUNT0x0010f20c
#define NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_MASK0xfff00000
#define NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_SHIFT20
#define NVC0_MEM_CTRLR_RAM_AMOUNT0x0010f20c
#define NVC0_MEM_CTRLR_COUNT0x00121c74
#define NV_PBUS_PCI_NV_190x0000184C
#define NV_PBUS_PCI_NV_200x00001850
#define NV_PBUS_PCI_NV_20_ROM_SHADOW_DISABLED(0 << 0)
#define NV_PBUS_PCI_NV_20_ROM_SHADOW_ENABLED(1 << 0)
#define NV_ARCH_40 0x40
#define NV_ARCH_50 0x50
#define NV_ARCH_C0 0xC0
#define NV_ARCH_D0 0xD0
#define NV_ARCH_E0 0xE0
#define CHIPSET_NV03 0x0010
#define CHIPSET_NV04 0x0020
trunk/i386/libsaio/cpu.c
260260
261261
262262
263
264
263
265264
266265
267
268
266
269267
270268
271
272
269
273270
274271
275
276
277
272
278273
279274
280275
......
282277
283278
284279
285
286
280
287281
288282
289283
......
307301
308302
309303
304
310305
306
311307
308
312309
313
310
311
312
314313
314
315315
316316
317317
......
320320
321321
322322
323
324
323
325324
326325
327326
328
329
330
327
331328
332329
333
334
335
330
336331
337332
338333
......
340335
341336
342337
343
344
338
345339
346340
347341
......
354348
355349
356350
357
358
359
360
351
352
361353
362354
363355
364356
365357
366358
367
368
359
369360
370361
371362
......
375366
376367
377368
378
379
369
380370
381371
382
383
372
384373
385374
386
387
375
388376
389377
390
391
378
392379
393380
394
395
381
396382
397383
398
399
384
400385
401386
402
403
387
404388
405389
406
407
390
408391
409392
410393
411
412
394
413395
414396
415397
......
448430
449431
450432
451
452
433
453434
454435
455436
......
459440
460441
461442
462
463
443
464444
465445
466446
467447
468
469
470
471
472
448
449
473450
474451
475452
476453
477454
478
479
455
480456
481457
482458
483
484
459
485460
486461
487462
488
489
490
463
491464
492465
493
494
466
495467
496468
497
498
469
499470
500471
501472
502473
503474
504475
505
506
476
507477
508
509
478
510479
511
512
513
480
514481
515482
516
517
518
483
519484
520485
521486
......
525490
526491
527492
528
493
529494
530495
531496
532497
533
498
534499
535500
536501
537502
538503
539504
540
541
505
542506
543507
544
545
546
508
547509
548510
549511
550512
551513
552
553
554
555
514
515
556516
557
558
559
517
560518
561519
562
563
520
564521
565
566
567
522
568523
569524
570525
do_cpuid(0x00000003, p->CPU.CPUID[CPUID_3]);
do_cpuid2(0x00000004, 0, p->CPU.CPUID[CPUID_4]);
do_cpuid(0x80000000, p->CPU.CPUID[CPUID_80]);
if (p->CPU.CPUID[CPUID_0][0] >= 0x5)
{
if (p->CPU.CPUID[CPUID_0][0] >= 0x5) {
do_cpuid(5, p->CPU.CPUID[CPUID_5]);
}
if (p->CPU.CPUID[CPUID_0][0] >= 6)
{
if (p->CPU.CPUID[CPUID_0][0] >= 6) {
do_cpuid(6, p->CPU.CPUID[CPUID_6]);
}
if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 8)
{
if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 8) {
do_cpuid(0x80000008, p->CPU.CPUID[CPUID_88]);
do_cpuid(0x80000001, p->CPU.CPUID[CPUID_81]);
}
else if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 1)
{
} else if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 1) {
do_cpuid(0x80000001, p->CPU.CPUID[CPUID_81]);
}
{
inti;
printf("CPUID Raw Values:\n");
for (i=0; i<CPUID_MAX; i++)
{
for (i=0; i<CPUID_MAX; i++) {
printf("%02d: %08x-%08x-%08x-%08x\n", i,
p->CPU.CPUID[i][0], p->CPU.CPUID[i][1],
p->CPU.CPUID[i][2], p->CPU.CPUID[i][3]);
p->CPU.Vendor= p->CPU.CPUID[CPUID_0][1];
p->CPU.Signature= p->CPU.CPUID[CPUID_1][0];
// stepping = cpu_feat_eax & 0xF;
p->CPU.Stepping= bitfield(p->CPU.CPUID[CPUID_1][0], 3, 0);
// model = (cpu_feat_eax >> 4) & 0xF;
p->CPU.Model= bitfield(p->CPU.CPUID[CPUID_1][0], 7, 4);
// family = (cpu_feat_eax >> 8) & 0xF;
p->CPU.Family= bitfield(p->CPU.CPUID[CPUID_1][0], 11, 8);
p->CPU.Type = bitfield(p->CPU.CPUID[CPUID_1][0], 13, 12);
// type = (cpu_feat_eax >> 12) & 0x3;
//p->CPU.Type= bitfield(p->CPU.CPUID[CPUID_1][0], 13, 12);
// ext_model = (cpu_feat_eax >> 16) & 0xF;
p->CPU.ExtModel= bitfield(p->CPU.CPUID[CPUID_1][0], 19, 16);
// ext_family = (cpu_feat_eax >> 20) & 0xFF;
p->CPU.ExtFamily= bitfield(p->CPU.CPUID[CPUID_1][0], 27, 20);
p->CPU.Model += (p->CPU.ExtModel << 4);
p->CPU.Family == 0x06 &&
p->CPU.Model >= CPU_MODEL_NEHALEM &&
p->CPU.Model != CPU_MODEL_ATOM// MSR is *NOT* available on the Intel Atom CPU
)
{
) {
msr = rdmsr64(MSR_CORE_THREAD_COUNT);// Undocumented MSR in Nehalem and newer CPUs
p->CPU.NoCores= bitfield((uint32_t)msr, 31, 16);// Using undocumented MSR to get actual values
p->CPU.NoThreads= bitfield((uint32_t)msr, 15, 0);// Using undocumented MSR to get actual values
}
else if (p->CPU.Vendor == CPUID_VENDOR_AMD)
{
} else if (p->CPU.Vendor == CPUID_VENDOR_AMD) {
p->CPU.NoThreads= bitfield(p->CPU.CPUID[CPUID_1][1], 23, 16);
p->CPU.NoCores= bitfield(p->CPU.CPUID[CPUID_88][2], 7, 0) + 1;
}
else
{
} else {
// Use previous method for Cores and Threads
p->CPU.NoThreads= bitfield(p->CPU.CPUID[CPUID_1][1], 23, 16);
p->CPU.NoCores= bitfield(p->CPU.CPUID[CPUID_4][0], 31, 26) + 1;
/* get brand string (if supported) */
/* Copyright: from Apple's XNU cpuid.c */
if (p->CPU.CPUID[CPUID_80][0] > 0x80000004)
{
if (p->CPU.CPUID[CPUID_80][0] > 0x80000004) {
uint32_treg[4];
charstr[128], *s;
/*
bcopy((char *)reg, &str[16], 16);
do_cpuid(0x80000004, reg);
bcopy((char *)reg, &str[32], 16);
for (s = str; *s != '\0'; s++)
{
if (*s != ' ')
{
for (s = str; *s != '\0'; s++) {
if (*s != ' ') {
break;
}
}
strlcpy(p->CPU.BrandString, s, sizeof(p->CPU.BrandString));
if (!strncmp(p->CPU.BrandString, CPU_STRING_UNKNOWN, MIN(sizeof(p->CPU.BrandString), strlen(CPU_STRING_UNKNOWN) + 1)))
{
if (!strncmp(p->CPU.BrandString, CPU_STRING_UNKNOWN, MIN(sizeof(p->CPU.BrandString), strlen(CPU_STRING_UNKNOWN) + 1))) {
/*
* This string means we have a firmware-programmable brand string,
* and the firmware couldn't figure out what sort of CPU we have.
}
/* setup features */
if ((bit(23) & p->CPU.CPUID[CPUID_1][3]) != 0)
{
if ((bit(23) & p->CPU.CPUID[CPUID_1][3]) != 0) {
p->CPU.Features |= CPU_FEATURE_MMX;
}
if ((bit(25) & p->CPU.CPUID[CPUID_1][3]) != 0)
{
if ((bit(25) & p->CPU.CPUID[CPUID_1][3]) != 0) {
p->CPU.Features |= CPU_FEATURE_SSE;
}
if ((bit(26) & p->CPU.CPUID[CPUID_1][3]) != 0)
{
if ((bit(26) & p->CPU.CPUID[CPUID_1][3]) != 0) {
p->CPU.Features |= CPU_FEATURE_SSE2;
}
if ((bit(0) & p->CPU.CPUID[CPUID_1][2]) != 0)
{
if ((bit(0) & p->CPU.CPUID[CPUID_1][2]) != 0) {
p->CPU.Features |= CPU_FEATURE_SSE3;
}
if ((bit(19) & p->CPU.CPUID[CPUID_1][2]) != 0)
{
if ((bit(19) & p->CPU.CPUID[CPUID_1][2]) != 0) {
p->CPU.Features |= CPU_FEATURE_SSE41;
}
if ((bit(20) & p->CPU.CPUID[CPUID_1][2]) != 0)
{
if ((bit(20) & p->CPU.CPUID[CPUID_1][2]) != 0) {
p->CPU.Features |= CPU_FEATURE_SSE42;
}
if ((bit(29) & p->CPU.CPUID[CPUID_81][3]) != 0)
{
if ((bit(29) & p->CPU.CPUID[CPUID_81][3]) != 0) {
p->CPU.Features |= CPU_FEATURE_EM64T;
}
if ((bit(5) & p->CPU.CPUID[CPUID_1][3]) != 0)
{
if ((bit(5) & p->CPU.CPUID[CPUID_1][3]) != 0) {
p->CPU.Features |= CPU_FEATURE_MSR;
}
//if ((bit(28) & p->CPU.CPUID[CPUID_1][3]) != 0) {
if (p->CPU.NoThreads > p->CPU.NoCores)
{
if (p->CPU.NoThreads > p->CPU.NoCores) {
p->CPU.Features |= CPU_FEATURE_HTT;
}
bus_ratio_min = bitfield(msr, 47, 40); //valv: not sure about this one (Remarq.1)
msr = rdmsr64(MSR_FLEX_RATIO);
DBG("msr(%d): flex_ratio %08x\n", __LINE__, bitfield(msr, 31, 0));
if (bitfield(msr, 16, 16))
{
if (bitfield(msr, 16, 16)) {
flex_ratio = bitfield(msr, 15, 8);
/* bcc9: at least on the gigabyte h67ma-ud2h,
where the cpu multipler can't be changed to
causing the system to crash since tscGranularity
is inadvertently set to 0.
*/
if (flex_ratio == 0)
{
if (flex_ratio == 0) {
/* Clear bit 16 (evidently the presence bit) */
wrmsr64(MSR_FLEX_RATIO, (msr & 0xFFFFFFFFFFFEFFFFULL));
msr = rdmsr64(MSR_FLEX_RATIO);
verbose("Unusable flex ratio detected. Patched MSR now %08x\n", bitfield(msr, 31, 0));
}
else
{
if (bus_ratio_max > flex_ratio)
{
} else {
if (bus_ratio_max > flex_ratio) {
bus_ratio_max = flex_ratio;
}
}
}
if (bus_ratio_max)
{
if (bus_ratio_max) {
fsbFrequency = (tscFrequency / bus_ratio_max);
}
//valv: Turbo Ratio Limit
if ((intelCPU != 0x2e) && (intelCPU != 0x2f))
{
if ((intelCPU != 0x2e) && (intelCPU != 0x2f)) {
msr = rdmsr64(MSR_TURBO_RATIO_LIMIT);
cpuFrequency = bus_ratio_max * fsbFrequency;
max_ratio = bus_ratio_max * 10;
}
else
{
} else {
cpuFrequency = tscFrequency;
}
if ((getValueForKey(kbusratio, &newratio, &len, &bootInfo->chameleonConfig)) && (len <= 4))
{
if ((getValueForKey(kbusratio, &newratio, &len, &bootInfo->chameleonConfig)) && (len <= 4)) {
max_ratio = atoi(newratio);
max_ratio = (max_ratio * 10);
if (len >= 3)
{
if (len >= 3) {
max_ratio = (max_ratio + 5);
}
verbose("Bus-Ratio: min=%d, max=%s\n", bus_ratio_min, newratio);
// extreme overclockers may love 320 ;)
if ((max_ratio >= min_ratio) && (max_ratio <= 320))
{
if ((max_ratio >= min_ratio) && (max_ratio <= 320)) {
cpuFrequency = (fsbFrequency * max_ratio) / 10;
if (len >= 3)
{
if (len >= 3) {
maxdiv = 1;
}
else
{
} else {
maxdiv = 0;
}
}
else
{
} else {
max_ratio = (bus_ratio_max * 10);
}
}
p->CPU.MinRatio = min_ratio;
myfsb = fsbFrequency / 1000000;
verbose("Sticking with [BCLK: %dMhz, Bus-Ratio: %d]\n", myfsb, max_ratio/10);
verbose("Sticking with [BCLK: %dMhz, Bus-Ratio: %d]\n", myfsb, max_ratio/10); // Bungo: fixed wrong Bus-Ratio readout
currcoef = bus_ratio_max;
} else {
msr = rdmsr64(MSR_IA32_PERF_STATUS);
DBG("msr(%d): ia32_perf_stat 0x%08x\n", __LINE__, bitfield(msr, 31, 0));
currcoef = bitfield(msr, 12, 8);
currcoef = bitfield(msr, 12, 8); // Bungo: reverted to 2263 state because of wrong old CPUs freq. calculating
/* Non-integer bus ratio for the max-multi*/
maxdiv = bitfield(msr, 46, 46);
/* Non-integer bus ratio for the current-multi (undocumented)*/
currdiv = bitfield(msr, 14, 14);
// This will always be model >= 3
if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0e) || (p->CPU.Family == 0x0f))
{
if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0e) || (p->CPU.Family == 0x0f)) {
/* On these models, maxcoef defines TSC freq */
maxcoef = bitfield(msr, 44, 40);
}
else
{
} else {
/* On lower models, currcoef defines TSC freq */
/* XXX */
maxcoef = currcoef;
}
if (maxcoef)
{
if (maxdiv)
{
if (maxcoef) {
if (maxdiv) {
fsbFrequency = ((tscFrequency * 2) / ((maxcoef * 2) + 1));
}
else
{
} else {
fsbFrequency = (tscFrequency / maxcoef);
}
if (currdiv)
{
if (currdiv) {
cpuFrequency = (fsbFrequency * ((currcoef * 2) + 1) / 2);
}
else
{
} else {
cpuFrequency = (fsbFrequency * currcoef);
}
DBG("max: %d%s current: %d%s\n", maxcoef, maxdiv ? ".5" : "",currcoef, currdiv ? ".5" : "");
trunk/i386/libsaio/platform.h
137137
138138
139139
140
140
141141
142142
143143
uint32_tVendor;// Vendor
uint32_tSignature;// Processor Signature
uint32_tStepping;// Stepping
uint32_tType;// Type
//uint32_tType;// Type
uint32_tModel;// Model
uint32_tExtModel;// Extended Model
uint32_tFamily;// Family
trunk/i386/libsaio/freebsd.c
33
44
55
6
67
78
89
9
10
1011
1112
1213
#include "freebsd.h"
#define FreeBSDProbeSize2048
#define DISKMAGIC((uint32_t)0x19540119)/* The disk magic number */
bool FreeBSDProbe (const void *buf)
{
return (OSReadLittleInt32(buf+0xA55C,0)==0x19540119);
return (OSReadLittleInt32(buf+0xA55C,0) == DISKMAGIC);
}
void FreeBSDGetDescription(CICell ih, char *str, long strMaxLen)
{
trunk/i386/libsaio/pci.c
7979
8080
8181
82
82
8383
8484
8585
for (func = 0; func < 8; func++) {
pci_addr = PCIADDR(bus, dev, func);
id = pci_config_read32(pci_addr, PCI_VENDOR_ID);
if (!id || id == 0xffffffff) {
if (!id || id == 0xfffffffful) {
continue;
}
new = (pci_dt_t*)malloc(sizeof(pci_dt_t));
trunk/i386/libsaio/stringTable.c
135135
136136
137137
138
139
140
141
142
138
143139
144
145
146
147
140
141
142
143
148144
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
166163
167164
168165
......
174171
175172
176173
177
178
179
180
174
175
181176
182177
183
184
185
186
178
179
180
181
187182
188183
189184
......
200195
201196
202197
203
204
198
205199
206200
207201
......
209203
210204
211205
212
206
213207
214208
215209
......
224218
225219
226220
227
228
229
230
231
221
232222
233
234
235
223
224
225
236226
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
254247
255
256
248
249
250
251
257252
258
259
260
261
262
263253
264254
265255
......
267257
268258
269259
270
271
272
260
261
262
273263
274
275
276
277
278
279
280
264
265
266
267
268
269
270
281271
282272
283273
......
288278
289279
290280
291
292
293
294
295
296
297
298
299
300
301
302
281
282
283
284
285
286
287
288
289
290
291
292
293
294
303295
304296
305297
306298
307
308
309
299
300
301
310302
311
312
313
303
304
305
306
307
314308
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
309
310
311
312
313
314
315
316
317
318
319
320
321
322
330323
331
332
333
334
324
325
326
327
328
335329
336
337
338330
339
331
340332
341333
342334
343335
344336
345
346
347
348
337
338
339
340
341
342
349343
350344
351345
......
358352
359353
360354
361
362
363
364
365
366
367
368
369
355
356
357
358
359
360
361
362
363
370364
371365
372366
373367
374
375
376
368
369
370
377371
378
379
380
381
382
383
372
373
374
384375
385376
386377
387378
388379
389
390
391
380
381
392382
383
393384
394385
395386
396387
397
388
398389
399
390
400391
401392
402393
403394
404
395
405396
406397
407398
......
411402
412403
413404
414
415
405
406
416407
417
408
418409
419410
420
421
422
423
424
425
426
411
412
413
414
427415
428416
429417
430418
431
432
433
419
420
434421
435422
436423
437
424
438425
439
440
441
426
427
442428
443
429
430
444431
445432
446
447
433
434
448435
449
436
437
450438
451
439
452440
453
441
442
454443
455
444
456445
457446
458
447
459448
460
449
461450
462451
463452
464
453
465454
466
455
467456
468457
469458
......
472461
473462
474463
475
476
477
478
464
465
466
467
479468
480
481
482
469
470
483471
484472
485
486
487
473
474
475
488476
489477
490478
491479
492
493
494
495
496
497
480
481
482
498483
499
484
485
486
500487
501
502
503
488
504489
505
506
507
508
509
490
491
492
510493
511
512
513
514
494
495
496
515497
516
517
498
499
500
501
502
518503
519
520
521
522
523
524
525
526
504
505
506
527507
528
508
509
510
511
512
513
514
515
529516
530517
531518
......
533520
534521
535522
536
523
537524
538
539
525
526
527
528
540529
541530
542531
543532
544
533
534
535
545536
546537
547538
......
558549
559550
560551
561
562
563
564
552
553
554
555
565556
566
567
557
558
568559
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
588584
589585
590586
......
602598
603599
604600
605
601
606602
607603
608604
......
623619
624620
625621
626
627
628
629
622
623
630624
631625
632626
633
627
634628
635629
636630
637631
638
632
639633
640634
641635
......
667661
668662
669663
670
671
672
673
674
675
676
677
678
679
680
681
664
665
666
667
668
669
670
671
672
682673
683674
684675
......
708699
709700
710701
711
712
713
714
702
703
715704
716705
717706
......
728717
729718
730719
731
732
733
734
720
721
722
723
724
735725
736726
737727
......
739729
740730
741731
742
743
744
745
732
733
734
735
746736
747
737
748738
749
750
751
752
753
739
740
741
742
754743
755
744
756745
757
758
759
760
761
762
763
746
747
748
749
750
751
764752
765
766
767
768
769
753
754
755
756
757
770758
771
772
773
774
759
760
761
775762
776
763
777764
778
779
780
781
765
766
767
768
769
782770
783
784
771
772
785773
786
787
774
775
788776
789
777
790778
return true;
}
char *
newStringFromList(
char **list,
int *size
)
char *newStringFromList(char **list, int *size)
{
char *begin = *list, *end;
char *newstr;
int newsize = *size;
int bufsize;
char *begin = *list, *end;
char *newstr;
int newsize = *size;
int bufsize;
while (*begin && newsize && isspace(*begin)) {
begin++;
newsize--;
}
end = begin;
while (*end && newsize && !isspace(*end)) {
end++;
newsize--;
}
if (begin == end)
return 0;
bufsize = end - begin + 1;
newstr = malloc(bufsize);
strlcpy(newstr, begin, bufsize);
*list = end;
*size = newsize;
return newstr;
while (*begin && newsize && isspace(*begin)) {
begin++;
newsize--;
}
end = begin;
while (*end && newsize && !isspace(*end)) {
end++;
newsize--;
}
if (begin == end) {
return 0;
}
bufsize = end - begin + 1;
newstr = malloc(bufsize);
strlcpy(newstr, begin, bufsize);
*list = end;
*size = newsize;
return newstr;
}
#endif
{
int ret = 0;
while (*table)
{
if (*table == '\\')
{
while (*table) {
if (*table == '\\') {
table += 2;
ret += 1 + (compress ? 0 : 1);
}
else
{
if (*table == '\"') return ret;
} else {
if (*table == '\"') {
return ret;
}
ret++;
table++;
}
value = XMLGetProperty(config->dictionary, key);
if (value != 0) {
if (value->type != kTagTypeString) {
error("Non-string tag '%s' found in config file\n",
key);
error("Non-string tag '%s' found in config file\n", key);
return false;
}
*val = value->string;
return true;
}
} else {
// Legacy plist-style table
}
* in the string table matching 'key'. Also translates
* \n escapes in the string.
*/
char *newStringForStringTableKey(
char *table,
char *key,
config_file_t *config
)
char *newStringForStringTableKey(char *table, char *key, config_file_t *config)
{
const char *val;
char *newstr, *p;
int size;
const char *val;
char *newstr, *p;
int size;
if (getValueForConfigTableKey(config, key, &val, &size)) {
newstr = (char *)malloc(size+1);
for (p = newstr; size; size--, p++, val++) {
if ((*p = *val) == '\\') {
switch (*++val) {
case 'r':
*p = '\r';
break;
case 'n':
*p = '\n';
break;
case 't':
*p = '\t';
break;
default:
*p = *val;
break;
if (getValueForConfigTableKey(config, key, &val, &size)) {
newstr = (char *)malloc(size+1);
for (p = newstr; size; size--, p++, val++) {
if ((*p = *val) == '\\') {
switch (*++val) {
case 'r':
*p = '\r';
break;
case 'n':
*p = '\n';
break;
case 't':
*p = '\t';
break;
default:
*p = *val;
break;
}
size--;
}
}
size--;
}
*p = '\0';
return newstr;
} else {
return 0;
}
*p = '\0';
return newstr;
} else {
return 0;
}
}
#endif
char *
newStringForKey(char *key, config_file_t *config)
{
const char *val;
char *newstr;
int size;
const char *val;
char *newstr;
int size;
if (getValueForKey(key, &val, &size, config) && size) {
newstr = (char *)malloc(size + 1);
strlcpy(newstr, val, size + 1);
return newstr;
} else {
return 0;
}
if (getValueForKey(key, &val, &size, config) && size) {
newstr = (char *)malloc(size + 1);
strlcpy(newstr, val, size + 1);
return newstr;
} else {
return 0;
}
}
/* parse a command line
static const char *getToken(const char *line, const char **begin, int *len)
{
if (*line == '\"') {
*begin = ++line;
while (*line && *line != '\"')
line++;
*len = line++ - *begin;
} else {
*begin = line;
while (*line && !isspace(*line) && *line != '=')
line++;
*len = line - *begin;
}
return line;
if (*line == '\"') {
*begin = ++line;
while (*line && *line != '\"') {
line++;
}
*len = line++ - *begin;
} else {
*begin = line;
while (*line && !isspace(*line) && *line != '=') {
line++;
}
*len = line - *begin;
}
return line;
}
bool getValueForBootKey(const char *line, const char *match, const char **matchval, int *len)
{
const char *key, *value;
int key_len, value_len;
bool retval = false;
const char *key, *value;
int key_len, value_len;
bool retval = false;
while (*line) {
/* look for keyword or argument */
while (isspace(*line)) line++;
while (*line) {
/* look for keyword or argument */
while (isspace(*line)) {
line++;
}
/* now look for '=' or whitespace */
line = getToken(line, &key, &key_len);
/* line now points to '=' or space */
if (*line && !isspace(*line)) {
line = getToken(++line, &value, &value_len);
} else {
value = line;
value_len = 0;
}
if ((strlen(match) == key_len)
&& strncmp(match, key, key_len) == 0) {
// create a new string
char* newstr = malloc(value_len + 1);
strncpy(newstr, value, value_len);
newstr[value_len] = 0;
/* now look for '=' or whitespace */
line = getToken(line, &key, &key_len);
/* line now points to '=' or space */
if (*line && !isspace(*line)) {
line = getToken(++line, &value, &value_len);
} else {
value = line;
value_len = 0;
}
if ((strlen(match) == key_len) && strncmp(match, key, key_len) == 0) {
// create a new string
char* newstr = malloc(value_len + 1);
strncpy(newstr, value, value_len);
newstr[value_len] = 0;
*matchval = newstr;
*len = value_len;
retval = true;
/* Continue to look for this key; last one wins. */
*matchval = newstr;
*len = value_len;
retval = true;
/* Continue to look for this key; last one wins. */
}
}
}
return retval;
return retval;
}
/* Return NULL if no option has been successfully retrieved, or the string otherwise */
const char * getStringForKey(const char * key, config_file_t *config)
{
static const char* value =0;
int len=0;
if(!getValueForKey(key, &value, &len, config)) value = 0;
return value;
static const char* value =0;
int len=0;
if(!getValueForKey(key, &value, &len, config)) {
value = 0;
}
return value;
}
const char *key_val;
int size;
if (getValueForKey(key, &key_val, &size, config)) {
if ( (size >= 1) && (key_val[0] == 'Y' || key_val[0] == 'y') ) {
*result_val = true;
} else {
*result_val = false;
}
return true;
}
return false;
if (getValueForKey(key, &key_val, &size, config)) {
if ( (size >= 1) && (key_val[0] == 'Y' || key_val[0] == 'y') ) {
*result_val = true;
} else {
*result_val = false;
}
return true;
}
return false;
}
bool getIntForKey( const char *key, int *value, config_file_t *config )
{
const char *val;
int size, sum;
bool negative = false;
const char *val;
int size, sum;
bool negative = false;
if (getValueForKey(key, &val, &size, config))
{
if ( size )
{
if (*val == '-')
{
if (getValueForKey(key, &val, &size, config)) {
if ( size ) {
if (*val == '-') {
negative = true;
val++;
size--;
}
for (sum = 0; size > 0; size--)
{
if (*val < '0' || *val > '9')
for (sum = 0; size > 0; size--) {
if (*val < '0' || *val > '9') {
return false;
}
sum = (sum * 10) + (*val++ - '0');
}
if (negative)
if (negative) {
sum = -sum;
}
*value = sum;
return true;
}
}
return false;
return false;
}
/*
bool getDimensionForKey( const char *key, unsigned int *value, config_file_t *config, unsigned int dimension_max, unsigned int object_size )
{
const char *val;
int size = 0;
int size = 0;
int sum = 0;
bool negative = false;
bool percentage = false;
if (getValueForKey(key, &val, &size, config))
{
if ( size )
{
if (*val == '-')
{
if (getValueForKey(key, &val, &size, config)) {
if ( size ) {
if (*val == '-') {
negative = true;
val++;
size--;
}
if (val[size-1] == '%')
{
if (val[size-1] == '%') {
percentage = true;
size--;
}
// convert string to integer
for (sum = 0; size > 0; size--)
{
if (*val < '0' || *val > '9')
for (sum = 0; size > 0; size--) {
if (*val < '0' || *val > '9') {
return false;
}
sum = (sum * 10) + (*val++ - '0');
}
if (percentage)
if (percentage) {
sum = ( dimension_max * sum ) / 100;
}
// calculate offset from opposite origin
if (negative)
if (negative) {
sum = ( ( dimension_max - object_size ) - sum );
}
} else {
// null value calculate center
sum = ( dimension_max - object_size ) / 2;
}
*value = (uint16_t) sum;
return true;
}
// key not found
return false;
return false;
}
/*
bool getColorForKey( const char *key, unsigned int *value, config_file_t *config )
{
const char *val;
int size;
if (getValueForKey(key, &val, &size, config))
const char *val;
int size;
if (getValueForKey(key, &val, &size, config))
{
if (*val == '#')
{
val++;
if (*val == '#') {
val++;
*value = strtol(val, NULL, 16);
return true;
}
}
return false;
}
}
return false;
}
bool getValueForKey( const char *key, const char **val, int *size, config_file_t *config )
{
const char *overrideVal;
int overrideSize;
bool override, ret;
if (getValueForBootKey(bootArgs->CommandLine, key, val, size))
return true;
const char *overrideVal;
int overrideSize;
bool override, ret;
ret = getValueForConfigTableKey(config, key, val, size);
if (getValueForBootKey(bootArgs->CommandLine, key, val, size)) {
return true;
}
// Try to find alternate keys in bootInfo->chameleonConfig (if config can be overriden)
// and prefer its values with the exceptions for
// "Kernel"="mach_kernel" and "Kernel Flags"="".
ret = getValueForConfigTableKey(config, key, val, size);
if (config->canOverride)
{
if (getValueForConfigTableKey(&bootInfo->chameleonConfig, key, &overrideVal, &overrideSize))
{
override = true;
// Try to find alternate keys in bootInfo->chameleonConfig (if config can be overriden)
// and prefer its values with the exceptions for
// "Kernel"="mach_kernel" and "Kernel Flags"="".
// NOTE: Values are defined by apple as being in com.apple.Boot.plist
// kHelperRootUUIDKey, kKernelArchKey, kMKextCacheKey, kKernelCacheKey, kKernelNameKey, kKernelFlagsKey
if (ret && (strcmp(key, kKernelNameKey) == 0) && (overrideSize == 0))
override = false;
if (config->canOverride) {
if (getValueForConfigTableKey(&bootInfo->chameleonConfig, key, &overrideVal, &overrideSize)) {
override = true;
if (ret && (strcmp(key, kKernelFlagsKey) == 0) && (overrideSize == 0))
override = false;
// NOTE: Values are defined by apple as being in com.apple.Boot.plist
// kHelperRootUUIDKey, kKernelArchKey, kMKextCacheKey, kKernelCacheKey, kKernelNameKey, kKernelFlagsKey
if (ret && (strcmp(key, kKernelNameKey) == 0) && (overrideSize == 0)) {
override = false;
}
if (override)
{
*val = overrideVal;
*size = overrideSize;
return true;
}
}
}
if (ret && (strcmp(key, kKernelFlagsKey) == 0) && (overrideSize == 0)) {
override = false;
}
return ret;
if (override) {
*val = overrideVal;
*size = overrideSize;
return true;
}
}
}
return ret;
}
void
printSystemConfig(char *p1)
{
char *p2 = p1, tmp;
char *p2 = p1, tmp;
while (*p1 != '\0') {
while (*p2 != '\0' && *p2 != '\n') p2++;
while (*p1 != '\0') {
while (*p2 != '\0' && *p2 != '\n') {
p2++;
}
tmp = *p2;
*p2 = '\0';
printf("%s\n", p1);
*p2 = tmp;
if (tmp == '\0') break;
if (tmp == '\0') {
break;
}
p1 = ++p2;
}
}
//
int ParseXMLFile( char * buffer, TagPtr * dict )
{
long length, pos;
TagPtr tag;
pos = 0;
char *configBuffer;
long length, pos;
TagPtr tag;
pos = 0;
char *configBuffer;
configBuffer = malloc(strlen(buffer)+1);
strcpy(configBuffer, buffer);
configBuffer = malloc(strlen(buffer)+1);
strcpy(configBuffer, buffer);
while (1)
{
length = XMLParseNextTag(configBuffer + pos, &tag);
if (length == -1) break;
pos += length;
if (tag == 0) continue;
if (tag->type == kTagTypeDict) break;
XMLFreeTag(tag);
}
free(configBuffer);
if (length < 0) {
error ("Error parsing plist file\n");
return -1;
}
*dict = tag;
return 0;
while (1) {
length = XMLParseNextTag(configBuffer + pos, &tag);
if (length == -1) {
break;
}
pos += length;
if (tag == 0) {
continue;
}
if (tag->type == kTagTypeDict) {
break;
}
XMLFreeTag(tag);
}
free(configBuffer);
if (length < 0) {
error ("Error parsing plist file\n");
return -1;
}
*dict = tag;
return 0;
}
/* loadConfigFile
// read file
count = read(fd, config->plist, IO_CONFIG_DATA_SIZE);
close(fd);
// build xml dictionary
ParseXMLFile(config->plist, &config->dictionary);
return 0;
int i, fd, count, ret=-1;
for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++)
{
if ((fd = open(dirspec[i], 0)) >= 0)
{
for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++) {
if ((fd = open(dirspec[i], 0)) >= 0) {
// read file
count = read(fd, config->plist, IO_CONFIG_DATA_SIZE);
close(fd);
// build xml dictionary
ParseXMLFile(config->plist, &config->dictionary);
sysConfigValid = true;
ret=0;
break;
}
}
int i, fd, count, ret=-1;
for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++)
{
if ((fd = open(dirspec[i], 0)) >= 0)
{
// Check for depreciated file names and annoy the user about it.
if(strstr(dirspec[i], "com.apple.Boot.plist"))
{
printf("%s is depreciated.\n", dirspec[i]);
dirspec[i][strlen(dirspec[i]) - strlen("com.apple.Boot.plist")] = 0;
printf("Please use the file %sorg.chameleon.Boot.plist instead.\n", dirspec[i]);
pause();
}
for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++) {
if ((fd = open(dirspec[i], 0)) >= 0) {
// Check for depreciated file names and annoy the user about it.
if(strstr(dirspec[i], "com.apple.Boot.plist")) {
printf("%s is depreciated.\n", dirspec[i]);
dirspec[i][strlen(dirspec[i]) - strlen("com.apple.Boot.plist")] = 0;
printf("Please use the file %sorg.chameleon.Boot.plist instead.\n", dirspec[i]);
pause();
}
// read file
count = read(fd, config->plist, IO_CONFIG_DATA_SIZE);
close(fd);
int i, fd, count, ret=-1;
for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++)
{
if ((fd = open(dirspec[i], 0)) >= 0)
{
for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++) {
if ((fd = open(dirspec[i], 0)) >= 0) {
// read file
count = read(fd, config->plist, IO_CONFIG_DATA_SIZE);
close(fd);
char * newString(const char * oldString)
{
if ( oldString )
return strcpy(malloc(strlen(oldString)+1), oldString);
else
return NULL;
if ( oldString ) {
return strcpy(malloc(strlen(oldString)+1), oldString);
} else {
return NULL;
}
}
/*
*/
char * getNextArg(char ** argPtr, char * val)
{
char * ptr = *argPtr;
const char * strStart;
int len = 0;
bool isQuoted = false;
char * ptr = *argPtr;
const char * strStart;
int len = 0;
bool isQuoted = false;
*val = '\0';
*val = '\0';
// Scan for the next non-whitespace character.
while ( *ptr && (*ptr == ' ' || *ptr == '=') )
{
ptr++;
}
// Scan for the next non-whitespace character.
while ( *ptr && (*ptr == ' ' || *ptr == '=') ) {
ptr++;
}
strStart = ptr;
strStart = ptr;
// Skip the leading double quote character.
if (*ptr == '\"')
{
isQuoted = true;
ptr++;
strStart++;
}
// Skip the leading double quote character.
if (*ptr == '\"') {
isQuoted = true;
ptr++;
strStart++;
}
// Scan for the argument terminator character.
// This can be either a NULL character - in case we reach the end of the string,
// a double quote in case of quoted argument,
// or a whitespace character (' ' or '=') for non-quoted argument.
while (*ptr && !( (isQuoted && (*ptr == '\"')) ||
// Scan for the argument terminator character.
// This can be either a NULL character - in case we reach the end of the string,
// a double quote in case of quoted argument,
// or a whitespace character (' ' or '=') for non-quoted argument.
while (*ptr && !( (isQuoted && (*ptr == '\"')) ||
(!isQuoted && (*ptr == ' ' || *ptr == '=')) )
)
{
ptr++;
}
) {
ptr++;
}
len = ptr - strStart;
len = ptr - strStart;
// Skip the closing double quote character and adjust
// the starting pointer for the next getNextArg call.
if (*ptr && isQuoted && *ptr == '\"')
ptr++;
// Skip the closing double quote character and adjust
// the starting pointer for the next getNextArg call.
if (*ptr && isQuoted && *ptr == '\"') {
ptr++;
}
// Copy the extracted argument to val.
strncat(val, strStart, len);
// Copy the extracted argument to val.
strncat(val, strStart, len);
// Set command line pointer.
*argPtr = ptr;
// Set command line pointer.
*argPtr = ptr;
return ptr;
return ptr;
}
trunk/i386/libsaio/convert.c
104104
105105
106106
107
108
109
110
107
108
109
110
111
111112
112113
113114
{
binChar = 0;
for (hexNibbleIdx = 0; hexNibbleIdx < sizeof(hexByte); hexNibbleIdx++)
{
if (hexNibbleIdx > 0) binChar = binChar << 4;
for (hexNibbleIdx = 0; hexNibbleIdx < sizeof(hexByte); hexNibbleIdx++) {
if (hexNibbleIdx > 0) {
binChar = binChar << 4;
}
if (hexByte[hexNibbleIdx] <= '9') binChar += hexByte[hexNibbleIdx] - '0';
else if (hexByte[hexNibbleIdx] <= 'F') binChar += hexByte[hexNibbleIdx] - ('A' - 10);
else if (hexByte[hexNibbleIdx] <= 'f') binChar += hexByte[hexNibbleIdx] - ('a' - 10);
trunk/i386/libsaio/saio_types.h
157157
158158
159159
160
160
161161
162162
163163
......
169169
170170
171171
172
172
173173
174174
175175
......
217217
218218
219219
220
220
221221
222222
223223
......
238238
239239
240240
241
242
243
241
242
244243
245244
246245
......
271270
272271
273272
274
273
275274
276275
277276
char * i_buf;/* file load address */
};
#define BPS 512/* sector size of the device */
#define BPS 512/* sector size of the device */
#define F_READ 0x1/* file opened for reading */
#define F_WRITE 0x2/* file opened for writing */
#define F_ALLOC 0x4/* buffer allocated */
struct dirstuff {
char * dir_path;/* directory path */
long long dir_index;/* directory entry index */
BVRef dir_bvr;/* volume reference */
BVRef dir_bvr;/* volume reference */
};
#define BVSTRLEN 32
enum {
kBIOSDevTypeFloppy= 0x00,
kBIOSDevTypeHardDrive= 0x80,
kBIOSDevTypeHardDrive= 0x80,
kBIOSDevTypeNetwork= 0xE0,
kBIOSDevUnitMask= 0x0F,
kBIOSDevTypeMask= 0xF0,
//#define BIOS_DEV_TYPE(d)((d) & kBIOSDevTypeMask)
#define BIOS_DEV_UNIT(bvr)((bvr)->biosdev - (bvr)->type)
/*
* KernBootStruct device types.
*/
// KernBootStruct device types.
enum {
DEV_SD = 0,
DEV_HD = 1,
}; //gBootFileType_t;
enum {
kCursorTypeHidden = 0x0100,
kCursorTypeHidden = 0x0100,
kCursorTypeUnderline = 0x0607
};
trunk/i386/include/string.h
108108
109109
110110
111
111112
112113
113114
int strncmp(const char *, const char *, size_t);
char*strncpy(char *, const char *, size_t);
#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
char*stpncpy(char *, const char *, size_t);
char*strnstr(const char *, const char *, size_t);
#endif/* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
char*strpbrk(const char *, const char *);
trunk/i386/include/mach/mach.h
4949
5050
5151
52
53
54
52
5553
5654
5755
*
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*/
/*
*
* Includes all the types that a normal user
* of Mach programs should need
*/
trunk/i386/boot2/mboot.c
433433
434434
435435
436
436
437437
438438
439439
multiboot_skip_partition = intVal;
multiboot_skip_partition_set = 1;
}
}
}
}
if(doSelectDevice)
{
trunk/i386/boot2/resume.c
2222
2323
2424
25
26
27
25
26
27
2828
29
30
31
32
33
34
35
36
37
38
39
29
30
31
32
33
34
35
36
37
4038
4139
4240
......
5048
5149
5250
53
51
5452
55
53
5654
5755
5856
5957
60
58
6159
6260
6361
64
62
6563
6664
6765
68
66
6967
7068
71
69
7270
7371
7472
......
8583
8684
8785
88
86
8987
9088
9189
9290
9391
9492
95
93
9694
9795
9896
......
103101
104102
105103
106
104
107105
108106
109107
110108
111109
112
113
110
114111
115112
116113
117
118
114
119115
120116
121117
......
128124
129125
130126
131
132
127
128
129
130
133131
132
134133
135134
136135
......
139138
140139
141140
142
143
141
144142
145143
146144
147145
148
146
149147
150148
151149
152150
153151
154152
155
156
153
157154
158155
159156
......
162159
163160
164161
165
162
166163
167164
168165
166
169167
170168
171169
......
177175
178176
179177
180
181
178
182179
183
180
184181
185182
186183
......
210207
211208
212209
213
210
214211
215212
static unsigned long
getmemorylimit(void)
{
int line;
int i;
MemoryRange *mp = bootInfo->memoryMap;
int line;
int i;
MemoryRange *mp = bootInfo->memoryMap;
// Activate and clear page 1
line = 1;
for (i = 0; i < bootInfo->memoryMapCount; i++)
{
if((mp->type == 1) && ((unsigned long)mp->base == 0x100000))
{
return (unsigned long)(mp->base + mp->length);
}
mp++;
}
return 0x10000000;
// Activate and clear page 1
line = 1;
for (i = 0; i < bootInfo->memoryMapCount; i++) {
if((mp->type == 1) && ((unsigned long)mp->base == 0x100000)) {
return (unsigned long)(mp->base + mp->length);
}
mp++;
}
return 0x10000000;
}
static void WakeKernel(IOHibernateImageHeader * header)
int32_t byteCnt;
u_int32_t lowHalf, highHalf;
u_int32_t sum;
printf("\nWake Kernel!\n");
dst = (unsigned long *) (header->restore1CodePage << 12);
count = header->restore1PageCount;
proc = (header->restore1CodeOffset + ((uint32_t) dst));
newSP = header->restore1StackOffset + (header->restore1CodePage << 12);
src = (unsigned long *) (((u_int32_t) &header->fileExtentMap[0])
+ header->fileExtentMapSize);
sum = 0;
for (page = 0; page < count; page++)
{
compressedSize = 4096;
lowHalf = 1;
highHalf = 0;
for (cnt = 0; cnt < compressedSize; cnt += 0x20) {
dst[0] = src[0];
dst[1] = src[1];
src += 8;
dst += 8;
}
lowHalf %= 65521L;
highHalf %= 65521L;
sum += (highHalf << 16) | lowHalf;
}
header->actualRestore1Sum = sum;
startprog (proc, header);
return;
}
IOHibernateImageHeader _header;
IOHibernateImageHeader * header = &_header;
long buffer;
size = ReadFileAtOffset (image_filename, header, 0, sizeof(IOHibernateImageHeader));
printf("header read size %x\n", size);
imageSize = header->image1Size;
codeSize = header->restore1PageCount << 12;
if (kIOHibernateHeaderSignature != header->signature)
{
if (kIOHibernateHeaderSignature != header->signature) {
printf ("Incorrect image signature\n");
return;
}
if (header->encryptStart)
{
if (header->encryptStart) {
printf ("Resuming from Encrypted image is unsupported.\n"
"Uncheck \"Use secure virtual memory\" in \"Security\" pane on system preferences.\n"
"Press any key to proceed with normal boot.\n");
uint32_t machineSignature;
size = GetProp(gChosenPH, kIOHibernateMachineSignatureKey,
(char *)&machineSignature, sizeof(machineSignature));
if (size != sizeof(machineSignature)) machineSignature = 0;
if (machineSignature != header->machineSignature)
if (size != sizeof(machineSignature)) {
machineSignature = 0;
}
if (machineSignature != header->machineSignature) {
break;
}
}
#endif
mem_base = getmemorylimit() - allocSize;//TODO: lower this
printf("mem_base %x\n", mem_base);
if (((long long)mem_base + allocSize) < (1024 * bootInfo->extmem + 0x100000))
{
if (((long long)mem_base + allocSize) < (1024 * bootInfo->extmem + 0x100000)) {
printf ("Not enough space to restore image. Press any key to proceed with normal boot.\n");
getchar();
return;
}
bcopy(header, (void *) mem_base, sizeof(IOHibernateImageHeader));
header = (IOHibernateImageHeader *) mem_base;
imageSize -= sizeof(IOHibernateImageHeader);
buffer = (long)(header + 1);
if (header->previewSize)
{
if (header->previewSize) {
uint64_t preview_offset = header->fileExtentMapSize - sizeof(header->fileExtentMap) + codeSize;
uint8_t progressSaveUnder[kIOHibernateProgressCount][kIOHibernateProgressSaveUnderSize];
previewTotalSectors = (imageSize-(preview_offset+header->previewSize))/512;
previewLoadedSectors = 0;
previewSaveunder = &(progressSaveUnder[0][0]);
if (preview_offset+header->previewSize<imageSize)
if (preview_offset+header->previewSize<imageSize) {
ReadFileAtOffset (image_filename, (char *)(long)(buffer+preview_offset+header->previewSize),
sizeof(IOHibernateImageHeader)+preview_offset+header->previewSize,
imageSize-(preview_offset+header->previewSize));
}
previewTotalSectors = 0;
previewLoadedSectors = 0;
previewSaveunder = 0;
remove it completely
setVideoMode( VGA_TEXT_MODE, 0 );
#endif
}
else
} else {
ReadFileAtOffset (image_filename, (char *)buffer, sizeof(IOHibernateImageHeader), imageSize);
}
// Depends on NVRAM
#if 0
if (header->encryptStart) {
bzero(&decryptkey, sizeof(decryptkey));
}
#endif
WakeKernel(header);
}
trunk/i386/boot2/boot.h
144144
145145
146146
147
147148
148149
149150
......
157158
158159
159160
161
162
163
164
160165
161166
162167
/* ErmaC: added these keys */
#define kEnableDualLink"EnableDualLink"/* nvidia.c && gma.c*/
#define kNvidiaGeneric"NvidiaGeneric"/* nvidia.c */
#define kSkipIntelGfx"SkipIntelGfx"/* pci_setup.c */
#define kSkipNvidiaGfx"SkipNvidiaGfx"/* pci_setup.c */
#define kSkipAtiGfx"SkipAtiGfx"/* pci_setup.c */
/* Karas: added these keys */
#define kMemFullInfo"ForceFullMemInfo"/* smbios.c */
/* Bungo: added these keys */
// mask private data or no
#define kPrivateData"PrivateData"/* smbios_decode.c */
/*
* Flags to the booter or kernel
*/
trunk/i386/boot2/gui.c
3636
3737
3838
39
40
39
40
4141
4242
4343
......
5555
5656
5757
58
5859
5960
6061
......
233234
234235
235236
236
237
238
239
237
238
240239
241240
242241
......
256255
257256
258257
259
260
261
262
258
259
263260
264
265
266
261
267262
268263
269264
270265
271
272
273
274
266
267
275268
276
277
278
269
279270
280271
281272
......
296287
297288
298289
299
290
300291
301
292
293
302294
303
295
296
304297
305
306
307
308
309
310
311
312
313
314
315
316
298
299
300
301
302
303
304
305
306
307
308
309
317310
318
319
320
321
322
323
311
312
313
314
315
324316
325
326
327
328
329
330
331
317
318
319
320
321
322
332323
333324
334325
335
336
326
337327
338328
339329
......
440430
441431
442432
443
433
444434
445
446
447
448
449
450
451
452
453
435
436
437
438
439
440
441
442
443
454444
455445
456446
......
458448
459449
460450
461
462
463
464
465
466
467
451
452
453
454
455
456
468457
469
458
470459
471460
472461
473462
474
475463
476
464
477465
466
478467
479
468
480469
481
470
482471
483472
484473
485474
486475
487476
488
489
490
491
477
478
492479
493480
494481
......
498485
499486
500487
501
502
488
503489
504490
505491
506
507
492
508493
509494
510495
......
519504
520505
521506
522
523
507
524508
525509
526510
527511
528
529
512
530513
531514
532515
......
540523
541524
542525
543
544
526
545527
546528
547529
548530
549
550531
551532
552533
......
555536
556537
557538
558
559
539
540
560541
542
543
561544
562545
563546
......
574557
575558
576559
577
560
578561
579562
580563
......
583566
584567
585568
586
569
587570
588571
589572
590573
591
574
592575
576
593577
594
578
595579
580
596581
597582
598583
......
607592
608593
609594
610
595
611596
597
612598
613
599
614600
601
615602
616603
617604
......
619606
620607
621608
622
609
623610
624
611
625612
626
613
614
627615
616
628617
629
618
630619
620
631621
632622
633623
634
624
635625
626
636627
637
628
638629
630
639631
640
641
642
643
644
632
633
634
635
645636
646637
647638
......
649640
650641
651642
652
643
653644
654645
655646
656647
657648
658649
659
650
660651
661
662
652
653
663654
664
665
655
656
666657
658
667659
668660
669661
......
671663
672664
673665
674
666
675667
668
676669
677670
678671
679672
680
673
681674
675
682676
683677
678
684679
680
685681
686682
687683
688684
689685
686
690687
688
691689
692690
691
693692
693
694694
695695
696696
697697
698698
699
699700
701
700702
701703
704
702705
706
703707
704708
705709
......
710714
711715
712716
717
713718
714
719
715720
721
716722
717
723
718724
725
719726
720
727
721728
729
722730
723
731
724732
733
725734
726
735
727736
737
728738
729
739
730740
741
731742
732
743
733744
745
734746
735
747
736748
737749
738750
739751
752
740753
754
741755
756
742757
743
758
744759
760
745761
762
746763
764
747765
748
766
749767
768
750769
751
770
752771
772
753773
754
774
755775
776
756777
757
778
758779
780
759781
760
782
761783
784
762785
763
786
764787
788
765789
790
766791
767792
768793
769794
770795
796
771797
772
798
773799
800
774801
775
802
776803
804
777805
778
806
779807
808
780809
781
810
782811
812
783813
784
814
785815
816
786817
787
818
788819
820
789821
790
822
791823
824
792825
793
826
794827
828
795829
796
830
797831
832
798833
834
799835
800836
801837
......
811847
812848
813849
814
850
815851
816
817
818
819
852
853
854
855
820856
821857
822858
......
852888
853889
854890
855
891
856892
857893
858894
......
888924
889925
890926
891
927
892928
893
894
929
895930
896931
897932
......
923958
924959
925960
926
961
927962
928963
929964
......
9881023
9891024
9901025
991
992
1026
9931027
9941028
9951029
......
10161050
10171051
10181052
1019
1020
1053
10211054
10221055
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
10361066
1037
1067
10381068
1039
1069
10401070
10411071
1042
1043
1072
10441073
10451074
10461075
......
10631092
10641093
10651094
1066
1067
1095
10681096
10691097
1070
1071
1098
10721099
10731100
10741101
10751102
10761103
1077
1104
10781105
1079
1106
10801107
1081
1108
10821109
1083
1110
10841111
10851112
10861113
......
10941121
10951122
10961123
1097
1098
1124
10991125
11001126
11011127
......
11331159
11341160
11351161
1136
1162
11371163
1138
1139
1164
11401165
11411166
1142
1143
1144
1167
1168
11451169
11461170
11471171
1148
1149
1172
11501173
11511174
11521175
......
11631186
11641187
11651188
1189
11661190
11671191
11681192
11691193
11701194
1171
1172
1173
1195
1196
11741197
1175
1176
1198
1199
11771200
1178
1179
1201
1202
11801203
1181
1182
1204
1205
11831206
1207
11841208
11851209
11861210
11871211
1188
1189
1212
11901213
11911214
11921215
......
11941217
11951218
11961219
1197
1198
1220
1221
11991222
12001223
12011224
12021225
12031226
1204
1205
1206
1207
1208
1209
1210
1227
1228
1229
1230
1231
1232
1233
1234
12111235
12121236
12131237
......
12421266
12431267
12441268
1245
1246
1269
12471270
12481271
12491272
12501273
12511274
1252
1253
1275
12541276
12551277
12561278
1257
1279
12581280
1259
1281
12601282
12611283
12621284
12631285
1264
1286
12651287
1266
1288
1289
12671290
1268
1291
12691292
1293
12701294
12711295
12721296
12731297
1274
1275
1298
12761299
12771300
12781301
12791302
12801303
1281
1304
12821305
1306
12831307
12841308
12851309
......
12881312
12891313
12901314
1291
12921315
12931316
12941317
......
13271350
13281351
13291352
1330
1331
1353
13321354
13331355
13341356
13351357
13361358
1337
1338
1359
13391360
13401361
13411362
1342
1363
13431364
1344
1365
13451366
13461367
13471368
13481369
1349
1370
13501371
1351
1372
13521373
1353
1374
13541375
1355
1376
13561377
13571378
13581379
1359
1360
1380
13611381
13621382
13631383
13641384
13651385
1366
1386
13671387
1388
13681389
13691390
13701391
......
14031424
14041425
14051426
1406
1407
1427
14081428
14091429
14101430
14111431
1412
1413
1432
14141433
14151434
1416
1417
1435
14181436
14191437
14201438
......
14241442
14251443
14261444
1427
1428
1445
14291446
14301447
14311448
14321449
14331450
14341451
1435
1436
1452
14371453
14381454
14391455
14401456
14411457
1442
1443
1458
14441459
14451460
14461461
14471462
14481463
1449
1464
14501465
1466
14511467
14521468
14531469
......
14601476
14611477
14621478
1463
1479
14641480
14651481
1466
1482
14671483
14681484
14691485
14701486
14711487
1472
1473
1488
14741489
14751490
1476
1477
1491
14781492
1493
14791494
14801495
14811496
......
14831498
14841499
14851500
1486
1487
1501
14881502
1489
1490
1503
14911504
14921505
14931506
14941507
14951508
14961509
1497
1498
1510
14991511
15001512
15011513
......
15131525
15141526
15151527
1516
1517
1528
15181529
15191530
1520
1521
1531
15221532
1523
1524
1533
15251534
1526
1535
15271536
1537
15281538
1529
1539
15301540
1541
15311542
15321543
15331544
......
15381549
15391550
15401551
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
15521563
15531564
15541565
......
15611572
15621573
15631574
1564
1565
1575
15661576
15671577
15681578
1569
1570
1579
15711580
15721581
1573
1574
1582
15751583
15761584
15771585
1578
1579
1586
15801587
15811588
1582
1583
1584
1585
1589
1590
15861591
15871592
15881593
15891594
15901595
1591
1596
15921597
1598
15931599
15941600
15951601
......
15991605
16001606
16011607
1602
1608
16031609
1610
16041611
1605
1612
16061613
1614
16071615
16081616
16091617
......
16121620
16131621
16141622
1615
1623
16161624
1617
1625
1626
16181627
16191628
16201629
16211630
1622
1623
1631
16241632
16251633
1626
1627
1628
1629
1634
1635
16301636
1631
1632
1637
16331638
16341639
16351640
......
16621667
16631668
16641669
1665
1666
1667
1668
1670
1671
16691672
1670
1671
1673
16721674
16731675
16741676
......
16951697
16961698
16971699
1698
1700
16991701
1700
1702
1703
17011704
17021705
17031706
1704
1705
1707
17061708
17071709
17081710
1709
1710
1711
1712
17111713
1712
1714
1715
17131716
17141717
17151718
17161719
1717
1718
1720
1721
17191722
1720
1723
1724
17211725
1722
1726
17231727
1724
1728
17251729
17261730
17271731
1728
1729
1732
17301733
1731
1732
1733
1734
1735
17341736
1735
1737
1738
17361739
1740
17371741
17381742
17391743
1740
1741
1742
1744
1745
17431746
1744
1745
1747
1748
17461749
17471750
17481751
......
17531756
17541757
17551758
1756
1759
17571760
1758
1761
17591762
17601763
17611764
17621765
1763
1766
17641767
1765
1768
17661769
17671770
17681771
1769
1770
1772
17711773
17721774
17731775
17741776
1775
1776
1777
17771778
17781779
17791780
......
17861787
17871788
17881789
1789
1790
1790
1791
17911792
1793
1794
17921795
1793
1794
1796
1797
17951798
1799
1800
17961801
1797
1798
1802
17991803
18001804
18011805
18021806
18031807
18041808
1805
1806
1807
1809
1810
18081811
1809
1810
1812
1813
18111814
1815
18121816
18131817
18141818
......
18181822
18191823
18201824
1821
1822
1825
18231826
18241827
18251828
......
18281831
18291832
18301833
1831
1834
18321835
1833
1836
18341837
18351838
18361839
18371840
18381841
18391842
1840
1843
18411844
1842
1845
1846
18431847
18441848
18451849
18461850
18471851
18481852
1849
1853
18501854
1851
1855
1856
18521857
18531858
1854
1859
18551860
1856
1861
1862
18571863
18581864
18591865
18601866
18611867
1862
1863
1864
1865
1866
1868
1869
1870
1871
1872
18671873
18681874
18691875
18701876
18711877
1872
1873
1874
1875
1876
1878
1879
1880
1881
1882
18771883
18781884
1879
1885
18801886
1881
1887
1888
1889
18821890
1891
1892
18831893
18841894
18851895
......
19061916
19071917
19081918
1909
1910
1911
1912
1919
1920
19131921
19141922
19151923
19161924
1917
1918
1925
19191926
19201927
1921
1922
1923
1928
19241929
19251930
19261931
......
19521957
19531958
19541959
1955
1956
1957
1958
1960
1961
19591962
1960
1961
1962
1963
19631964
19641965
19651966
19661967
19671968
1968
1969
1970
1969
19711970
19721971
19731972
......
19791978
19801979
19811980
1982
1983
1981
19841982
1983
19851984
1986
1985
19871986
1987
19881988
19891989
19901990
......
19921992
19931993
19941994
1995
1995
19961996
1997
1998
1997
19991998
2000
2001
1999
20022000
2003
2004
2005
2001
20062002
20072003
20082004
......
20342030
20352031
20362032
2037
2033
20382034
20392035
20402036
......
20692065
20702066
20712067
2072
2068
20732069
20742070
20752071
......
20792075
20802076
20812077
2082
2083
2084
2085
2078
2079
20862080
20872081
20882082
* ATTENTION: the enum and the following array images[] MUST match !!!
*/
enum {
iBackground = 0,
iLogo,
iBackground = 0,
iLogo,
iDeviceGeneric,
iDeviceGeneric_o,
iDeviceHFS_Leo_o,
iDeviceHFS_Tiger,
iDeviceHFS_Tiger_o,
iDeviceHFSRAID,
iDeviceHFSRAID_o,
iDeviceHFSRAID_mav,
static int getImageIndexByName(const char *name)
{
int i;
for (i = 0; i < sizeof(images) / sizeof(images[0]); i++)
{
if (strcmp(name, images[i].name) == 0)
{
for (i = 0; i < sizeof(images) / sizeof(images[0]); i++) {
if (strcmp(name, images[i].name) == 0) {
return i; // found the name
}
}
// generated manualy, this *will* fail to work properly.
while((result = strcmp(name, embeddedImages[compareIndex].name)) != 0)
{
if (result > 0)// We need to search a HIGHER index
{
if (compareIndex != lowerLimit)
{
if (result > 0){ // We need to search a HIGHER index
if (compareIndex != lowerLimit) {
lowerLimit = compareIndex;
}
else
{
} else {
return -1;
}
compareIndex = (upperLimit + lowerLimit + 1) >> 1;// Midpoint, round up
}
else // We Need to search a LOWER index
{
if (compareIndex != upperLimit)
{
else { // We Need to search a LOWER index
if (compareIndex != upperLimit) {
upperLimit = compareIndex;
}
else
{
} else {
return -1;
}
compareIndex = (upperLimit + lowerLimit) >> 1;// Midpoint, round down
uint16_theight;
uint8_t*imagedata;
if ((strlen(image) + strlen(theme_name) + 20) > sizeof(dirspec))
if ((strlen(image) + strlen(theme_name) + 20) > sizeof(dirspec)) {
return 1;
if ((i = getImageIndexByName(image)) < 0)
}
if ((i = getImageIndexByName(image)) < 0) {
return 1;
if (!images[i].image && !(images[i].image = malloc(sizeof(pixmap_t))))
}
if (!images[i].image && !(images[i].image = malloc(sizeof(pixmap_t)))) {
return 1;
sprintf(dirspec, "/Extra/Themes/%s/%s.png", theme_name, image);
width = 0;
height = 0;
imagedata = NULL;
if ((loadPngImage(dirspec, &width, &height, &imagedata)) == 0)
{
images[i].image->width = width;
images[i].image->height = height;
images[i].image->pixels = (pixel_t *)imagedata;
flipRB(images[i].image);
return 0;
}
}
sprintf(dirspec, "/Extra/Themes/%s/%s.png", theme_name, image);
width = 0;
height = 0;
imagedata = NULL;
if ((loadPngImage(dirspec, &width, &height, &imagedata)) == 0) {
images[i].image->width = width;
images[i].image->height = height;
images[i].image->pixels = (pixel_t *)imagedata;
flipRB(images[i].image);
return 0;
}
#ifdef CONFIG_EMBED_THEME
else if ((e = getEmbeddedImageIndexByName(image)) >= 0)
{
unsigned char *embed_data;
unsigned int embed_size;
embed_data = embeddedImages[e].pngdata;
embed_size = *embeddedImages[e].length;
else if ((e = getEmbeddedImageIndexByName(image)) >= 0) {
unsigned char *embed_data;
unsigned int embed_size;
embed_data = embeddedImages[e].pngdata;
embed_size = *embeddedImages[e].length;
if (loadEmbeddedPngImage(embed_data, embed_size, &width, &height, &imagedata) == 0)
{
images[i].image->width = width;
images[i].image->height = height;
images[i].image->pixels = (pixel_t *)imagedata;
flipRB(images[i].image);
return 0;
if (loadEmbeddedPngImage(embed_data, embed_size, &width, &height, &imagedata) == 0) {
images[i].image->width = width;
images[i].image->height = height;
images[i].image->pixels = (pixel_t *)imagedata;
flipRB(images[i].image);
return 0;
}
}
#endif
else if (alt_image != IMG_REQUIRED && is_image_loaded(alt_image))
{
else if (alt_image != IMG_REQUIRED && is_image_loaded(alt_image)) {
// Using the passed alternate image for non-mandatory images.
// We don't clone the already existing pixmap, but using its properties instead!
images[i].image->width = images[alt_image].image->width;
static int unloadGraphics(void)
{
int i;
int i;
destroyFont(&font_console);
destroyFont(&font_small);
for (i = 0; i < sizeof(images) / sizeof(images[0]); i++)
{
if (images[i].image)
{
if (images[i].image->pixels) free(images[i].image->pixels);
free (images[i].image);
images[i].image = 0;
destroyFont(&font_console);
destroyFont(&font_small);
for (i = 0; i < sizeof(images) / sizeof(images[0]); i++) {
if (images[i].image) {
if (images[i].image->pixels) {
free(images[i].image->pixels);
}
free (images[i].image);
images[i].image = 0;
}
}
return 0;
int freeBackBuffer( window_t *window )
{
if (gui.backbuffer && gui.backbuffer->pixels)
{
free(gui.backbuffer->pixels);
free(gui.backbuffer);
gui.backbuffer = 0;
return 0;
}
if (gui.backbuffer && gui.backbuffer->pixels) {
free(gui.backbuffer->pixels);
free(gui.backbuffer);
gui.backbuffer = 0;
return 0;
}
return 1;
return 1;
}
pixmap_t *getCroppedPixmapAtPosition( pixmap_t *from, position_t pos, uint16_t width, uint16_t height )
{
pixmap_t *cropped = malloc( sizeof( pixmap_t ) );
if( !cropped )
if( !cropped ) {
return 0;
}
cropped->pixels = malloc( width * height * 4 );
if ( !cropped->pixels )
if ( !cropped->pixels ) {
return 0;
}
cropped->width = width;
cropped->height = height;
int destx = 0, desty = 0;
int srcx = pos.x, srcy = pos.y;
for( ; desty < height; desty++, srcy++)
{
for( destx = 0, srcx = pos.x; destx < width; destx++, srcx++ )
{
for( ; desty < height; desty++, srcy++) {
for( destx = 0, srcx = pos.x; destx < width; destx++, srcx++ ) {
pixel( cropped, destx, desty ).value = pixel( from, srcx, srcy ).value;
}
}
int createBackBuffer( window_t *window )
{
gui.backbuffer = malloc(sizeof(pixmap_t));
if(!gui.backbuffer)
{
if(!gui.backbuffer) {
return 1;
}
gui.backbuffer->pixels = malloc( window->width * window->height * 4 );
if(!gui.backbuffer->pixels)
{
if(!gui.backbuffer->pixels) {
free(gui.backbuffer);
gui.backbuffer = 0;
return 1;
int createWindowBuffer( window_t *window )
{
window->pixmap = malloc(sizeof(pixmap_t));
if(!window->pixmap)
{
if(!window->pixmap) {
return 1;
}
window->pixmap->pixels = malloc( window->width * window->height * 4 );
if(!window->pixmap->pixels)
{
if(!window->pixmap->pixels) {
free(window->pixmap);
window->pixmap = 0;
return 1;
int freeWindowBuffer( window_t *window )
{
if (window->pixmap && window->pixmap->pixels)
{
if (window->pixmap && window->pixmap->pixels) {
free(window->pixmap->pixels);
free(window->pixmap);
return 0;
}
return 1;
}
int x,y;
// fill with given color AARRGGBB
for( x=0; x < pm->width; x++ )
for( y=0; y< pm->height; y++)
for( x=0; x < pm->width; x++ ) {
for( y=0; y< pm->height; y++) {
pixel(pm,x,y).value = color;
}
}
}
void drawBackground()
// draw logo.png into background buffer
if (gui.logo.draw)
{
blend( images[iLogo].image, gui.screen.pixmap, gui.logo.pos);
blend( images[iLogo].image, gui.screen.pixmap, gui.logo.pos);
}
memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
void setupDeviceList(config_file_t *theme)
{
unsigned int pixel;
intalpha;// transparency level 0 (obligue) - 255 (transparent)
intalpha;// transparency level 0 (obligue) - 255 (transparent)
uint32_t color;// color value formatted RRGGBB
int val, len;
const char *string;
if(getIntForKey("devices_max_visible", &val, theme ))
if(getIntForKey("devices_max_visible", &val, theme )) {
gui.maxdevices = MIN( val, gDeviceCount );
}
if(getIntForKey("devices_iconspacing", &val, theme ))
if(getIntForKey("devices_iconspacing", &val, theme )) {
gui.devicelist.iconspacing = val;
}
// check layout for horizontal or vertical
gui.layout = HorizontalLayout;
gui.devicelist.height = ((images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing) * MIN(gui.maxdevices, gDeviceCount) + (images[iDeviceScrollPrev].image->height + images[iDeviceScrollNext].image->height) + gui.devicelist.iconspacing);
gui.devicelist.width = (images[iSelection].image->width + gui.devicelist.iconspacing);
if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , images[iSelection].image->width ) )
if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , images[iSelection].image->width ) ) {
gui.devicelist.pos.x = pixel;
}
if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , gui.devicelist.height ) )
if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , gui.devicelist.height ) ) {
gui.devicelist.pos.y = pixel;
}
break;
case HorizontalLayout:
gui.devicelist.width = ((images[iSelection].image->width + gui.devicelist.iconspacing) * MIN(gui.maxdevices, gDeviceCount) + (images[iDeviceScrollPrev].image->width + images[iDeviceScrollNext].image->width) + gui.devicelist.iconspacing);
gui.devicelist.height = (images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing);
if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , gui.devicelist.width ) )
if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , gui.devicelist.width ) ) {
gui.devicelist.pos.x = pixel;
else
} else {
gui.devicelist.pos.x = ( gui.screen.width - gui.devicelist.width ) / 2;
}
if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , images[iSelection].image->height ) )
{
gui.devicelist.pos.y = pixel;
else
} else {
gui.devicelist.pos.y = ( gui.screen.height - gui.devicelist.height ) / 2;
}
break;
}
if(getColorForKey("devices_bgcolor", &color, theme))
if(getColorForKey("devices_bgcolor", &color, theme)) {
gui.devicelist.bgcolor = (color & 0x00FFFFFF);
}
if(getIntForKey("devices_transparency", &alpha, theme))
if(getIntForKey("devices_transparency", &alpha, theme)) {
gui.devicelist.bgcolor = gui.devicelist.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
}
if (gui.devicelist.pixmap)
{
freeWindowBuffer(&gui.devicelist);
createWindowBuffer(&gui.devicelist);
}
if (gui.devicelist.pixmap) {
freeWindowBuffer(&gui.devicelist);
createWindowBuffer(&gui.devicelist);
}
}
void loadThemeValues(config_file_t *theme)
unsigned int screen_width = gui.screen.width;
unsigned int screen_height = gui.screen.height;
unsigned int pixel;
intalpha;// transparency level 0 (obligue) - 255 (transparent)
intalpha;// transparency level 0 (obligue) - 255 (transparent)
uint32_t color;// color value formatted RRGGBB
int val;
/*
* Parse screen parameters
*/
if(getColorForKey("screen_bgcolor", &color, theme ))
if(getColorForKey("screen_bgcolor", &color, theme )) {
gui.screen.bgcolor = (color & 0x00FFFFFF);
if(getIntForKey("screen_textmargin_h", &val, theme))
}
if(getIntForKey("screen_textmargin_h", &val, theme)) {
gui.screen.hborder = MIN( gui.screen.width , val );
if(getIntForKey("screen_textmargin_v", &val, theme))
}
if(getIntForKey("screen_textmargin_v", &val, theme)) {
gui.screen.vborder = MIN( gui.screen.height , val );
}
/*
* Parse background parameters
if(getDimensionForKey("background_pos_x", &pixel, theme, screen_width , images[iBackground].image->width ) )
gui.background.pos.x = pixel;
if(getDimensionForKey("background_pos_y", &pixel, theme, screen_height , images[iBackground].image->height ) )
if(getDimensionForKey("background_pos_y", &pixel, theme, screen_height , images[iBackground].image->height ) ) {
gui.background.pos.y = pixel;
}
/*
* Parse logo parameters
*/
if(getDimensionForKey("logo_pos_x", &pixel, theme, screen_width , images[iLogo].image->width ) )
if(getDimensionForKey("logo_pos_x", &pixel, theme, screen_width , images[iLogo].image->width ) ) {
gui.logo.pos.x = pixel;
}
if(getDimensionForKey("logo_pos_y", &pixel, theme, screen_height , images[iLogo].image->height ) )
{
gui.logo.pos.y = pixel;
}
/*
* Parse progress bar parameters
*/
if(getDimensionForKey("progressbar_pos_x", &pixel, theme, screen_width , 0 ) )
{
gui.progressbar.pos.x = pixel;
}
if(getDimensionForKey("progressbar_pos_y", &pixel, theme, screen_height , 0 ) )
{
gui.progressbar.pos.y = pixel;
}
/*
* Parse countdown text parameters
*/
if(getDimensionForKey("countdown_pos_x", &pixel, theme, screen_width , 0 ) )
{
gui.countdown.pos.x = pixel;
}
if(getDimensionForKey("countdown_pos_y", &pixel, theme, screen_height , 0 ) )
{
gui.countdown.pos.y = pixel;
}
/*
* Parse devicelist parameters
* Parse infobox parameters
*/
if(getIntForKey("infobox_width", &val, theme))
{
gui.infobox.width = MIN( screen_width , val );
}
if(getIntForKey("infobox_height", &val, theme))
{
gui.infobox.height = MIN( screen_height , val );
}
if(getDimensionForKey("infobox_pos_x", &pixel, theme, screen_width , gui.infobox.width ) )
{
gui.infobox.pos.x = pixel;
}
if(getDimensionForKey("infobox_pos_y", &pixel, theme, screen_height , gui.infobox.height ) )
{
gui.infobox.pos.y = pixel;
}
if(getIntForKey("infobox_textmargin_h", &val, theme))
{
gui.infobox.hborder = MIN( gui.infobox.width , val );
}
if(getIntForKey("infobox_textmargin_v", &val, theme))
{
gui.infobox.vborder = MIN( gui.infobox.height , val );
}
if(getColorForKey("infobox_bgcolor", &color, theme))
{
gui.infobox.bgcolor = (color & 0x00FFFFFF);
}
if(getIntForKey("infobox_transparency", &alpha, theme))
{
gui.infobox.bgcolor = gui.infobox.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
}
/*
* Parse menu parameters
*/
if(getDimensionForKey("menu_width", &pixel, theme, gui.screen.width , 0 ) )
{
gui.menu.width = pixel;
}
else
{
gui.menu.width = images[iMenuSelection].image->width;
}
if(getDimensionForKey("menu_height", &pixel, theme, gui.screen.height , 0 ) )
{
gui.menu.height = pixel;
}
else
{
gui.menu.height = (infoMenuItemsCount) * images[iMenuSelection].image->height;
}
if(getDimensionForKey("menu_pos_x", &pixel, theme, screen_width , gui.menu.width ) )
{
gui.menu.pos.x = pixel;
}
if(getDimensionForKey("menu_pos_y", &pixel, theme, screen_height , gui.menu.height ) )
{
gui.menu.pos.y = pixel;
}
if(getIntForKey("menu_textmargin_h", &val, theme))
{
gui.menu.hborder = MIN( gui.menu.width , val );
}
if(getIntForKey("menu_textmargin_v", &val, theme))
{
gui.menu.vborder = MIN( gui.menu.height , val );
}
if(getColorForKey("menu_bgcolor", &color, theme))
{
gui.menu.bgcolor = (color & 0x00FFFFFF);
}
if(getIntForKey("menu_transparency", &alpha, theme))
{
gui.menu.bgcolor = gui.menu.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
}
/*
* Parse bootprompt parameters
*/
if(getDimensionForKey("bootprompt_width", &pixel, theme, screen_width , 0 ) )
{
gui.bootprompt.width = pixel;
}
if(getIntForKey("bootprompt_height", &val, theme))
{
gui.bootprompt.height = MIN( screen_height , val );
}
if(getDimensionForKey("bootprompt_pos_x", &pixel, theme, screen_width , gui.bootprompt.width ) )
{
gui.bootprompt.pos.x = pixel;
}
if(getDimensionForKey("bootprompt_pos_y", &pixel, theme, screen_height , gui.bootprompt.height ) )
{
gui.bootprompt.pos.y = pixel;
}
if(getIntForKey("bootprompt_textmargin_h", &val, theme))
{
gui.bootprompt.hborder = MIN( gui.bootprompt.width , val );
}
if(getIntForKey("bootprompt_textmargin_v", &val, theme))
{
gui.bootprompt.vborder = MIN( gui.bootprompt.height , val );
}
if(getColorForKey("bootprompt_bgcolor", &color, theme))
{
gui.bootprompt.bgcolor = (color & 0x00FFFFFF);
}
if(getIntForKey("bootprompt_transparency", &alpha, theme))
{
gui.bootprompt.bgcolor = gui.bootprompt.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);
}
if(getColorForKey("font_small_color", &color, theme))
{
gui.screen.font_small_color = (color & 0x00FFFFFF);
}
if(getColorForKey("font_console_color", &color, theme))
{
gui.screen.font_console_color = (color & 0x00FFFFFF);
}
}
int initGUI(void)
sprintf(dirspec, "/Extra/Themes/%s/theme.plist", theme_name);
if (loadConfigFile(dirspec, &bootInfo->themeConfig) != 0) {
#ifdef CONFIG_EMBED_THEME
config_file_t*config;
config_file_t*config;
config = &bootInfo->themeConfig;
if (ParseXMLFile((char *)__theme_plist, &config->dictionary) != 0) {
return 1;
}
config = &bootInfo->themeConfig;
if (ParseXMLFile((char *)__theme_plist, &config->dictionary) != 0) {
return 1;
}
#else
return 1;
#endif
if (createWindowBuffer(&gui.bootprompt) == 0) {
if (createWindowBuffer(&gui.infobox) == 0) {
if (createWindowBuffer(&gui.menu) == 0) {
gui.logo.draw = true;
gui.logo.draw = true;
drawBackground();
// lets copy the screen into the back buffer
memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
{
int devicetype;
if( diskIsCDROM(device) )
if( diskIsCDROM(device) ) {
devicetype = iDeviceCDROM;// Use CDROM icon
else
{
} else {
switch (device->part_type)
{
case kPartitionTypeHFS:
break;
}
}
case kPartitionTypeHPFS:
devicetype = iDeviceNTFS;// Use HPFS / NTFS icon
break;
makeRoundedCorners( gui.devicelist.pixmap);
switch (gui.layout)
{
switch (gui.layout) {
case VerticalLayout:
p.x = (gui.devicelist.width /2);
}
// draw visible device icons
for (i = 0; i < gui.maxdevices; i++)
{
for (i = 0; i < gui.maxdevices; i++) {
BVRef param = menuItems[start + i].param;
bool isSelected = ((start + i) == selection) ? true : false;
if (isSelected)
{
if (param->flags & kBVFlagNativeBoot)
{
infoMenuNativeBoot = true;
}
else
{
infoMenuNativeBoot = false;
if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)
infoMenuSelection = 0;
}
bool isSelected = ((start + i) == selection) ? true : false;
if (isSelected) {
if (param->flags & kBVFlagNativeBoot) {
infoMenuNativeBoot = true;
} else {
infoMenuNativeBoot = false;
if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END) {
infoMenuSelection = 0;
}
}
if (gui.menu.draw)
if (gui.menu.draw) {
drawInfoMenuItems();
}
getBoolForKey(kShowInfoKey, &shoWinfo, &bootInfo->chameleonConfig);
if (shoWinfo && showBootBanner)
{
if (shoWinfo && showBootBanner) {
gui.debug.cursor = pos( 10, 100);
dprintf( &gui.screen, "label: %s\n", param->label );
dprintf( &gui.screen, "biosdev: 0x%x\n", param->biosdev );
drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);
if (gui.layout == HorizontalLayout)
{
if (gui.layout == HorizontalLayout) {
p.x += images[iSelection].image->width + gui.devicelist.iconspacing;
}
if (gui.layout == VerticalLayout)
{
if (gui.layout == VerticalLayout) {
p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing );
}
}
// draw prev indicator
if (start)
if (start) {
blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );
}
// draw next indicator
if ( end < gDeviceCount - 1 )
if ( end < gDeviceCount - 1 ) {
blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );
}
gui.redraw = true;
updateVRAM();
//prompt_pos=0;
if(gui.bootprompt.draw == true )
{
if( gui.bootprompt.draw == true ) {
gui.bootprompt.draw = false;
gui.redraw = true;
// this causes extra frames to be drawn
static inline
void vramwrite (void *data, int width, int height)
{
if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)
if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4) {
memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));
else
{
} else {
uint32_t r, g, b;
int i, j;
for (i = 0; i < VIDEO (height); i++)
for (j = 0; j < VIDEO (width); j++)
{
for (i = 0; i < VIDEO (height); i++) {
for (j = 0; j < VIDEO (width); j++) {
b = ((uint8_t *) data)[4*i*width + 4*j];
g = ((uint8_t *) data)[4*i*width + 4*j + 1];
r = ((uint8_t *) data)[4*i*width + 4*j + 2];
switch (VIDEO (depth))
{
switch (VIDEO (depth)) {
case 32:
*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
break;
break;
}
}
}
}
}
void updateVRAM()
{
if (gui.redraw)
{
if (gui.devicelist.draw)
if (gui.redraw) {
if (gui.devicelist.draw) {
blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );
if (gui.bootprompt.draw)
}
if (gui.bootprompt.draw) {
blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );
if (gui.menu.draw)
}
if (gui.menu.draw) {
blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );
if (gui.infobox.draw)
}
if (gui.infobox.draw) {
blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );
}
}
vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );
if (gui.redraw)
{
if (gui.redraw) {
memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
gui.redraw = false;
}
struct putc_info //Azi: exists on console.c & printf.c
{
char * str;
char * last_str;
char * str;
char * last_str;
};
static int
sputc(int c, struct putc_info * pi) //Azi: same as above
{
if (pi->last_str)
if (pi->str == pi->last_str) {
*(pi->str) = '\0';
return 0;
}
*(pi->str)++ = c;
return c;
if (pi->last_str) {
if (pi->str == pi->last_str) {
*(pi->str) = '\0';
return 0;
}
}
*(pi->str)++ = c;
return c;
}
int gprintf( window_t * window, const char * fmt, ...)
font_t *font = &font_console;
for( i=0; i< strlen(formattedtext); i++ )
{
for( i=0; i< strlen(formattedtext); i++ ) {
character = formattedtext[i];
character -= 32;
// newline ?
if( formattedtext[i] == '\n' )
{
if( formattedtext[i] == '\n' ) {
cursor.x = window->hborder;
cursor.y += font->height;
if ( cursor.y > bounds.y )
if ( cursor.y > bounds.y ) {
cursor.y = origin.y;
}
continue;
}
// tab ?
if( formattedtext[i] == '\t' )
if( formattedtext[i] == '\t' ) {
cursor.x += ( font->chars[0]->width * 5 );
}
// draw the character
if( font->chars[character])
if( font->chars[character]) {
blend(font->chars[character], window->pixmap, cursor);
}
cursor.x += font->chars[character]->width;
// check x pos and do newline
if ( cursor.x > bounds.x )
{
if ( cursor.x > bounds.x ) {
cursor.x = origin.x;
cursor.y += font->height;
}
// check y pos and reset to origin.y
if ( cursor.y > bounds.y )
if ( cursor.y > bounds.y ) {
cursor.y = origin.y;
}
}
// update cursor postition
free(formattedtext);
return 0;
}
return 1;
}
font_t *font = &font_console;
for( i=0; i< strlen(formattedtext); i++ )
{
for( i=0; i< strlen(formattedtext); i++ ) {
character = formattedtext[i];
character -= 32;
// newline ?
if( formattedtext[i] == '\n' )
{
if( formattedtext[i] == '\n' ) {
cursor.x = window->hborder;
cursor.y += font->height;
if ( cursor.y > bounds.y )
if ( cursor.y > bounds.y ) {
cursor.y = origin.y;
}
continue;
}
// tab ?
if( formattedtext[i] == '\t' )
if( formattedtext[i] == '\t' ) {
cursor.x += ( font->chars[0]->width * 5 );
}
// draw the character
if( font->chars[character])
if( font->chars[character]) {
blend(font->chars[character], gui.backbuffer, cursor);
}
cursor.x += font->chars[character]->width;
// check x pos and do newline
if ( cursor.x > bounds.x )
{
if ( cursor.x > bounds.x ) {
cursor.x = origin.x;
cursor.y += font->height;
}
// check y pos and reset to origin.y
if ( cursor.y > bounds.y )
if ( cursor.y > bounds.y ) {
cursor.y = origin.y;
}
}
// update cursor postition
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;
// newline ?
if( formattedtext[i] == '\n' )
{
if( formattedtext[i] == '\n' ) {
cursor.x = window->hborder;
cursor.y += font->height;
if ( cursor.y > bounds.y )
{
if ( cursor.y > bounds.y ) {
gui.redraw = true;
updateVRAM();
cursor.y = window->vborder;
}
// tab ?
if( formattedtext[i] == '\t' )
{
if( formattedtext[i] == '\t' ) {
cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );
continue;
}
cursor.x += font->chars[character]->width;
// check x pos and do newline
if ( cursor.x > bounds.x )
{
if ( cursor.x > bounds.x ) {
cursor.x = origin.x;
cursor.y += font->height;
}
// check y pos and reset to origin.y
if ( cursor.y > ( bounds.y + font->chars[0]->height) )
{
if ( cursor.y > ( bounds.y + font->chars[0]->height) ) {
gui.redraw = true;
updateVRAM();
cursor.y = window->vborder;
}
// draw the character
if( font->chars[character])
if( font->chars[character]) {
blend(font->chars[character], gui.backbuffer, cursor);
}
}
// save cursor postition
window->cursor.x = cursor.x;
pixmap_t* charToPixmap(unsigned char ch, font_t *font) {
unsigned int cha = (unsigned int)ch - 32;
if (cha >= font->count)
if (cha >= font->count) {
// return ? if the font for the char doesn't exists
cha = '?' - 32;
}
return font->chars[cha] ? font->chars[cha] : NULL;
}
position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p) {
pixmap_t* pm = charToPixmap(ch, font);
if (pm && ((p.x + pm->width) < blendInto->width))
{
if (pm && ((p.x + pm->width) < blendInto->width)) {
blend(pm, blendInto, p);
return pos(p.x + pm->width, p.y);
}
else
} else {
return p;
}
}
void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)
int i=0;
position_t current_pos = pos(p.x, p.y);
for (i=0; i < strlen(ch); i++)
{
for (i=0; i < strlen(ch); i++) {
// newline ?
if ( ch[i] == '\n' )
{
if ( ch[i] == '\n' ) {
current_pos.x = p.x;
current_pos.y += font->height;
continue;
}
// tab ?
if ( ch[i] == '\t' )
{
if ( ch[i] == '\t' ) {
current_pos.x += TAB_PIXELS_WIDTH;
continue;
}
// calculate the width in pixels
for (i=0; i < strlen(text); i++) {
if (text[i] == '\n')
{
if (text[i] == '\n') {
width = 0;
height += font->height;
}
else if (text[i] == '\t')
} else if (text[i] == '\t') {
width += TAB_PIXELS_WIDTH;
else
{
} else {
pixmap_t* pm = charToPixmap(text[i], font);
if (pm)
if (pm){
width += pm->width;
}
}
if (width > max_width)
if (width > max_width) {
max_width = width;
}
}
p.x = ( p.x - ( max_width / 2 ) );
int destroyFont(font_t *font)
{
int i;
for (i = 0; i < CHARACTERS_COUNT; i++)
{
if (font->chars[i])
{
if (font->chars[i]->pixels) free (font->chars[i]->pixels);
free (font->chars[i]);
font->chars[i] = 0;
}
}
return 0;
int i;
for (i = 0; i < CHARACTERS_COUNT; i++) {
if (font->chars[i]) {
if (font->chars[i]->pixels) {
free (font->chars[i]->pixels);
}
free (font->chars[i]);
font->chars[i] = 0;
}
}
return 0;
}
int initFont(font_t *font, image_t *data)
font->height = data->image->height;
for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++)
{
for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++) {
start = end;
// if the pixel is red we've reached the end of the char
if( pixel( data->image, x, 0 ).value == 0xFFFF0000)
{
if( pixel( data->image, x, 0 ).value == 0xFFFF0000) {
end = x + 1;
if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )
{
if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) ) {
font->chars[count]->width = ( end - start) - 1;
font->chars[count]->height = font->height;
if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )
{
if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) ) {
space += ( font->chars[count]->width * data->image->height * 4 );
// we skip the first line because there are just the red pixels for the char width
for( y = 1; y< (font->height); y++)
{
for( x2 = start, x3 = 0; x2 < end; x2++, x3++)
{
for( y = 1; y< (font->height); y++) {
for( x2 = start, x3 = 0; x2 < end; x2++, x3++) {
pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );
}
}
// check if font is monospaced
if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )
if( ( count > 0 ) && ( font->width != font->chars[count]->width ) ) {
monospaced = true;
}
font->width = font->chars[count]->width;
}
}
for (x = count; x < CHARACTERS_COUNT; x++)
for (x = count; x < CHARACTERS_COUNT; x++) {
font->chars[x] = NULL;
}
if(monospaced)
if(monospaced) {
font->width = 0;
}
font->count = count;
void colorFont(font_t *font, uint32_t color)
{
if( !color )
if( !color ) {
return;
}
int x, y, width, height;
int count = 0;
pixel_t *buff;
while( font->chars[count++] )
{
while( font->chars[count++] ) {
width = font->chars[count-1]->width;
height = font->chars[count-1]->height;
for( y = 0; y < height; y++ )
{
for( x = 0; x < width; x++ )
{
for( y = 0; y < height; y++ ) {
for( x = 0; x < width; x++ ) {
buff = &(pixel( font->chars[count-1], x, y ));
if( buff->ch.a )
{
if( buff->ch.a ) {
buff->ch.r = (color & 0xFFFF0000) >> 16;
buff->ch.g = (color & 0xFF00FF00) >> 8;
buff->ch.b = (color & 0xFF0000FF);
uint8_t alpha=0;
for( y=0; y<10; y++)
{
for( x=0; x<10; x++)
{
for( y=0; y<10; y++) {
for( x=0; x<10; x++) {
// skip if the pixel should be visible
if(roundedCorner[y][x] != 0xFF)
{
if(roundedCorner[y][x] != 0xFF){
alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );
// Upper left corner
pixel(p, x, y).ch.a = alpha;
int cnt=0;
int offset=0;
if( !title || !text_orig )
if( !title || !text_orig ) {
return;
}
// Create a copy so that we don't mangle the original
text = malloc(strlen(text_orig) + 1);
strcpy(text, text_orig);
position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );
// calculate number of lines in the title
for ( i = 0, lines = 1; i<strlen(title); i++ )
if( title[i] == '\n')
for ( i = 0, lines = 1; i<strlen(title); i++ ) {
if( title[i] == '\n') {
lines++;
}
}
// y position of text is lines in title * height of font
position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));
// calculate number of lines in the text
for ( i=0, lines = 1; i<strlen(text); i++ )
if( text[i] == '\n')
for ( i=0, lines = 1; i<strlen(text); i++ ) {
if( text[i] == '\n') {
lines++;
}
}
// if text ends with \n strip off
if( text[i] == '\n' || text[i] == '\0')
if( text[i] == '\n' || text[i] == '\0') {
lines--;
}
visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;
// lets display the text and allow scroll thru using up down / arrows
while(1)
{
while(1) {
// move to current line in text
for( offset = 0, i = 0; offset < strlen(text); offset++ )
{
if( currentline == i)
for( offset = 0, i = 0; offset < strlen(text); offset++ ) {
if( currentline == i) {
break;
if( text[offset] =='\n')
}
if( text[offset] =='\n') {
i++;
}
}
// find last visible line in text and place \0
for( i = offset, cnt = 0; i < strlen(text); i++)
{
if(text[i]=='\n')
for( i = offset, cnt = 0; i < strlen(text); i++) {
if(text[i]=='\n') {
cnt++;
if ( cnt == visiblelines )
{
}
if ( cnt == visiblelines ) {
text[i]='\0';
break;
}
makeRoundedCorners( gui.infobox.pixmap);
// print the title if present
if( title )
if( title ) {
drawStr(title, &font_console, gui.infobox.pixmap, pos_title);
}
// print the text
drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);
// restore \n in text
if ( cnt == visiblelines )
if ( cnt == visiblelines ) {
text[i] = '\n';
}
position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );
// draw prev indicator
if(offset)
{
if(offset) {
blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));
}
// draw next indicator
if( lines > ( currentline + visiblelines ) )
{
if( lines > ( currentline + visiblelines ) ) {
pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );
blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );
}
key = getchar();
if( key == KEY_UP )
if( currentline > 0 )
if( key == KEY_UP ) {
if( currentline > 0 ) {
currentline--;
}
}
if( key == KEY_DOWN )
if( lines > ( currentline + visiblelines ) )
if( key == KEY_DOWN ) {
if( lines > ( currentline + visiblelines ) ) {
currentline++;
}
}
if( key == KEY_ESC || key == 'q' || key == 'Q')
{
if( key == KEY_ESC || key == 'q' || key == 'Q') {
gui.infobox.draw = false;
gui.redraw = true;
updateVRAM();
break;
}
if(key == ' ') // spacebar = next page
{
if( lines > ( currentline + visiblelines ) )
if(key == ' ') { // spacebar = next page
if( lines > ( currentline + visiblelines ) ) {
currentline += visiblelines;
if(lines < (currentline + visiblelines))
}
if(lines < (currentline + visiblelines)) {
currentline = lines - visiblelines;
}
}
}
free(text);
{
int y;
if( time18() > lasttime)
{
if( time18() > lasttime) {
lasttime = time18();
pixmap_t *buffBar = images[iProgressBar].image;
memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );
for( y = buffBar->height - 1; y > 0; y--)
for( y = buffBar->height - 1; y > 0; y--) {
pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);
}
pixel(buffBar, buffBar->width-1, 0).value = buff;
}
}
void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)
{
if(progress>100)
if(progress>100) {
return;
}
p.x = ( p.x - ( width / 2 ) );
int todraw = (width * progress) / 100;
pixmap_t *buff = images[iProgressBar].image;
pixmap_t *buffBG = images[iProgressBarBackground].image;
if(!buff || !buffBG)
if(!buff || !buffBG) {
return;
}
pixmap_t progressbar;
progressbar.pixels=malloc(width * 4 * buff->height);
if(!progressbar.pixels)
if(!progressbar.pixels) {
return;
}
progressbar.width = width;
progressbar.height = buff->height;
int x=0,x2=0,y=0;
for(y=0; y<buff->height; y++)
{
for(x=0; x<todraw; x++, x2++)
{
if(x2 == (buff->width-1)) x2=0;
for(y=0; y<buff->height; y++) {
for(x=0; x<todraw; x++, x2++) {
if(x2 == (buff->width-1)) {
x2=0;
}
pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;
}
x2=0;
}
for(y=0; y<buff->height; y++)
{
for(x=todraw, x2 = 0; x < width - 1; x++, x2++)
{
if(x2 == (buffBG->width -2 )) x2 = 0;
for(y=0; y<buff->height; y++) {
for(x=todraw, x2 = 0; x < width - 1; x++, x2++) {
if(x2 == (buffBG->width -2 )) {
x2 = 0;
}
pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;
}
if(progress < 100)
if(progress < 100) {
pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;
if(progress == 0)
}
if(progress == 0) {
pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;
}
x2=0;
}
position = pos(0,0);
for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++)
{
if (i == infoMenuSelection)
{
for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++) {
if (i == infoMenuSelection) {
blend(selection, gui.menu.pixmap, position);
}
pbuff = images[n].image;
if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)
{
if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END) {
blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap,
pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
}
else
{
} else {
blend( pbuff, gui.menu.pixmap,
pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
}
{
case KEY_UP:// up arrow
if (infoMenuSelection > 0)
{
if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)
{
if (infoMenuSelection > 0) {
if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1) {
infoMenuSelection -= 4;
}
else
{
} else {
infoMenuSelection--;
}
drawInfoMenuItems();
updateVRAM();
}
else
{
} else {
gui.menu.draw = false;
gui.redraw = true;
break;
case KEY_DOWN:// down arrow
if (infoMenuSelection < infoMenuItemsCount - 1)
{
if (infoMenuSelection < infoMenuItemsCount - 1) {
if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)
{
infoMenuSelection += 4;
else
} else {
infoMenuSelection++;
}
drawInfoMenuItems();
updateVRAM();
}
case KEY_ENTER:
key = 0;
if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )
if( infoMenuSelection == MENU_SHOW_MEMORY_INFO ) {
showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());
else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )
} else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO ) {
showInfoBox( getVBEInfoString(), getVBEModeInfoString() );
else if( infoMenuSelection == MENU_SHOW_HELP )
} else if( infoMenuSelection == MENU_SHOW_HELP ) {
showHelp();
else
{
} else {
int buff = infoMenuSelection;
infoMenuSelection = 0;
return buff;
sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);
if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {
#ifdef CONFIG_EMBED_THEME
if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)
if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)
#endif
usePngImage = false;
}
screen_params[1] = DEFAULT_SCREEN_HEIGHT;
}
// Save current screen resolution.
// Save current screen resolution.
oldScreenWidth = gui.screen.width;
oldScreenHeight = gui.screen.height;
// find best matching vesa mode for our requested width & height
getGraphicModeParams(screen_params);
// Set graphics mode if the booter was in text mode or the screen resolution has changed.
if (bootArgs->Video.v_display == VGA_TEXT_MODE
|| (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) )
{
// Set graphics mode if the booter was in text mode or the screen resolution has changed.
if (bootArgs->Video.v_display == VGA_TEXT_MODE || (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) ) {
setVideoMode(GRAPHICS_MODE, 0);
}
trunk/i386/boot2/gui.h
6464
6565
6666
67
67
6868
6969
7070
uint16_theight;// Font Height
uint16_twidth;// Font Width for monospace font only
pixmap_t*chars[CHARACTERS_COUNT];
uint16_t count; // Number of chars in font
uint16_tcount;// Number of chars in font
} font_t;
/*
trunk/i386/boot2/options.c
189189
190190
191191
192
193192
194193
195194
......
228227
229228
230229
231
230
232231
233232
234233
......
254253
255254
256255
257
258
256
257
258
259
259260
260261
261262
......
11261127
11271128
11281129
1129
1130
1131
1132
1133
1130
1131
1132
1133
11341134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
11481149
11491150
11501151
......
11531154
11541155
11551156
1156
1157
1158
1159
1160
1161
1162
1163
1164
1157
1158
1159
1160
1161
1162
1163
1164
1165
11651166
1166
1167
11671168
1168
1169
11691170
1170
1171
11711172
1172
1173
1174
1175
1176
1177
1173
1174
1175
1176
1177
1178
1179
11781180
1179
1180
1181
1182
1181
1182
11831183
1184
1185
1184
1185
11861186
1187
1188
1187
11891188
1190
1189
1190
1191
1192
1193
1194
11911195
1192
1193
1194
1195
1196
1196
11971197
1198
1198
1199
1200
1201
11991202
1200
1201
1202
1203
1203
1204
12041205
1205
1206
1206
1207
12071208
1208
1209
1209
1210
1211
1212
1213
1214
12101215
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
12281226
12291227
12301228
12311229
1232
1233
1230
1231
12341232
12351233
1236
1234
12371235
1238
1239
1240
1241
1242
1236
1237
1238
1239
1240
12431241
1244
1242
12451243
12461244
1247
1248
1249
1250
1251
1245
1246
1247
1248
12521249
1253
1254
1250
12551251
1256
1252
12571253
1254
12581255
1259
1256
12601257
1261
1262
1258
1259
12631260
1261
12641262
12651263
1266
1264
12671265
1266
12681267
12691268
1270
1269
12711270
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
12941293
1295
1296
1297
1298
1294
1295
1296
1297
12991298
1300
1301
1302
1303
1299
1300
1301
1302
13041303
1305
1304
13061305
1307
1308
1309
1310
1306
1307
1308
1309
13111310
1312
1311
13131312
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
13311330
1332
1333
1331
13341332
13351333
13361334
13371335
13381336
13391337
1340
1341
1342
1338
1339
1340
13431341
13441342
1345
1343
13461344
1347
1345
13481346
1347
13491348
1350
1351
1349
1350
13521351
1353
1352
13541353
13551354
13561355
......
13691368
13701369
13711370
1371
1372
1373
1374
13721375
1373
1374
1375
1376
13771376
13781377
13791378
if (bootArgs->Video.v_display != VGA_TEXT_MODE) {
clearGraphicBootPrompt();
}
execute_hook("ClearArgs", NULL, NULL, NULL, NULL);
}
}
} else {
if (bootArgs->Video.v_display != VGA_TEXT_MODE) {
clearGraphicBootPrompt();
clearGraphicBootPrompt();
} else {
printf("Press Enter to start up the foreign OS. ");
}
{
x = 80; y--;
}
if (x) x--;
if (x) {
x--;
}
if( bootArgs->Video.v_display == VGA_TEXT_MODE )
{
setCursorPosition( x, y, 0 );
int *cntRemainingP, // Output count
char *foundVal, // found value
int foundValSize // max found value size
)
{
const char *val;
int cnt;
bool found = false;
) {
const char *val;
int cnt;
bool found = false;
if (getValueForBootKey(userString, argName, &val, &cnt)) {
// Don't copy; these values will be copied at the end of argument processing.
found = true;
} else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) {
// Don't copy; these values will be copied at the end of argument processing.
found = true;
} else if (getValueForKey(argName, &val, &cnt, &bootInfo->chameleonConfig)) {
copyArgument(argName, val, cnt, argP, cntRemainingP);
found = true;
}
if (found && foundVal)
strlcpy(foundVal, val, foundValSize);
return found;
if (getValueForBootKey(userString, argName, &val, &cnt)) {
// Don't copy; these values will be copied at the end of argument processing.
found = true;
} else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) {
// Don't copy; these values will be copied at the end of argument processing.
found = true;
} else if (getValueForKey(argName, &val, &cnt, &bootInfo->chameleonConfig)) {
copyArgument(argName, val, cnt, argP, cntRemainingP);
found = true;
}
if (found && foundVal) {
strlcpy(foundVal, val, foundValSize);
}
return found;
}
// Maximum config table value size
int
processBootOptions()
{
const char *cp = gBootArgs;
const char *val = 0;
const char *kernel;
int cnt;
int userCnt;
int cntRemaining;
char *argP;
char *configKernelFlags;
char *valueBuffer;
const char *cp = gBootArgs;
const char *val = 0;
const char *kernel;
int cnt;
int userCnt;
int cntRemaining;
char *argP;
char *configKernelFlags;
char *valueBuffer;
valueBuffer = malloc(VALUE_SIZE);
valueBuffer = malloc(VALUE_SIZE);
skipblanks( &cp );
skipblanks( &cp );
// Update the unit and partition number.
// Update the unit and partition number.
if ( gBootVolume )
{
if (!( gBootVolume->flags & kBVFlagNativeBoot ))
{
readBootSector( gBootVolume->biosdev, gBootVolume->part_boff,
(void *) 0x7c00 );
if ( gBootVolume ) {
if (!( gBootVolume->flags & kBVFlagNativeBoot )) {
readBootSector( gBootVolume->biosdev, gBootVolume->part_boff, (void *) 0x7c00 );
//
// Setup edx, and signal intention to chain load the
// foreign booter.
//
//
// Setup edx, and signal intention to chain load the
// foreign booter.
//
chainbootdev = gBootVolume->biosdev;
chainbootflag = 1;
chainbootdev = gBootVolume->biosdev;
chainbootflag = 1;
return 1;
}
return 1;
}
setRootVolume(gBootVolume);
setRootVolume(gBootVolume);
}
// If no boot volume fail immediately because we're just going to fail
// trying to load the config file anyway.
else {
return -1;
}
}
// If no boot volume fail immediately because we're just going to fail
// trying to load the config file anyway.
else
return -1;
// Load config table specified by the user, or use the default.
// Load config table specified by the user, or use the default.
if (!getValueForBootKey(cp, "config", &val, &cnt)) {
val = 0;
cnt = 0;
}
if (!getValueForBootKey(cp, "config", &val, &cnt)) {
val = 0;
cnt = 0;
}
// Load com.apple.Boot.plist from the selected volume
// and use its contents to override default bootConfig.
// Load com.apple.Boot.plist from the selected volume
// and use its contents to override default bootConfig.
loadSystemConfig(&bootInfo->bootConfig);
loadChameleonConfig(&bootInfo->chameleonConfig);
loadSystemConfig(&bootInfo->bootConfig);
loadChameleonConfig(&bootInfo->chameleonConfig);
// Use the kernel name specified by the user, or fetch the name
// in the config table, or use the default if not specified.
// Specifying a kernel name on the command line, or specifying
// a non-default kernel name in the config file counts as
// overriding the kernel, which causes the kernelcache not
// to be used.
// Use the kernel name specified by the user, or fetch the name
// in the config table, or use the default if not specified.
// Specifying a kernel name on the command line, or specifying
// a non-default kernel name in the config file counts as
// overriding the kernel, which causes the kernelcache not
// to be used.
gOverrideKernel = false;
if (( kernel = extractKernelName((char **)&cp) )) {
strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile) );
} else {
if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) {
strlcpy( bootInfo->bootFile, val, cnt+1 );
} else {
strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) );
}
}
gOverrideKernel = false;
if (( kernel = extractKernelName((char **)&cp) )) {
strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile) );
} else {
if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) {
strlcpy( bootInfo->bootFile, val, cnt+1 );
} else {
strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) );
}
}
if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) {
gOverrideKernel = true;
}
cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space
argP = bootArgs->CommandLine;
cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space
argP = bootArgs->CommandLine;
// Get config kernel flags, if not ignored.
if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) ||
if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) ||
!getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig )) {
val = "";
cnt = 0;
}
configKernelFlags = malloc(cnt + 1);
strlcpy(configKernelFlags, val, cnt + 1);
val = "";
cnt = 0;
}
configKernelFlags = malloc(cnt + 1);
strlcpy(configKernelFlags, val, cnt + 1);
// boot-uuid can be set either on the command-line or in the config file
// boot-uuid can be set either on the command-line or in the config file
if (!processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config,
&argP, &cntRemaining, gBootUUIDString, sizeof(gBootUUIDString))) {
//
// Try an alternate method for getting the root UUID on boot helper partitions.
//
if (gBootVolume->flags & kBVFlagBooter)
{
//
// Try an alternate method for getting the root UUID on boot helper partitions.
//
if (gBootVolume->flags & kBVFlagBooter) {
// Load the configuration store in the boot helper partition
if (loadHelperConfig(&bootInfo->helperConfig) == 0)
{
if (loadHelperConfig(&bootInfo->helperConfig) == 0) {
val = getStringForKey(kHelperRootUUIDKey, &bootInfo->helperConfig);
if (val != NULL)
if (val != NULL) {
strlcpy(gBootUUIDString, val, sizeof(gBootUUIDString));
}
}
}
}
// Try to get the volume uuid string
if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid)
// Try to get the volume uuid string
if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid) {
gBootVolume->fs_getuuid(gBootVolume, gBootUUIDString);
}
// If we have the volume uuid add it to the commandline arguments
if (strlen(gBootUUIDString))
if (strlen(gBootUUIDString)) {
copyArgument(kBootUUIDKey, gBootUUIDString, strlen(gBootUUIDString), &argP, &cntRemaining);
}
}
if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config,
if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config,
&argP, &cntRemaining, gRootDevice, ROOT_DEVICE_SIZE)) {
cnt = 0;
if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->chameleonConfig)) {
valueBuffer[0] = '*';
cnt++;
strlcpy(valueBuffer + 1, val, cnt);
val = valueBuffer;
} else {
if (strlen(gBootUUIDString)) {
val = "*uuid";
cnt = 5;
} else {
// Don't set "rd=.." if there is no boot device key
// and no UUID.
val = "";
cnt = 0;
}
}
if (cnt > 0) {
copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining);
}
strlcpy( gRootDevice, val, (cnt + 1));
}
cnt = 0;
if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->chameleonConfig)) {
valueBuffer[0] = '*';
cnt++;
strlcpy(valueBuffer + 1, val, cnt);
val = valueBuffer;
} else {