From 8be739c0d895e71cf9b736e6590f5f549634bc31 Mon Sep 17 00:00:00 2001 From: Apple Date: Thu, 28 Apr 2005 20:17:19 +0000 Subject: [PATCH] BootX-74.1.tar.gz --- APPLE_LICENSE | 372 ++++++++++ Makefile.postamble | 1 + Makefile.preamble | 3 - bootx.tproj/Makefile | 2 +- bootx.tproj/Makefile.postamble | 4 +- bootx.tproj/Makefile.preamble | 3 +- bootx.tproj/ci.subproj/Control2.c | 23 +- bootx.tproj/ci.subproj/MAC-PARTS.c | 23 +- bootx.tproj/ci.subproj/ci.c | 43 +- bootx.tproj/ci.subproj/ci_io.c | 33 +- bootx.tproj/ci.subproj/sl_words.c | 23 +- bootx.tproj/fs.subproj/CaseTables.h | 23 +- bootx.tproj/fs.subproj/HFSCompare.c | 23 +- bootx.tproj/fs.subproj/Makefile | 2 +- bootx.tproj/fs.subproj/cache.c | 25 +- bootx.tproj/fs.subproj/ext2fs.c | 49 +- bootx.tproj/fs.subproj/ext2fs.h | 23 +- bootx.tproj/fs.subproj/ext2fs_bswap.c | 23 +- bootx.tproj/fs.subproj/ext2fs_dinode.h | 23 +- bootx.tproj/fs.subproj/ext2fs_dir.h | 23 +- bootx.tproj/fs.subproj/fs.c | 163 ++++- bootx.tproj/fs.subproj/hfs.c | 105 ++- bootx.tproj/fs.subproj/md5c.c | 342 +++++++++ bootx.tproj/fs.subproj/net.c | 23 +- bootx.tproj/fs.subproj/ufs.c | 111 ++- bootx.tproj/fs.subproj/ufs_byteorder.c | 23 +- bootx.tproj/fs.subproj/ufs_byteorder.h | 23 +- bootx.tproj/include.subproj/boot_args.h | 23 +- bootx.tproj/include.subproj/ci.h | 23 +- bootx.tproj/include.subproj/device_tree.h | 23 +- bootx.tproj/include.subproj/fs.h | 37 +- bootx.tproj/include.subproj/libclite.h | 30 +- bootx.tproj/include.subproj/sl.h | 92 ++- bootx.tproj/include.subproj/sl_words.h | 23 +- bootx.tproj/libclite.subproj/bsearch.c | 23 +- bootx.tproj/libclite.subproj/bswap.c | 23 +- bootx.tproj/libclite.subproj/mem.c | 40 +- bootx.tproj/libclite.subproj/prf.c | 23 +- bootx.tproj/libclite.subproj/printf.c | 23 +- bootx.tproj/libclite.subproj/sprintf.c | 27 +- bootx.tproj/libclite.subproj/string.c | 50 +- bootx.tproj/libclite.subproj/strtol.c | 94 ++- bootx.tproj/libclite.subproj/zalloc.c | 25 +- bootx.tproj/sl.subproj/Makefile | 4 +- bootx.tproj/sl.subproj/Makefile.postamble | 2 + bootx.tproj/sl.subproj/aes.h | 175 +++++ bootx.tproj/sl.subproj/aescrypt.c | 407 +++++++++++ bootx.tproj/sl.subproj/aeskey.c | 455 ++++++++++++ bootx.tproj/sl.subproj/aesopt.h | 753 +++++++++++++++++++ bootx.tproj/sl.subproj/aestab.c | 384 ++++++++++ bootx.tproj/sl.subproj/aestab.h | 175 +++++ bootx.tproj/sl.subproj/appleboot.h | 23 +- bootx.tproj/sl.subproj/bmdecompress.c | 256 +++++++ bootx.tproj/sl.subproj/clut.h | 23 +- bootx.tproj/sl.subproj/device_tree.c | 23 +- bootx.tproj/sl.subproj/display.c | 71 +- bootx.tproj/sl.subproj/drivers.c | 737 +------------------ bootx.tproj/sl.subproj/elf.c | 23 +- bootx.tproj/sl.subproj/elf.h | 23 +- bootx.tproj/sl.subproj/failedboot.h | 23 +- bootx.tproj/sl.subproj/lzss.c | 23 +- bootx.tproj/sl.subproj/macho.c | 27 +- bootx.tproj/sl.subproj/main.c | 378 ++++++---- bootx.tproj/sl.subproj/netboot.h | 23 +- bootx.tproj/sl.subproj/plist.c | 840 +++++++++++++++++++++ bootx.tproj/sl.subproj/raid.c | 841 ++++++++++++++++++++++ dpkg/control | 5 + fcode-to-c.tproj/fcode-to-c.c | 23 +- macho-to-xcoff.tproj/macho-to-xcoff.c | 23 +- 69 files changed, 6302 insertions(+), 1551 deletions(-) create mode 100644 APPLE_LICENSE create mode 100644 bootx.tproj/fs.subproj/md5c.c create mode 100755 bootx.tproj/sl.subproj/aes.h create mode 100755 bootx.tproj/sl.subproj/aescrypt.c create mode 100755 bootx.tproj/sl.subproj/aeskey.c create mode 100755 bootx.tproj/sl.subproj/aesopt.h create mode 100755 bootx.tproj/sl.subproj/aestab.c create mode 100755 bootx.tproj/sl.subproj/aestab.h create mode 100644 bootx.tproj/sl.subproj/bmdecompress.c create mode 100644 bootx.tproj/sl.subproj/plist.c create mode 100644 bootx.tproj/sl.subproj/raid.c create mode 100644 dpkg/control diff --git a/APPLE_LICENSE b/APPLE_LICENSE new file mode 100644 index 0000000..a0a8416 --- /dev/null +++ b/APPLE_LICENSE @@ -0,0 +1,372 @@ +APPLE PUBLIC SOURCE LICENSE +Version 1.1 - April 19,1999 + +Please read this License carefully before downloading this software. +By downloading and using this software, you are agreeing to be bound +by the terms of this License. If you do not or cannot agree to the +terms of this License, please do not download or use the software. + +1. General; Definitions. This License applies to any program or other +work which Apple Computer, Inc. ("Apple") publicly announces as +subject to this Apple Public Source License and which contains a +notice placed by Apple identifying such program or work as "Original +Code" and stating that it is subject to the terms of this Apple Public +Source License version 1.1 (or subsequent version thereof), as it may +be revised from time to time by Apple ("License"). As used in this +License: + +1.1 "Affected Original Code" means only those specific portions of +Original Code that allegedly infringe upon any party's intellectual +property rights or are otherwise the subject of a claim of +infringement. + +1.2 "Applicable Patent Rights" mean: (a) in the case where Apple is +the grantor of rights, (i) claims of patents that are now or hereafter +acquired, owned by or assigned to Apple and (ii) that cover subject +matter contained in the Original Code, but only to the extent +necessary to use, reproduce and/or distribute the Original Code +without infringement; and (b) in the case where You are the grantor of +rights, (i) claims of patents that are now or hereafter acquired, +owned by or assigned to You and (ii) that cover subject matter in Your +Modifications, taken alone or in combination with Original Code. + +1.3 "Covered Code" means the Original Code, Modifications, the +combination of Original Code and any Modifications, and/or any +respective portions thereof. + +1.4 "Deploy" means to use, sublicense or distribute Covered Code other +than for Your internal research and development (R&D), and includes +without limitation, any and all internal use or distribution of +Covered Code within Your business or organization except for R&D use, +as well as direct or indirect sublicensing or distribution of Covered +Code by You to any third party in any form or manner. + +1.5 "Larger Work" means a work which combines Covered Code or portions +thereof with code not governed by the terms of this License. + +1.6 "Modifications" mean any addition to, deletion from, and/or change +to, the substance and/or structure of Covered Code. When code is +released as a series of files, a Modification is: (a) any addition to +or deletion from the contents of a file containing Covered Code; +and/or (b) any new file or other representation of computer program +statements that contains any part of Covered Code. + +1.7 "Original Code" means (a) the Source Code of a program or other +work as originally made available by Apple under this License, +including the Source Code of any updates or upgrades to such programs +or works made available by Apple under this License, and that has been +expressly identified by Apple as such in the header file(s) of such +work; and (b) the object code compiled from such Source Code and +originally made available by Apple under this License. + +1.8 "Source Code" means the human readable form of a program or other +work that is suitable for making modifications to it, including all +modules it contains, plus any associated interface definition files, +scripts used to control compilation and installation of an executable +(object code). + +1.9 "You" or "Your" means an individual or a legal entity exercising +rights under this License. For legal entities, "You" or "Your" +includes any entity which controls, is controlled by, or is under +common control with, You, where "control" means (a) the power, direct +or indirect, to cause the direction or management of such entity, +whether by contract or otherwise, or (b) ownership of fifty percent +(50%) or more of the outstanding shares or beneficial ownership of +such entity. + +2. Permitted Uses; Conditions & Restrictions. Subject to the terms +and conditions of this License, Apple hereby grants You, effective on +the date You accept this License and download the Original Code, a +world-wide, royalty-free, non- exclusive license, to the extent of +Apple's Applicable Patent Rights and copyrights covering the Original +Code, to do the following: + +2.1 You may use, copy, modify and distribute Original Code, with or +without Modifications, solely for Your internal research and +development, provided that You must in each instance: + +(a) retain and reproduce in all copies of Original Code the copyright +and other proprietary notices and disclaimers of Apple as they appear +in the Original Code, and keep intact all notices in the Original Code +that refer to this License; + +(b) include a copy of this License with every copy of Source Code of +Covered Code and documentation You distribute, and You may not offer +or impose any terms on such Source Code that alter or restrict this +License or the recipients' rights hereunder, except as permitted under +Section 6; and + +(c) completely and accurately document all Modifications that you have +made and the date of each such Modification, designate the version of +the Original Code you used, prominently include a file carrying such +information with the Modifications, and duplicate the notice in +Exhibit A in each file of the Source Code of all such Modifications. + +2.2 You may Deploy Covered Code, provided that You must in each + instance: + +(a) satisfy all the conditions of Section 2.1 with respect to the +Source Code of the Covered Code; + +(b) make all Your Deployed Modifications publicly available in Source +Code form via electronic distribution (e.g. download from a web site) +under the terms of this License and subject to the license grants set +forth in Section 3 below, and any additional terms You may choose to +offer under Section 6. You must continue to make the Source Code of +Your Deployed Modifications available for as long as you Deploy the +Covered Code or twelve (12) months from the date of initial +Deployment, whichever is longer; + +(c) if You Deploy Covered Code containing Modifications made by You, +inform others of how to obtain those Modifications by filling out and +submitting the information found at +http://www.apple.com/publicsource/modifications.html, if available; +and + +(d) if You Deploy Covered Code in object code, executable form only, +include a prominent notice, in the code itself as well as in related +documentation, stating that Source Code of the Covered Code is +available under the terms of this License with information on how and +where to obtain such Source Code. + +3. Your Grants. In consideration of, and as a condition to, the +licenses granted to You under this License: + +(a) You hereby grant to Apple and all third parties a non-exclusive, +royalty-free license, under Your Applicable Patent Rights and other +intellectual property rights owned or controlled by You, to use, +reproduce, modify, distribute and Deploy Your Modifications of the +same scope and extent as Apple's licenses under Sections 2.1 and 2.2; +and + +(b) You hereby grant to Apple and its subsidiaries a non-exclusive, +worldwide, royalty-free, perpetual and irrevocable license, under Your +Applicable Patent Rights and other intellectual property rights owned +or controlled by You, to use, reproduce, execute, compile, display, +perform, modify or have modified (for Apple and/or its subsidiaries), +sublicense and distribute Your Modifications, in any form, through +multiple tiers of distribution. + +4. Larger Works. You may create a Larger Work by combining Covered +Code with other code not governed by the terms of this License and +distribute the Larger Work as a single product. In each such +instance, You must make sure the requirements of this License are +fulfilled for the Covered Code or any portion thereof. + +5. Limitations on Patent License. Except as expressly stated in +Section 2, no other patent rights, express or implied, are granted by +Apple herein. Modifications and/or Larger Works may require +additional patent licenses from Apple which Apple may grant in its +sole discretion. + +6. Additional Terms. You may choose to offer, and to charge a fee +for, warranty, support, indemnity or liability obligations and/or +other rights consistent with the scope of the license granted herein +("Additional Terms") to one or more recipients of Covered +Code. However, You may do so only on Your own behalf and as Your sole +responsibility, and not on behalf of Apple. You must obtain the +recipient's agreement that any such Additional Terms are offered by +You alone, and You hereby agree to indemnify, defend and hold Apple +harmless for any liability incurred by or claims asserted against +Apple by reason of any such Additional Terms. + +7. Versions of the License. Apple may publish revised and/or new +versions of this License from time to time. Each version will be +given a distinguishing version number. Once Original Code has been +published under a particular version of this License, You may continue +to use it under the terms of that version. You may also choose to use +such Original Code under the terms of any subsequent version of this +License published by Apple. No one other than Apple has the right to +modify the terms applicable to Covered Code created under this +License. + +8. NO WARRANTY OR SUPPORT. The Original Code may contain in whole or +in part pre-release, untested, or not fully tested works. The +Original Code may contain errors that could cause failures or loss of +data, and may be incomplete or contain inaccuracies. You expressly +acknowledge and agree that use of the Original Code, or any portion +thereof, is at Your sole and entire risk. THE ORIGINAL CODE IS +PROVIDED "AS IS" AND WITHOUT WARRANTY, UPGRADES OR SUPPORT OF ANY KIND +AND APPLE AND APPLE'S LICENSOR(S) (FOR THE PURPOSES OF SECTIONS 8 AND +9, APPLE AND APPLE'S LICENSOR(S) ARE COLLECTIVELY REFERRED TO AS +"APPLE") EXPRESSLY DISCLAIM ALL WARRANTIES AND/OR CONDITIONS, EXPRESS +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +AND/OR CONDITIONS OF MERCHANTABILITY OR SATISFACTORY QUALITY AND +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY +RIGHTS. APPLE DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED IN THE +ORIGINAL CODE WILL MEET YOUR REQUIREMENTS, OR THAT THE OPERATION OF +THE ORIGINAL CODE WILL BE UNINTERRUPTED OR ERROR- FREE, OR THAT +DEFECTS IN THE ORIGINAL CODE WILL BE CORRECTED. NO ORAL OR WRITTEN +INFORMATION OR ADVICE GIVEN BY APPLE OR AN APPLE AUTHORIZED +REPRESENTATIVE SHALL CREATE A WARRANTY OR IN ANY WAY INCREASE THE +SCOPE OF THIS WARRANTY. You acknowledge that the Original Code is not +intended for use in the operation of nuclear facilities, aircraft +navigation, communication systems, or air traffic control machines in +which case the failure of the Original Code could lead to death, +personal injury, or severe physical or environmental damage. + +9. Liability. + +9.1 Infringement. If any portion of, or functionality implemented by, +the Original Code becomes the subject of a claim of infringement, +Apple may, at its option: (a) attempt to procure the rights necessary +for Apple and You to continue using the Affected Original Code; (b) +modify the Affected Original Code so that it is no longer infringing; +or (c) suspend Your rights to use, reproduce, modify, sublicense and +distribute the Affected Original Code until a final determination of +the claim is made by a court or governmental administrative agency of +competent jurisdiction and Apple lifts the suspension as set forth +below. Such suspension of rights will be effective immediately upon +Apple's posting of a notice to such effect on the Apple web site that +is used for implementation of this License. Upon such final +determination being made, if Apple is legally able, without the +payment of a fee or royalty, to resume use, reproduction, +modification, sublicensing and distribution of the Affected Original +Code, Apple will lift the suspension of rights to the Affected +Original Code by posting a notice to such effect on the Apple web site +that is used for implementation of this License. If Apple suspends +Your rights to Affected Original Code, nothing in this License shall +be construed to restrict You, at Your option and subject to applicable +law, from replacing the Affected Original Code with non-infringing +code or independently negotiating for necessary rights from such third +party. + +9.2 LIMITATION OF LIABILITY. UNDER NO CIRCUMSTANCES SHALL APPLE BE +LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES +ARISING OUT OF OR RELATING TO THIS LICENSE OR YOUR USE OR INABILITY TO +USE THE ORIGINAL CODE, OR ANY PORTION THEREOF, WHETHER UNDER A THEORY +OF CONTRACT, WARRANTY, TORT (INCLUDING NEGLIGENCE), PRODUCTS LIABILITY +OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES AND NOTWITHSTANDING THE FAILURE OF ESSENTIAL PURPOSE OF +ANY REMEDY. In no event shall Apple's total liability to You for all +damages under this License exceed the amount of fifty dollars +($50.00). + +10. Trademarks. This License does not grant any rights to use the +trademarks or trade names "Apple", "Apple Computer", "Mac OS X", "Mac +OS X Server" or any other trademarks or trade names belonging to Apple +(collectively "Apple Marks") and no Apple Marks may be used to endorse +or promote products derived from the Original Code other than as +permitted by and in strict compliance at all times with Apple's third +party trademark usage guidelines which are posted at +http://www.apple.com/legal/guidelinesfor3rdparties.html. + +11. Ownership. Apple retains all rights, title and interest in and to +the Original Code and any Modifications made by or on behalf of Apple +("Apple Modifications"), and such Apple Modifications will not be +automatically subject to this License. Apple may, at its sole +discretion, choose to license such Apple Modifications under this +License, or on different terms from those contained in this License or +may choose not to license them at all. Apple's development, use, +reproduction, modification, sublicensing and distribution of Covered +Code will not be subject to this License. + +12. Termination. + +12.1 Termination. This License and the rights granted hereunder will + terminate: + +(a) automatically without notice from Apple if You fail to comply with +any term(s) of this License and fail to cure such breach within 30 +days of becoming aware of such breach; (b) immediately in the event of +the circumstances described in Section 13.5(b); or (c) automatically +without notice from Apple if You, at any time during the term of this +License, commence an action for patent infringement against Apple. + +12.2 Effect of Termination. Upon termination, You agree to +immediately stop any further use, reproduction, modification, +sublicensing and distribution of the Covered Code and to destroy all +copies of the Covered Code that are in your possession or control. +All sublicenses to the Covered Code which have been properly granted +prior to termination shall survive any termination of this License. +Provisions which, by their nature, should remain in effect beyond the +termination of this License shall survive, including but not limited +to Sections 3, 5, 8, 9, 10, 11, 12.2 and 13. Neither party will be +liable to the other for compensation, indemnity or damages of any sort +solely as a result of terminating this License in accordance with its +terms, and termination of this License will be without prejudice to +any other right or remedy of either party. + +13. Miscellaneous. + +13.1 Government End Users. The Covered Code is a "commercial item" as +defined in FAR 2.101. Government software and technical data rights +in the Covered Code include only those rights customarily provided to +the public as defined in this License. This customary commercial +license in technical data and software is provided in accordance with +FAR 12.211 (Technical Data) and 12.212 (Computer Software) and, for +Department of Defense purchases, DFAR 252.227-7015 (Technical Data -- +Commercial Items) and 227.7202-3 (Rights in Commercial Computer +Software or Computer Software Documentation). Accordingly, all U.S. +Government End Users acquire Covered Code with only those rights set +forth herein. + +13.2 Relationship of Parties. This License will not be construed as +creating an agency, partnership, joint venture or any other form of +legal association between You and Apple, and You will not represent to +the contrary, whether expressly, by implication, appearance or +otherwise. + +13.3 Independent Development. Nothing in this License will impair +Apple's right to acquire, license, develop, have others develop for +it, market and/or distribute technology or products that perform the +same or similar functions as, or otherwise compete with, +Modifications, Larger Works, technology or products that You may +develop, produce, market or distribute. + +13.4 Waiver; Construction. Failure by Apple to enforce any provision +of this License will not be deemed a waiver of future enforcement of +that or any other provision. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +will not apply to this License. + +13.5 Severability. (a) If for any reason a court of competent +jurisdiction finds any provision of this License, or portion thereof, +to be unenforceable, that provision of the License will be enforced to +the maximum extent permissible so as to effect the economic benefits +and intent of the parties, and the remainder of this License will +continue in full force and effect. (b) Notwithstanding the foregoing, +if applicable law prohibits or restricts You from fully and/or +specifically complying with Sections 2 and/or 3 or prevents the +enforceability of either of those Sections, this License will +immediately terminate and You must immediately discontinue any use of +the Covered Code and destroy all copies of it that are in your +possession or control. + +13.6 Dispute Resolution. Any litigation or other dispute resolution +between You and Apple relating to this License shall take place in the +Northern District of California, and You and Apple hereby consent to +the personal jurisdiction of, and venue in, the state and federal +courts within that District with respect to this License. The +application of the United Nations Convention on Contracts for the +International Sale of Goods is expressly excluded. + +13.7 Entire Agreement; Governing Law. This License constitutes the +entire agreement between the parties with respect to the subject +matter hereof. This License shall be governed by the laws of the +United States and the State of California, except that body of +California law concerning conflicts of law. + +Where You are located in the province of Quebec, Canada, the following +clause applies: The parties hereby confirm that they have requested +that this License and all related documents be drafted in English. Les +parties ont exige que le present contrat et tous les documents +connexes soient rediges en anglais. + +EXHIBIT A. + +"Portions Copyright (c) 1999-2000 Apple Computer, Inc. All Rights +Reserved. This file contains Original Code and/or Modifications of +Original Code as defined in and that are subject to the Apple Public +Source License Version 1.1 (the "License"). You may not use this file +except in compliance with the License. Please obtain a copy of the +License at http://www.apple.com/publicsource and read it before using +this file. + +The Original Code and all software distributed under the License are +distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER +EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, +INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the +License for the specific language governing rights and limitations +under the License." diff --git a/Makefile.postamble b/Makefile.postamble index 411cde6..c7b6b63 100644 --- a/Makefile.postamble +++ b/Makefile.postamble @@ -65,6 +65,7 @@ # DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags # passed to ld/libtool (defaults to nothing) +WARNING_CFLAGS = -Wall # Library and Framework projects only: # INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked diff --git a/Makefile.preamble b/Makefile.preamble index 11f5837..cfe786a 100644 --- a/Makefile.preamble +++ b/Makefile.preamble @@ -1,6 +1,3 @@ -INCLUDED_ARCHS = ppc -OTHER_RECURSIVE_VARIABLES += INCLUDED_ARCHS - ############################################################################### # Makefile.preamble # Copyright 1997, Apple Computer, Inc. diff --git a/bootx.tproj/Makefile b/bootx.tproj/Makefile index b63380a..edefa83 100644 --- a/bootx.tproj/Makefile +++ b/bootx.tproj/Makefile @@ -30,7 +30,7 @@ PROF_LIBS = $(LIBS) HEADER_PATHS = -I$(SRCROOT)/bootx.tproj/include.subproj -NEXTSTEP_PB_CFLAGS = -static +NEXTSTEP_PB_CFLAGS = -static -msoft-float NEXTSTEP_PB_LDFLAGS = -nostdlib -e _StartTVector -seg1addr 05600000 diff --git a/bootx.tproj/Makefile.postamble b/bootx.tproj/Makefile.postamble index 2c133fe..f855ea0 100644 --- a/bootx.tproj/Makefile.postamble +++ b/bootx.tproj/Makefile.postamble @@ -65,8 +65,8 @@ # DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags # passed to ld/libtool (defaults to nothing) -WARNING_CFLAGS = -Wmost -Wno-format -OPTIMIZE_BUILD_CFLAGS = -O0 +WARNING_CFLAGS = -Wall -Wno-format +OPTIMIZE_BUILD_CFLAGS = -Os # Library and Framework projects only: # INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked diff --git a/bootx.tproj/Makefile.preamble b/bootx.tproj/Makefile.preamble index df4d732..266463d 100644 --- a/bootx.tproj/Makefile.preamble +++ b/bootx.tproj/Makefile.preamble @@ -106,7 +106,8 @@ AFTER_INSTALL = bootx_after_install # you do not have to (and shouldn't) add OTHER_*FLAGS to # OTHER_RECURSIVE_VARIABLES. -OTHER_RECURSIVE_VARIABLES = WARNING_CFLAGS OPTIMIZE_BUILD_CFLAGS +INCLUDED_ARCHS=ppc +OTHER_RECURSIVE_VARIABLES = WARNING_CFLAGS OPTIMIZE_BUILD_CFLAGS INCLUDED_ARCHS LIBRARY_STYLE = STATIC # Additional headers to export beyond those in the PB.project: diff --git a/bootx.tproj/ci.subproj/Control2.c b/bootx.tproj/ci.subproj/Control2.c index 740d33c..2a684e2 100644 --- a/bootx.tproj/ci.subproj/Control2.c +++ b/bootx.tproj/ci.subproj/Control2.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/ci.subproj/MAC-PARTS.c b/bootx.tproj/ci.subproj/MAC-PARTS.c index 48e53a4..4eca06a 100644 --- a/bootx.tproj/ci.subproj/MAC-PARTS.c +++ b/bootx.tproj/ci.subproj/MAC-PARTS.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/ci.subproj/ci.c b/bootx.tproj/ci.subproj/ci.c index fa2e19e..9bddc40 100644 --- a/bootx.tproj/ci.subproj/ci.c +++ b/bootx.tproj/ci.subproj/ci.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -327,6 +324,10 @@ CICell Open(char *devSpec) CICell ihandle; long ret; + // intercept software RAID's virtual devices + if(isRAIDPath(devSpec)) + return (CICell)RAIDOpen(devSpec); + ciArgs.service = "open"; ciArgs.nArgs = 1; ciArgs.nReturns = 1; @@ -345,6 +346,11 @@ void Close(CICell ihandle) { CIArgs ciArgs; + if(isRAIDDevice((void*)ihandle)) { + RAIDClose((RAIDDevicePtr)ihandle); + return; + } + ciArgs.service = "close"; ciArgs.nArgs = 1; ciArgs.nReturns = 0; @@ -361,6 +367,9 @@ CICell Read(CICell ihandle, long addr, long length) long actual; long ret; + if(isRAIDDevice((void*)ihandle)) + return RAIDRead((RAIDDevicePtr)ihandle, addr, length, -1); + ciArgs.service = "read"; ciArgs.nArgs = 3; ciArgs.nReturns = 1; @@ -386,6 +395,11 @@ CICell Write(CICell ihandle, long addr, long length) CIArgs ciArgs; long actual; long ret; + + if(isRAIDDevice((void*)ihandle)) { + printf("who's trying to write to RAID?!\n"); + return -1; + } ciArgs.service = "write"; ciArgs.nArgs = 3; @@ -410,6 +424,9 @@ CICell Seek(CICell ihandle, long long position) CIArgs ciArgs; long ret; + if(isRAIDDevice((void*)ihandle)) + return RAIDSeek((RAIDDevicePtr)ihandle, position); + ciArgs.service = "seek"; ciArgs.nArgs = 3; ciArgs.nReturns = 1; diff --git a/bootx.tproj/ci.subproj/ci_io.c b/bootx.tproj/ci.subproj/ci_io.c index e58b4f3..39ff1c7 100644 --- a/bootx.tproj/ci.subproj/ci_io.c +++ b/bootx.tproj/ci.subproj/ci_io.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -41,3 +38,13 @@ int putchar(int ch) return ch; } + +int puts(const char *str) +{ + while (*str != '\0') + putchar(*str++); + + putchar('\n'); + + return 0; +} diff --git a/bootx.tproj/ci.subproj/sl_words.c b/bootx.tproj/ci.subproj/sl_words.c index 34c8cfd..d99a3d9 100644 --- a/bootx.tproj/ci.subproj/sl_words.c +++ b/bootx.tproj/ci.subproj/sl_words.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/fs.subproj/CaseTables.h b/bootx.tproj/fs.subproj/CaseTables.h index fb2f62e..d4691b6 100644 --- a/bootx.tproj/fs.subproj/CaseTables.h +++ b/bootx.tproj/fs.subproj/CaseTables.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/fs.subproj/HFSCompare.c b/bootx.tproj/fs.subproj/HFSCompare.c index d159c5e..1ea1796 100644 --- a/bootx.tproj/fs.subproj/HFSCompare.c +++ b/bootx.tproj/fs.subproj/HFSCompare.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/fs.subproj/Makefile b/bootx.tproj/fs.subproj/Makefile index bcc0e14..aab1a6d 100644 --- a/bootx.tproj/fs.subproj/Makefile +++ b/bootx.tproj/fs.subproj/Makefile @@ -16,7 +16,7 @@ HFILES = CaseTables.h ext2fs.h ext2fs_dinode.h ext2fs_dir.h\ ufs_byteorder.h CFILES = cache.c ext2fs.c ext2fs_bswap.c fs.c hfs.c HFSCompare.c\ - net.c ufs.c ufs_byteorder.c + net.c ufs.c ufs_byteorder.c md5c.c OTHERSRCS = Makefile.preamble Makefile Makefile.postamble diff --git a/bootx.tproj/fs.subproj/cache.c b/bootx.tproj/fs.subproj/cache.c index d3f6930..03ed81c 100644 --- a/bootx.tproj/fs.subproj/cache.c +++ b/bootx.tproj/fs.subproj/cache.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -79,7 +76,7 @@ void CacheInit(CICell ih, long blockSize) long CacheRead(CICell ih, char *buffer, long long offset, long length, long cache) { - long cnt, oldestEntry, oldestTime, loadCache = 0; + long cnt, oldestEntry = 0, oldestTime, loadCache = 0; CacheEntry *entry; // See if the data can be cached. diff --git a/bootx.tproj/fs.subproj/ext2fs.c b/bootx.tproj/fs.subproj/ext2fs.c index 1d16ab3..c8bdc99 100644 --- a/bootx.tproj/fs.subproj/ext2fs.c +++ b/bootx.tproj/fs.subproj/ext2fs.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -172,6 +169,16 @@ long Ext2GetDirEntry(CICell ih, char *dirPath, long *dirIndex, return 0; } +// XX no support in AppleFileSystemDriver yet +long Ext2GetUUID(CICell ih, char *uuidStr) +{ + uint8_t *uuid = gFS->e2fs.e2fs_uuid; + + if (Ext2InitPartition(ih) == -1) return -1; + + return CreateUUIDString(uuid, sizeof(gFS->e2fs.e2fs_uuid), uuidStr); +} + // Private functions static long HowMany(long bufferSize, long unitSize) @@ -337,17 +344,17 @@ static char *ReadFileBlock(InodePtr fileInode, long blockNum, long blockOffset, // Get Double Indirect Block Number. if (blockNum < (refsPerBlock * refsPerBlock)) { - indBlockNum = fileInode->e2di_blocks[NDADDR + 1]; + indBlockNum = bswap32(fileInode->e2di_blocks[NDADDR + 1]); } else { - blockNum -= refsPerBlock * refsPerBlock; + blockNum -= refsPerBlock * refsPerBlock; - // Get Triple Indirect Block Number. - indBlockNum = fileInode->e2di_blocks[NDADDR + 2]; + // Get Triple Indirect Block Number. + indBlockNum = bswap32(fileInode->e2di_blocks[NDADDR + 2]); - indBlock = ReadBlock(indBlockNum, 0, gBlockSize, 0, 1); - indBlockOff = blockNum / (refsPerBlock * refsPerBlock); - blockNum %= (refsPerBlock * refsPerBlock); - indBlockNum = bswap32(((u_int32_t *)indBlock)[indBlockOff]); + indBlock = ReadBlock(indBlockNum, 0, gBlockSize, 0, 1); + indBlockOff = blockNum / (refsPerBlock * refsPerBlock); + blockNum %= (refsPerBlock * refsPerBlock); + indBlockNum = bswap32(((u_int32_t *)indBlock)[indBlockOff]); } indBlock = ReadBlock(indBlockNum, 0, gBlockSize, 0, 1); diff --git a/bootx.tproj/fs.subproj/ext2fs.h b/bootx.tproj/fs.subproj/ext2fs.h index ed8369f..0cb9acb 100644 --- a/bootx.tproj/fs.subproj/ext2fs.h +++ b/bootx.tproj/fs.subproj/ext2fs.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/fs.subproj/ext2fs_bswap.c b/bootx.tproj/fs.subproj/ext2fs_bswap.c index 572a248..8699b65 100644 --- a/bootx.tproj/fs.subproj/ext2fs_bswap.c +++ b/bootx.tproj/fs.subproj/ext2fs_bswap.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/fs.subproj/ext2fs_dinode.h b/bootx.tproj/fs.subproj/ext2fs_dinode.h index cf4d1fa..276254d 100644 --- a/bootx.tproj/fs.subproj/ext2fs_dinode.h +++ b/bootx.tproj/fs.subproj/ext2fs_dinode.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/fs.subproj/ext2fs_dir.h b/bootx.tproj/fs.subproj/ext2fs_dir.h index 48f2fe9..30bf40f 100644 --- a/bootx.tproj/fs.subproj/ext2fs_dir.h +++ b/bootx.tproj/fs.subproj/ext2fs_dir.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/fs.subproj/fs.c b/bootx.tproj/fs.subproj/fs.c index a58553b..98f5e79 100644 --- a/bootx.tproj/fs.subproj/fs.c +++ b/bootx.tproj/fs.subproj/fs.c @@ -3,39 +3,41 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ /* * fs.c - Generic access to the file system modules. * - * Copyright (c) 1999-2000 Apple Computer, Inc. + * Copyright (c) 1999-2004 Apple Computer, Inc. * * DRI: Josh de Cesare */ #include +#include typedef long (* FSLoadFile)(CICell ih, char *filePath); +typedef long (* FSReadFile)(CICell ih, char *filePath, + void *base, unsigned long offset, + unsigned long length); typedef long (* FSGetDirEntry)(CICell ih, char *dirPath, long *dirIndex, char **name, long *flags, long *time); +typedef long (* FSGetUUID)(CICell ih, char *uuidStr); #define kPartNet (0) #define kPartHFS (1) @@ -46,7 +48,9 @@ struct PartInfo { long partType; CICell partIH; FSLoadFile loadFile; + FSReadFile readFile; FSGetDirEntry getDirEntry; + FSGetUUID getUUID; char partName[1024]; }; typedef struct PartInfo PartInfo, *PartInfoPtr; @@ -83,6 +87,128 @@ long LoadFile(char *fileSpec) return length; } +long LoadThinFatFile(char *fileSpec, void **binary) +{ + char devSpec[256]; + char *filePath; + FSLoadFile loadFile; + FSReadFile readFile; + long ret, length, length2, partIndex; + + ret = ConvertFileSpec(fileSpec, devSpec, &filePath); + if ((ret == -1) || (filePath == NULL)) return -1; + + // Get the partition index for devSpec. + partIndex = LookupPartition(devSpec); + if (partIndex == -1) return -1; + + *binary = (void *)kLoadAddr; + + readFile = gParts[partIndex].readFile; + + if (readFile != NULL) { + // Read the first 4096 bytes (fat header) + length = readFile(gParts[partIndex].partIH, filePath, *binary, 0, 0x1000); + if (length > 0) { + if (ThinFatBinary(binary, &length) == 0) { + // We found a fat binary; read only the thin part + length = readFile(gParts[partIndex].partIH, filePath, + (void *)kLoadAddr, (unsigned long)(*binary) - kLoadAddr, length); + *binary = (void *)kLoadAddr; + } else { + // Not a fat binary; read the rest of the file + length2 = readFile(gParts[partIndex].partIH, filePath, (void *)(kLoadAddr + length), length, 0); + if (length2 == -1) return -1; + length += length2; + } + } + } else { + loadFile = gParts[partIndex].loadFile; + length = loadFile(gParts[partIndex].partIH, filePath); + if (length > 0) { + ThinFatBinary(binary, &length); + } + } + + return length; +} + +long GetFSUUID(char *spec, char *uuidStr) +{ + long rval = -1, partIndex; + FSGetUUID getUUID; + char devSpec[256]; + + do { + if(ConvertFileSpec(spec, devSpec, NULL)) break; + + // Get the partition index + partIndex = LookupPartition(devSpec); + if (partIndex == -1) break; + + getUUID = gParts[partIndex].getUUID; + if(getUUID) + rval = getUUID(gParts[partIndex].partIH, uuidStr); + } while(0); + + return rval; +} + + +// from our uuid/namespace.h (UFS and HFS uuids can live in the same space?) +static char kFSUUIDNamespaceSHA1[] = {0xB3,0xE2,0x0F,0x39,0xF2,0x92,0x11,0xD6,0x97,0xA4,0x00,0x30,0x65,0x43,0xEC,0xAC}; + +// filesystem-specific getUUID functions call this shared string generator +long CreateUUIDString(uint8_t uubytes[], int nbytes, char *uuidStr) +{ + unsigned fmtbase, fmtidx, i; + uint8_t uuidfmt[] = { 4, 2, 2, 2, 6 }; + char *p = uuidStr; + MD5_CTX md5c; + uint8_t mdresult[16]; + + bzero(mdresult, sizeof(mdresult)); + + // just like AppleFileSystemDriver + MD5Init(&md5c); + MD5Update(&md5c, kFSUUIDNamespaceSHA1, sizeof(kFSUUIDNamespaceSHA1)); + MD5Update(&md5c, uubytes, nbytes); + MD5Final(mdresult, &md5c); + + // this UUID has been made version 3 style (i.e. via namespace) + // see "-uuid-urn-" IETF draft (which otherwise copies byte for byte) + mdresult[6] = 0x30 | ( mdresult[6] & 0x0F ); + mdresult[8] = 0x80 | ( mdresult[8] & 0x3F ); + + + // generate the text: e.g. 5EB1869F-C4FA-3502-BDEB-3B8ED5D87292 + i = 0; fmtbase = 0; + for(fmtidx = 0; fmtidx < sizeof(uuidfmt); fmtidx++) { + for(i=0; i < uuidfmt[fmtidx]; i++) { + uint8_t byte = mdresult[fmtbase+i]; + char nib; + + nib = byte >> 4; + *p = nib + '0'; // 0x4 -> '4' + if(*p > '9') *p = (nib - 9 + ('A'-1)); // 0xB -> 'B' + p++; + + nib = byte & 0xf; + *p = nib + '0'; // 0x4 -> '4' + if(*p > '9') *p = (nib - 9 + ('A'-1)); // 0xB -> 'B' + p++; + + } + fmtbase += i; + if(fmtidx < sizeof(uuidfmt)-1) + *(p++) = '-'; + else + *p = '\0'; + } + + return 0; +} + long GetFileInfo(char *dirSpec, char *name, long *flags, long *time) { long ret, index = 0; @@ -206,22 +332,31 @@ long LookupPartition(char *devSpec) switch (partType) { case kPartNet: gParts[partIndex].loadFile = NetLoadFile; + gParts[partIndex].readFile = NULL; gParts[partIndex].getDirEntry = NetGetDirEntry; + gParts[partIndex].getUUID = NULL; break; case kPartHFS: gParts[partIndex].loadFile = HFSLoadFile; + gParts[partIndex].readFile = HFSReadFile; gParts[partIndex].getDirEntry = HFSGetDirEntry; + gParts[partIndex].getUUID = HFSGetUUID; break; case kPartUFS: gParts[partIndex].loadFile = UFSLoadFile; + gParts[partIndex].readFile = UFSReadFile; gParts[partIndex].getDirEntry = UFSGetDirEntry; + gParts[partIndex].getUUID = UFSGetUUID; break; case kPartExt2: gParts[partIndex].loadFile = Ext2LoadFile; + gParts[partIndex].readFile = NULL; gParts[partIndex].getDirEntry = Ext2GetDirEntry; + gParts[partIndex].getUUID = NULL; + // Ext2GetUUID exists, but there's no kernel support break; } } diff --git a/bootx.tproj/fs.subproj/hfs.c b/bootx.tproj/fs.subproj/hfs.c index 1b30dac..610e504 100644 --- a/bootx.tproj/fs.subproj/hfs.c +++ b/bootx.tproj/fs.subproj/hfs.c @@ -3,29 +3,26 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ /* * hfs.c - File System Module for HFS and HFS+. * - * Copyright (c) 1999-2002 Apple Computer, Inc. + * Copyright (c) 1999-2004 Apple Computer, Inc. * * DRI: Josh de Cesare */ @@ -52,9 +49,10 @@ static HFSMasterDirectoryBlock *gHFSMDB =(HFSMasterDirectoryBlock*)gHFSMdbVib; static char gHFSPlusHeader[kBlockSize]; static HFSPlusVolumeHeader *gHFSPlus =(HFSPlusVolumeHeader*)gHFSPlusHeader; static char gLinkTemp[64]; +static long long gVolID; -static long ReadFile(void *file, long *length); +static long ReadFile(void *file, long *length, void *base, long offset); static long GetCatalogEntryInfo(void *entry, long *flags, long *time); static long ResolvePathToCatalogEntry(char *filePath, long *flags, void *entry, long dirID, long *dirIndex); @@ -119,6 +117,9 @@ long HFSInitPartition(CICell ih) gBlockSize = gHFSMDB->drAlBlkSiz; CacheInit(ih, gBlockSize); gCurrentIH = ih; + + // grab the 64 bit volume ID + bcopy(&gHFSMDB->drFndrInfo[6], &gVolID, 8); // Get the Catalog BTree node size. extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec; @@ -142,15 +143,20 @@ long HFSInitPartition(CICell ih) Seek(ih, gAllocationOffset + kMDBBaseOffset); Read(ih, (long)gHFSPlusHeader, kBlockSize); +//printf("checking signatures...\n"); // Not a HFS[+] volume. if ((gHFSPlus->signature != kHFSPlusSigWord) && (gHFSPlus->signature != kHFSXSigWord)) return -1; - +//printf("continuing with HFS\n"); + gIsHFSPlus = 1; gBlockSize = gHFSPlus->blockSize; CacheInit(ih, gBlockSize); gCurrentIH = ih; + // grab the 64 bit volume ID + bcopy(&gHFSPlus->finderInfo[24], &gVolID, 8); + // Get the Catalog BTree node size. extent = &gHFSPlus->catalogFile.extents; extentSize = gHFSPlus->catalogFile.logicalSize; @@ -166,13 +172,20 @@ long HFSInitPartition(CICell ih) } long HFSLoadFile(CICell ih, char *filePath) +{ + return HFSReadFile(ih, filePath, (void *)kLoadAddr, 0, 0); +} + +extern long HFSReadFile(CICell ih, char *filePath, void *base, + unsigned long offset, unsigned long length) { char entry[512]; - long dirID, result, length, flags; + long dirID, result, flags; if (HFSInitPartition(ih) == -1) return -1; - printf("Loading HFS%s file: [%s] from %x.\n", + printf("%s HFS%s file: [%s] from %x.\n", + (((offset == 0) && (length == 0)) ? "Loading" : "Reading"), (gIsHFSPlus ? "+" : ""), filePath, ih); dirID = kHFSRootFolderID; @@ -191,9 +204,12 @@ long HFSLoadFile(CICell ih, char *filePath) if ((result == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) return -1; // Check file owner and permissions. - if (flags & (kOwnerNotRoot | kPermGroupWrite | kPermOtherWrite)) return -1; + if (flags & (kOwnerNotRoot | kPermGroupWrite | kPermOtherWrite)) { + printf("%s: permissions incorrect\n", filePath); + return -1; + } - result = ReadFile(entry, &length); + result = ReadFile(entry, &length, base, offset); if (result == -1) return -1; return length; @@ -234,40 +250,57 @@ long HFSGetDirEntry(CICell ih, char *dirPath, long *dirIndex, char **name, return 0; } +long HFSGetUUID(CICell ih, char *uuidStr) +{ + if (HFSInitPartition(ih) == -1) return -1; + if (gVolID == 0LL) return -1; + + return CreateUUIDString((uint8_t*)(&gVolID), sizeof(gVolID), uuidStr); +} + // Private Functions -static long ReadFile(void *file, long *length) +static long ReadFile(void *file, long *length, void *base, long offset) { void *extents; - long fileID; + long fileID, fileLength; HFSCatalogFile *hfsFile = file; HFSPlusCatalogFile *hfsPlusFile = file; if (gIsHFSPlus) { fileID = hfsPlusFile->fileID; - *length = hfsPlusFile->dataFork.logicalSize; + fileLength = hfsPlusFile->dataFork.logicalSize; extents = &hfsPlusFile->dataFork.extents; } else { fileID = hfsFile->fileID; - *length = hfsFile->dataLogicalSize; + fileLength = hfsFile->dataLogicalSize; extents = &hfsFile->dataExtents; } + if (offset > fileLength) { + printf("Offset is too large.\n"); + return -1; + } + + if ((*length == 0) || ((offset + *length) > fileLength)) { + *length = fileLength - offset; + } + if (*length > kLoadSize) { printf("File is too large.\n"); return -1; } - *length = ReadExtent((char *)extents, *length, fileID, - 0, *length, (char *)kLoadAddr, 0); + *length = ReadExtent((char *)extents, fileLength, fileID, + offset, *length, base, 0); return 0; } static long GetCatalogEntryInfo(void *entry, long *flags, long *time) { - long tmpTime; + long tmpTime = 0; // Get information about the file. switch (*(short *)entry) { @@ -279,8 +312,13 @@ static long GetCatalogEntryInfo(void *entry, long *flags, long *time) case kHFSPlusFolderRecord : *flags = kFileTypeDirectory | (((HFSPlusCatalogFolder *)entry)->bsdInfo.fileMode & kPermMask); - if (((HFSPlusCatalogFolder *)entry)->bsdInfo.ownerID != 0) + if (((HFSPlusCatalogFolder *)entry)->bsdInfo.ownerID != 0) { + static int nwarnings = 0; + if(nwarnings++ < 25) // so we don't warn for all in an Extensions walk + printf("non-root file owner detected: %d\n", + ((HFSPlusCatalogFolder *)entry)->bsdInfo.ownerID); *flags |= kOwnerNotRoot; + } tmpTime = ((HFSPlusCatalogFolder *)entry)->contentModDate; break; @@ -292,8 +330,11 @@ static long GetCatalogEntryInfo(void *entry, long *flags, long *time) case kHFSPlusFileRecord : *flags = kFileTypeFlat | (((HFSPlusCatalogFile *)entry)->bsdInfo.fileMode & kPermMask); - if (((HFSPlusCatalogFile *)entry)->bsdInfo.ownerID != 0) + if (((HFSPlusCatalogFile *)entry)->bsdInfo.ownerID != 0) { + printf("non-root file owner detected: %d\n", + ((HFSPlusCatalogFile *)entry)->bsdInfo.ownerID); *flags |= kOwnerNotRoot; + } tmpTime = ((HFSPlusCatalogFile *)entry)->contentModDate; break; @@ -318,7 +359,7 @@ static long ResolvePathToCatalogEntry(char *filePath, long *flags, void *entry, long dirID, long *dirIndex) { char *restPath; - long result, cnt, subFolderID, tmpDirIndex; + long result, cnt, subFolderID = 0, tmpDirIndex; HFSPlusCatalogFile *hfsPlusFile; // Copy the file name to gTempStr @@ -469,8 +510,8 @@ static long ReadBTreeEntry(long btree, void *key, char *entry, long *dirIndex) short extentFile; char *nodeBuf; BTNodeDescriptor *node; - long nodeSize, result, entrySize; - long curNode, index, lowerBound, upperBound; + long nodeSize, result = 0, entrySize = 0; + long curNode, index = 0, lowerBound, upperBound; char *testKey, *recordData; // Figure out which tree is being looked at. diff --git a/bootx.tproj/fs.subproj/md5c.c b/bootx.tproj/fs.subproj/md5c.c new file mode 100644 index 0000000..a1700d0 --- /dev/null +++ b/bootx.tproj/fs.subproj/md5c.c @@ -0,0 +1,342 @@ +/* + * MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm + * + * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All + * rights reserved. + * + * License to copy and use this software is granted provided that it + * is identified as the "RSA Data Security, Inc. MD5 Message-Digest + * Algorithm" in all material mentioning or referencing this software + * or this function. + * + * License is also granted to make and use derivative works provided + * that such works are identified as "derived from the RSA Data + * Security, Inc. MD5 Message-Digest Algorithm" in all material + * mentioning or referencing the derived work. + * + * RSA Data Security, Inc. makes no representations concerning either + * the merchantability of this software or the suitability of this + * software for any particular purpose. It is provided "as is" + * without express or implied warranty of any kind. + * + * These notices must be retained in any copies of any part of this + * documentation and/or software. + * + * $Id: md5c.c,v 1.2 2005/02/03 05:16:40 lindak Exp $ + * + * This code is the same as the code published by RSA Inc. It has been + * edited for clarity and style only. + */ + +#include + +#ifdef KERNEL +#include +#else +#include +#endif + +#include + + +#ifdef KERNEL +#define memset(x,y,z) bzero(x,z); +#define memcpy(x,y,z) bcopy(y, x, z) +#endif + +#if defined(__i386__) || defined(__alpha__) +#define Encode memcpy +#define Decode memcpy +#else /* __i386__ */ + +/* + * Encodes input (u_int32_t) into output (unsigned char). Assumes len is + * a multiple of 4. + */ + +/* XXX not prototyped, and not compatible with memcpy(). */ +static void +Encode (output, input, len) + unsigned char *output; + u_int32_t *input; + unsigned int len; +{ + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) { + output[j] = (unsigned char)(input[i] & 0xff); + output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); + output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); + output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); + } +} + +/* + * Decodes input (unsigned char) into output (u_int32_t). Assumes len is + * a multiple of 4. + */ + +static void +Decode (output, input, len) + u_int32_t *output; + const unsigned char *input; + unsigned int len; +{ + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) + output[i] = ((u_int32_t)input[j]) | (((u_int32_t)input[j+1]) << 8) | + (((u_int32_t)input[j+2]) << 16) | (((u_int32_t)input[j+3]) << 24); +} +#endif /* i386 */ + +static unsigned char PADDING[64] = { + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +/* F, G, H and I are basic MD5 functions. */ +#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) +#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) +#define H(x, y, z) ((x) ^ (y) ^ (z)) +#define I(x, y, z) ((y) ^ ((x) | (~z))) + +/* ROTATE_LEFT rotates x left n bits. */ +#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) + +/* + * FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. + * Rotation is separate from addition to prevent recomputation. + */ +#define FF(a, b, c, d, x, s, ac) { \ + (a) += F ((b), (c), (d)) + (x) + (u_int32_t)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } +#define GG(a, b, c, d, x, s, ac) { \ + (a) += G ((b), (c), (d)) + (x) + (u_int32_t)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } +#define HH(a, b, c, d, x, s, ac) { \ + (a) += H ((b), (c), (d)) + (x) + (u_int32_t)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } +#define II(a, b, c, d, x, s, ac) { \ + (a) += I ((b), (c), (d)) + (x) + (u_int32_t)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } + +/* MD5 initialization. Begins an MD5 operation, writing a new context. */ + +void +MD5Init (context) + MD5_CTX *context; +{ + + context->count[0] = context->count[1] = 0; + + /* Load magic initialization constants. */ + context->state[0] = 0x67452301; + context->state[1] = 0xefcdab89; + context->state[2] = 0x98badcfe; + context->state[3] = 0x10325476; +} + +/* + * MD5 block update operation. Continues an MD5 message-digest + * operation, processing another message block, and updating the + * context. + */ + +void +MD5Update (context, input, inputLen) + MD5_CTX *context; + const unsigned char *input; + unsigned int inputLen; +{ + unsigned int i, index, partLen; + + /* Compute number of bytes mod 64 */ + index = (unsigned int)((context->count[0] >> 3) & 0x3F); + + /* Update number of bits */ + if ((context->count[0] += ((u_int32_t)inputLen << 3)) + < ((u_int32_t)inputLen << 3)) + context->count[1]++; + context->count[1] += ((u_int32_t)inputLen >> 29); + + partLen = 64 - index; + + /* Transform as many times as possible. */ + if (inputLen >= partLen) { + memcpy((void *)&context->buffer[index], (const void *)input, + partLen); + MD5Transform (context->state, context->buffer); + + for (i = partLen; i + 63 < inputLen; i += 64) + MD5Transform (context->state, &input[i]); + + index = 0; + } + else + i = 0; + + /* Buffer remaining input */ + memcpy ((void *)&context->buffer[index], (const void *)&input[i], + inputLen-i); +} + +/* + * MD5 padding. Adds padding followed by original length. + */ + +void +MD5Pad (context) + MD5_CTX *context; +{ + unsigned char bits[8]; + unsigned int index, padLen; + + /* Save number of bits */ + Encode (bits, context->count, 8); + + /* Pad out to 56 mod 64. */ + index = (unsigned int)((context->count[0] >> 3) & 0x3f); + padLen = (index < 56) ? (56 - index) : (120 - index); + MD5Update (context, PADDING, padLen); + + /* Append length (before padding) */ + MD5Update (context, bits, 8); +} + +/* + * MD5 finalization. Ends an MD5 message-digest operation, writing the + * the message digest and zeroizing the context. + */ + +void +MD5Final (digest, context) + unsigned char digest[16]; + MD5_CTX *context; +{ + /* Do padding. */ + MD5Pad (context); + + /* Store state in digest */ + Encode (digest, context->state, 16); + + /* Zeroize sensitive information. */ + memset ((void *)context, 0, sizeof (*context)); +} + +/* MD5 basic transformation. Transforms state based on block. */ + +void +MD5Transform (state, block) + u_int32_t state[4]; + const unsigned char block[64]; +{ + u_int32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16]; + + Decode (x, block, 64); + + /* Round 1 */ +#define S11 7 +#define S12 12 +#define S13 17 +#define S14 22 + FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ + FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ + FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ + FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ + FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ + FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ + FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ + FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ + FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ + FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ + FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ + FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ + FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ + FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ + FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ + FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ + + /* Round 2 */ +#define S21 5 +#define S22 9 +#define S23 14 +#define S24 20 + GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ + GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ + GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ + GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ + GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ + GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ + GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ + GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ + GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ + GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ + GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ + GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ + GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ + GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ + GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ + GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ + + /* Round 3 */ +#define S31 4 +#define S32 11 +#define S33 16 +#define S34 23 + HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ + HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ + HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ + HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ + HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ + HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ + HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ + HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ + HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ + HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ + HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ + HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ + HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ + HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ + HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ + HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ + + /* Round 4 */ +#define S41 6 +#define S42 10 +#define S43 15 +#define S44 21 + II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ + II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ + II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ + II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ + II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ + II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ + II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ + II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ + II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ + II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ + II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ + II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ + II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ + II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ + II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ + II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ + + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; + + /* Zeroize sensitive information. */ + memset ((void *)x, 0, sizeof (x)); +} diff --git a/bootx.tproj/fs.subproj/net.c b/bootx.tproj/fs.subproj/net.c index cec5bcf..5ef461b 100644 --- a/bootx.tproj/fs.subproj/net.c +++ b/bootx.tproj/fs.subproj/net.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/fs.subproj/ufs.c b/bootx.tproj/fs.subproj/ufs.c index 77abab5..ae86f76 100644 --- a/bootx.tproj/fs.subproj/ufs.c +++ b/bootx.tproj/fs.subproj/ufs.c @@ -3,29 +3,26 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ /* * ufs.c - File System Module for UFS. * - * Copyright (c) 1998-2002 Apple Computer, Inc. + * Copyright (c) 1998-2004 Apple Computer, Inc. * * DRI: Josh de Cesare */ @@ -49,13 +46,15 @@ static long FindFileInDir(char *fileName, long *flags, InodePtr fileInode, InodePtr dirInode); static char *ReadFileBlock(InodePtr fileInode, long fragNum, long blockOffset, long length, char *buffer, long cache); -static long ReadFile(InodePtr fileInode, long *length); +static long ReadFile(InodePtr fileInode, long *length, + void *base, long offset); static CICell gCurrentIH; static long long gPartitionBase; static char gFSBuf[SBSIZE]; static struct fs *gFS; +static struct ufslabel gUFSLabel; // for UUID static long gBlockSize; static long gBlockSizeOld; static long gFragSize; @@ -70,23 +69,35 @@ static Inode gFileInode; long UFSInitPartition(CICell ih) { + int ret; + if (ih == gCurrentIH) return 0; printf("UFSInitPartition: %x\n", ih); gCurrentIH = 0; - - // Assume there is no Disk Label + + // Assume UFS starts at the beginning of the device gPartitionBase = 0; + // read the disk label to get the UUID + // (rumor has it that UFS headers can be either-endian on disk; hopefully + // that isn't true for this UUID field). + Seek(ih, gPartitionBase + UFS_LABEL_OFFSET); + ret = Read(ih, (long)&gUFSLabel, UFS_LABEL_SIZE); + if(ret != UFS_LABEL_SIZE) + bzero(&gUFSLabel, UFS_LABEL_SIZE); + // Look for the Super Block Seek(ih, gPartitionBase + SBOFF); Read(ih, (long)gFSBuf, SBSIZE); gFS = (struct fs *)gFSBuf; +//printf("looking for UFS magic ... \n"); if (gFS->fs_magic != FS_MAGIC) { return -1; } +//printf("continuing w/UFS\n"); // Calculate the block size and set up the block cache. gBlockSize = gFS->fs_bsize; @@ -110,13 +121,31 @@ long UFSInitPartition(CICell ih) } +long UFSGetUUID(CICell ih, char *uuidStr) +{ + long long uuid = gUFSLabel.ul_uuid; + + if (UFSInitPartition(ih) == -1) return -1; + if (uuid == 0LL) return -1; + + return CreateUUIDString((uint8_t*)(&uuid), sizeof(uuid), uuidStr); +} + long UFSLoadFile(CICell ih, char *filePath) { - long ret, length, flags; + return UFSReadFile(ih, filePath, (void *)kLoadAddr, 0, 0); +} + +long UFSReadFile(CICell ih, char *filePath, void *base, + unsigned long offset, unsigned long length) +{ + long ret, flags; if (UFSInitPartition(ih) == -1) return -1; - printf("Loading UFS file: [%s] from %x.\n", filePath, ih); + printf("%s UFS file: [%s] from %x.\n", + (((offset == 0) && (length == 0)) ? "Loading" : "Reading"), + filePath, ih); // Skip one or two leading '\'. if (*filePath == '\\') filePath++; @@ -124,9 +153,12 @@ long UFSLoadFile(CICell ih, char *filePath) ret = ResolvePathToInode(filePath, &flags, &gFileInode, &gRootInode); if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) return -1; - if (flags & (kOwnerNotRoot | kPermGroupWrite | kPermOtherWrite)) return -1; + if (flags & (kOwnerNotRoot | kPermGroupWrite | kPermOtherWrite)) { + printf("%s: permissions incorrect\n", filePath); + return -1; + } - ret = ReadFile(&gFileInode, &length); + ret = ReadFile(&gFileInode, &length, base, offset); if (ret == -1) return -1; return length; @@ -203,7 +235,12 @@ static long ReadInode(long inodeNum, InodePtr inode, long *flags, long *time) *flags |= inode->di_mode & kPermMask; - if (inode->di_uid != 0) *flags |= kOwnerNotRoot; + if (inode->di_uid != 0) { + static int nwarnings = 0; + if(nwarnings++ < 25) // so we don't warn for all in an Extensions walk + printf("non-root file owner detected: %d\n", inode->di_uid); + *flags |= kOwnerNotRoot; + } } return 0; @@ -353,25 +390,41 @@ static char *ReadFileBlock(InodePtr fileInode, long fragNum, long blockOffset, } -static long ReadFile(InodePtr fileInode, long *length) +static long ReadFile(InodePtr fileInode, long *length, void *base, long offset) { - long bytesLeft, curSize, curFrag = 0; - char *buffer, *curAddr = (char *)kLoadAddr; + long bytesLeft, curSize, curFrag; + char *buffer, *curAddr = (char *)base; + + bytesLeft = fileInode->di_size; - bytesLeft = *length = fileInode->di_size; + if (offset > bytesLeft) { + printf("Offset is too large.\n"); + return -1; + } + + if ((*length == 0) || ((offset + *length) > bytesLeft)) { + *length = bytesLeft - offset; + } if (*length > kLoadSize) { printf("File is too large.\n"); return -1; } + bytesLeft = *length; + curFrag = (offset / gBlockSize) * gFragsPerBlock; + offset %= gBlockSize; + while (bytesLeft) { - if (bytesLeft > gBlockSize) curSize = gBlockSize; - else curSize = bytesLeft; + curSize = gBlockSize; + if (curSize > bytesLeft) curSize = bytesLeft; + if (offset != 0) curSize -= offset; - buffer = ReadFileBlock(fileInode, curFrag, 0, curSize, curAddr, 0); + buffer = ReadFileBlock(fileInode, curFrag, offset, curSize, curAddr, 0); if (buffer == 0) break; + if (offset != 0) offset = 0; + curFrag += gFragsPerBlock; curAddr += curSize; bytesLeft -= curSize; diff --git a/bootx.tproj/fs.subproj/ufs_byteorder.c b/bootx.tproj/fs.subproj/ufs_byteorder.c index 789e7db..f693992 100644 --- a/bootx.tproj/fs.subproj/ufs_byteorder.c +++ b/bootx.tproj/fs.subproj/ufs_byteorder.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/fs.subproj/ufs_byteorder.h b/bootx.tproj/fs.subproj/ufs_byteorder.h index 56685b9..cf1fd07 100644 --- a/bootx.tproj/fs.subproj/ufs_byteorder.h +++ b/bootx.tproj/fs.subproj/ufs_byteorder.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/include.subproj/boot_args.h b/bootx.tproj/include.subproj/boot_args.h index 58a89dd..5bc4f3b 100644 --- a/bootx.tproj/include.subproj/boot_args.h +++ b/bootx.tproj/include.subproj/boot_args.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/include.subproj/ci.h b/bootx.tproj/include.subproj/ci.h index f458d94..b9d6f1d 100644 --- a/bootx.tproj/include.subproj/ci.h +++ b/bootx.tproj/include.subproj/ci.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/include.subproj/device_tree.h b/bootx.tproj/include.subproj/device_tree.h index a271088..b842c1d 100644 --- a/bootx.tproj/include.subproj/device_tree.h +++ b/bootx.tproj/include.subproj/device_tree.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/include.subproj/fs.h b/bootx.tproj/include.subproj/fs.h index e5aa248..4c95151 100644 --- a/bootx.tproj/include.subproj/fs.h +++ b/bootx.tproj/include.subproj/fs.h @@ -3,29 +3,26 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ /* * fs.h - Externs for the File System Modules * - * Copyright (c) 1999-2000 Apple Computer, Inc. + * Copyright (c) 1999-2004 Apple Computer, Inc. * * DRI: Josh de Cesare */ @@ -35,10 +32,13 @@ // Externs for fs.c extern long LoadFile(char *fileSpec); +extern long LoadThinFatFile(char *fileSpec, void **binary); extern long GetFileInfo(char *dirSpec, char *name, long *flags, long *time); extern long GetDirEntry(char *dirSpec, long *dirIndex, char **name, long *flags, long *time); extern long DumpDir(char *dirSpec); +extern long GetFSUUID(char *devSpec, char *uuidStr); +extern long CreateUUIDString(uint8_t uubytes[], int nbytes, char *uuidStr); // Externs for cache.c extern unsigned long gCacheHits; @@ -59,16 +59,24 @@ extern long NetGetDirEntry(CICell ih, char *dirPath, // Externs for hfs.c extern long HFSInitPartition(CICell ih); extern long HFSLoadFile(CICell ih, char *filePath); +extern long HFSReadFile(CICell ih, char *filePath, + void *base, unsigned long offset, + unsigned long length); extern long HFSGetDirEntry(CICell ih, char *dirPath, long *dirIndex, char **name, long *flags, long *time); +extern long HFSGetUUID(CICell ih, char *uuidStr); // Externs for ufs.c extern long UFSInitPartition(CICell ih); extern long UFSLoadFile(CICell ih, char *filePath); +extern long UFSReadFile(CICell ih, char *filePath, + void *base, unsigned long offset, + unsigned long length); extern long UFSGetDirEntry(CICell ih, char *dirPath, long *dirIndex, char **name, long *flags, long *time); +extern long UFSGetUUID(CICell ih, char *uuidStr); // Externs for ext2.c extern long Ext2InitPartition(CICell ih); @@ -76,5 +84,6 @@ extern long Ext2LoadFile(CICell ih, char *filePath); extern long Ext2GetDirEntry(CICell ih, char *dirPath, long *dirIndex, char **name, long *flags, long *time); +extern long Ext2GetUUID(CICell ih, char *uuidStr); #endif /* ! _BOOTX_FS_H_ */ diff --git a/bootx.tproj/include.subproj/libclite.h b/bootx.tproj/include.subproj/libclite.h index a294aa2..132c39e 100644 --- a/bootx.tproj/include.subproj/libclite.h +++ b/bootx.tproj/include.subproj/libclite.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -42,9 +39,10 @@ // ci_io.c extern int putchar(int ch); +extern int puts(const char *str); // prf.c -extern void prf(const char *fmt, unsigned int *adx, void (*putfn_p)(), +extern void prf(const char *fmt, unsigned int *adx, int (*putfn_p)(int ch), void *putfn_arg); // printf.c @@ -59,8 +57,6 @@ extern int strcmp(const char *s1, const char *s2); extern int strncmp(const char *s1, const char *s2, size_t len); extern char *strcpy(char *s1, const char *s2); extern char *strncpy(char *s1, const char *s2, size_t n); -extern int ptol(char *str); -extern int atoi(const char *str); extern char *strncat(char *s1, const char *s2, size_t n); extern char *strcat(char *s1, const char *s2); extern int strncasecmp(const char *s1, const char *s2, size_t len); @@ -72,6 +68,7 @@ extern int isspace(char c); extern int isdigit(char c); extern char tolower(char c); extern long strtol(const char *nptr, char **endptr, register int base); +extern u_quad_t strtouq(const char *nptr, char **endptr, register int base); // zalloc.c extern void malloc_init(char *start, int size); @@ -83,6 +80,7 @@ extern void *realloc(void *start, size_t newsize); // mem.c extern void *memcpy(void *dst, const void *src, size_t len); extern void *memset(void *dst, int ch, size_t len); +extern int memcmp(const void *b1, const void *b2, size_t len); extern void bcopy(const void *src, void *dst, size_t len); extern void bzero(void *dst, int len); diff --git a/bootx.tproj/include.subproj/sl.h b/bootx.tproj/include.subproj/sl.h index 6e30cb0..9667a41 100644 --- a/bootx.tproj/include.subproj/sl.h +++ b/bootx.tproj/include.subproj/sl.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -33,6 +30,7 @@ #ifndef _BOOTX_SL_H_ #define _BOOTX_SL_H_ +// i.e. should we put up our failure screen; else back to OF #define kFailToBoot (1) /* @@ -84,6 +82,10 @@ Logical Address #define kMallocAddr (0x05400000) #define kMallocSize (0x00200000) +#define kMallocAddr_H (0x05400000) +#define kMallocSize_H (0x00200000) +#define kImageAddr_H (0x06000000) + // Default Output Level #define kOutputLevelOff (0) #define kOutputLevelFull (16) @@ -126,6 +128,7 @@ enum { #define kOptKey (0x201) #define kShiftKey (0x202) #define kControlKey (0x203) +#define kDeleteKey (0x204) // Mac OS X Booter Signature 'MOSX' #define kMacOSXSignature (0x4D4F5358) @@ -139,6 +142,7 @@ enum { #include #include +#include #include #include @@ -146,6 +150,28 @@ enum { #include #include +// types for plist.c +typedef enum { + kTagTypeNone = 0, + kTagTypeDict, + kTagTypeKey, + kTagTypeString, + kTagTypeInteger, + kTagTypeData, + kTagTypeDate, + kTagTypeFalse, + kTagTypeTrue, + kTagTypeArray +} TagType; + +struct Tag { + TagType type; + char *string; + struct Tag *tag; + struct Tag *tagNext; +}; +typedef struct Tag Tag, *TagPtr; + // Externs for main.c extern char *gVectorSaveAddr; extern long gKernelEntryPoint; @@ -162,6 +188,7 @@ extern long gBootFileType; extern char gHaveKernelCache; extern char gBootDevice[256]; extern char gBootFile[256]; +extern TagPtr gBootDict; extern char gTempStr[4096]; @@ -185,6 +212,9 @@ extern CICell gMemoryIH; extern CICell gStdOutIH; extern CICell gKeyboardIH; +// useful to activate debug logs near when a problem happens +//extern int gDebugCount; + extern long ThinFatBinary(void **binary, unsigned long *length); extern long GetDeviceType(char *devSpec); extern long ConvertFileSpec(char *fileSpec, char *devSpec, char **filePath); @@ -192,7 +222,7 @@ extern long MatchThis(CICell phandle, char *string); extern void *AllocateBootXMemory(long size); extern long AllocateKernelMemory(long size); extern long AllocateMemoryRange(char *rangeName, long start, long length); -extern unsigned long Alder32(unsigned char *buffer, long length); +extern unsigned long Adler32(unsigned char *buffer, long length); // Externs for macho.c extern long ThinFatBinaryMachO(void **binary, unsigned long *length); @@ -208,10 +238,16 @@ extern CICell SearchForNode(CICell ph, long top, char *prop, char *value); extern CICell SearchForNodeMatching(CICell ph, long top, char *value); // Externs for display.c -extern long InitDisplays(void); +extern long InitDisplays(int fill); extern long DrawSplashScreen(long stage); extern long DrawFailedBootPicture(void); -extern void GetMainScreenPH(Boot_Video_Ptr video); +extern void GetMainScreenPH(Boot_Video_Ptr video, int setProperties); +void SplashPreview(void *src, u_int8_t * saveunder, u_int32_t savelen); +void SplashProgress(u_int8_t * saveunder, int32_t firstBlob, int32_t select); + +// Externs for bmdecompress.c +extern int DecompressData(void *srcbase, void *dstbase, + int dw, int dh, int bytesPerPixel, int rowbytes); // Externs for drivers.c extern long LoadDrivers(char *dirPath); @@ -223,4 +259,28 @@ extern long ParseConfigFile(char *addr); // Externs for lzss.c extern int decompress_lzss(u_int8_t *dst, u_int8_t *src, u_int32_t srclen); + +// Externs for plist.c +#define PLIST_DEBUG 0 // whether report parsing errors, etc + +extern TagPtr GetProperty(TagPtr dict, char *key); +extern long ParseXML(char *buffer, TagPtr *dict); +extern void FreeTag(TagPtr tag); +#if PLIST_DEBUG +extern void DumpTag(TagPtr tag, long depth); +#endif + + +// Externs/types for raid.c +typedef struct RAIDMember *RAIDDevicePtr; + +extern int isRAIDPath(char *devSpec); +extern int isRAIDDevice(void *ih); +extern long LookForRAID(TagPtr bootDict); +extern RAIDDevicePtr RAIDOpen(char *devSpec); +extern void RAIDClose(RAIDDevicePtr raid); +extern long RAIDRead(RAIDDevicePtr raid, long a, long n, long long offset); +extern long RAIDSeek(RAIDDevicePtr raid, long long position); + + #endif /* ! _BOOTX_SL_H_ */ diff --git a/bootx.tproj/include.subproj/sl_words.h b/bootx.tproj/include.subproj/sl_words.h index 4960683..2359484 100644 --- a/bootx.tproj/include.subproj/sl_words.h +++ b/bootx.tproj/include.subproj/sl_words.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/libclite.subproj/bsearch.c b/bootx.tproj/libclite.subproj/bsearch.c index 32ef0d1..a9168a7 100644 --- a/bootx.tproj/libclite.subproj/bsearch.c +++ b/bootx.tproj/libclite.subproj/bsearch.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/libclite.subproj/bswap.c b/bootx.tproj/libclite.subproj/bswap.c index 09f4d37..7aec0d7 100644 --- a/bootx.tproj/libclite.subproj/bswap.c +++ b/bootx.tproj/libclite.subproj/bswap.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/libclite.subproj/mem.c b/bootx.tproj/libclite.subproj/mem.c index d0f300f..39e6911 100644 --- a/bootx.tproj/libclite.subproj/mem.c +++ b/bootx.tproj/libclite.subproj/mem.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -79,6 +76,23 @@ void *memset(void *dst, int ch, size_t len) return dst; } + +int +memcmp(const void *b1, const void *b2, size_t len) +{ + register long n = len; + unsigned char *m1 = (unsigned char *)b1; + unsigned char *m2 = (unsigned char *)b2; + + while (n-- && (*m1 == *m2)) { + m1++; + m2++; + } + + return ((n < 0) ? 0 : (*m1 - *m2)); +} + + void bcopy(const void *src, void *dst, size_t len) { memcpy(dst, src, len); diff --git a/bootx.tproj/libclite.subproj/prf.c b/bootx.tproj/libclite.subproj/prf.c index db95c8b..f06b024 100644 --- a/bootx.tproj/libclite.subproj/prf.c +++ b/bootx.tproj/libclite.subproj/prf.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/libclite.subproj/printf.c b/bootx.tproj/libclite.subproj/printf.c index 8a2db9c..df2ccee 100644 --- a/bootx.tproj/libclite.subproj/printf.c +++ b/bootx.tproj/libclite.subproj/printf.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/libclite.subproj/sprintf.c b/bootx.tproj/libclite.subproj/sprintf.c index 9de77ec..6e2690c 100644 --- a/bootx.tproj/libclite.subproj/sprintf.c +++ b/bootx.tproj/libclite.subproj/sprintf.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -64,7 +61,7 @@ int sprintf(char *str, const char *fmt, ...) va_start(ap, fmt); pi.str = str; pi.last_str = 0; - prf(fmt, (unsigned int *)ap, sputc, &pi); + prf(fmt, (unsigned int *)ap, (int (*)(int ch))sputc, &pi); *pi.str = '\0'; va_end(ap); return 0; @@ -76,7 +73,7 @@ int slvprintf(char *str, int len, const char *fmt, va_list ap ) struct putc_info pi; pi.str = str; pi.last_str = str + len - 1; - prf(fmt, (unsigned int *)ap, sputc, &pi); + prf(fmt, (unsigned int *)ap, (int (*)(int ch))sputc, &pi); *pi.str = '\0'; return (pi.str - str); } diff --git a/bootx.tproj/libclite.subproj/string.c b/bootx.tproj/libclite.subproj/string.c index bc76dc6..44ff6a2 100644 --- a/bootx.tproj/libclite.subproj/string.c +++ b/bootx.tproj/libclite.subproj/string.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -86,33 +83,6 @@ strncpy(char *s1, const char *s2, size_t n) return ret; } -int -ptol(char *str) -{ - register int c = *str; - - if (c <= '7' && c >= '0') - c -= '0'; - else if (c <= 'h' && c >= 'a') - c -= 'a'; - else c = 0; - return c; -} - -int -atoi(const char *str) -{ - register int sum = 0; - while (*str == ' ' || *str == '\t') - str++; - while (*str >= '0' && *str <= '9') { - sum *= 10; - sum += *str++ - '0'; - } - return sum; -} - - char *strncat(char *s1, const char *s2, size_t n) { register char *ret = s1; diff --git a/bootx.tproj/libclite.subproj/strtol.c b/bootx.tproj/libclite.subproj/strtol.c index 37cf4b9..97cf46b 100644 --- a/bootx.tproj/libclite.subproj/strtol.c +++ b/bootx.tproj/libclite.subproj/strtol.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -272,3 +269,74 @@ strtoul(nptr, endptr, base) return (acc); } +/* + * Convert a string to an unsigned quad integer. + * + * Ignores `locale' stuff. Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +u_quad_t +strtouq(nptr, endptr, base) + const char *nptr; + char **endptr; + register int base; +{ + register const char *s = nptr; + register u_quad_t acc; + register int c; + register u_quad_t qbase, cutoff; + register int neg, any, cutlim; + + /* + * See strtoq for comments as to the logic used. + */ + s = nptr; + do { + c = *s++; + } while (isspace(c)); + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + qbase = (unsigned)base; + cutoff = (u_quad_t)UQUAD_MAX / qbase; + cutlim = (u_quad_t)UQUAD_MAX % qbase; + for (acc = 0, any = 0;; c = *s++) { + if (isdigit(c)) + c -= '0'; + else if (isalpha(c)) + c -= isupper(c) ? 'A' - 10 : 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) + any = -1; + else { + any = 1; + acc *= qbase; + acc += c; + } + } + if (any < 0) { + acc = UQUAD_MAX; +// errno = ERANGE; + } else if (neg) + acc = -acc; + if (endptr != 0) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} + diff --git a/bootx.tproj/libclite.subproj/zalloc.c b/bootx.tproj/libclite.subproj/zalloc.c index 200b6c5..cdd1ba5 100644 --- a/bootx.tproj/libclite.subproj/zalloc.c +++ b/bootx.tproj/libclite.subproj/zalloc.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -136,7 +133,7 @@ done: void free(void *pointer) { - int i, tsize, found = 0; + int i, tsize = 0, found = 0; char *start = pointer; if (!zalloc_base) { diff --git a/bootx.tproj/sl.subproj/Makefile b/bootx.tproj/sl.subproj/Makefile index 51ebbe6..c761d73 100644 --- a/bootx.tproj/sl.subproj/Makefile +++ b/bootx.tproj/sl.subproj/Makefile @@ -12,9 +12,9 @@ NAME = sl PROJECTVERSION = 2.8 PROJECT_TYPE = Component -HFILES = appleboot.h clut.h elf.h failedboot.h netboot.h +HFILES = appleboot.h clut.h elf.h failedboot.h netboot.h aesopt.h aestab.h aes.h -CFILES = main.c macho.c device_tree.c display.c drivers.c elf.c lzss.c +CFILES = main.c macho.c device_tree.c display.c drivers.c elf.c lzss.c aescrypt.c aeskey.c aestab.c bmdecompress.c plist.c raid.c OTHERSRCS = Makefile.preamble Makefile Makefile.postamble diff --git a/bootx.tproj/sl.subproj/Makefile.postamble b/bootx.tproj/sl.subproj/Makefile.postamble index 411cde6..2fc0ab1 100644 --- a/bootx.tproj/sl.subproj/Makefile.postamble +++ b/bootx.tproj/sl.subproj/Makefile.postamble @@ -65,6 +65,8 @@ # DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags # passed to ld/libtool (defaults to nothing) +WARNING_CFLAGS = -Wall + # Library and Framework projects only: # INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked diff --git a/bootx.tproj/sl.subproj/aes.h b/bootx.tproj/sl.subproj/aes.h new file mode 100755 index 0000000..fc2dad5 --- /dev/null +++ b/bootx.tproj/sl.subproj/aes.h @@ -0,0 +1,175 @@ +/* + --------------------------------------------------------------------------- + Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved. + + LICENSE TERMS + + The free distribution and use of this software in both source and binary + form is allowed (with or without changes) provided that: + + 1. distributions of this source code include the above copyright + notice, this list of conditions and the following disclaimer; + + 2. distributions in binary form include the above copyright + notice, this list of conditions and the following disclaimer + in the documentation and/or other associated materials; + + 3. the copyright holder's name is not used to endorse products + built using this software without specific written permission. + + ALTERNATIVELY, provided that this notice is retained in full, this product + may be distributed under the terms of the GNU General Public License (GPL), + in which case the provisions of the GPL apply INSTEAD OF those given above. + + DISCLAIMER + + This software is provided 'as is' with no explicit or implied warranties + in respect of its properties, including, but not limited to, correctness + and/or fitness for purpose. + --------------------------------------------------------------------------- + Issue 28/01/2004 + + This file contains the definitions required to use AES in C. See aesopt.h + for optimisation details. +*/ + +#if !defined( _AES_H ) +#define _AES_H + +/* This include is used to find 8 & 32 bit unsigned integer types */ +#include + +#if defined(__cplusplus) +extern "C" +{ +#endif + +#define AES_128 /* define if AES with 128 bit keys is needed */ +#define AES_192 /* define if AES with 192 bit keys is needed */ +#define AES_256 /* define if AES with 256 bit keys is needed */ +#define AES_VAR /* define if a variable key size is needed */ + +/* The following must also be set in assembler files if being used */ + +//#define AES_ENCRYPT /* if support for encryption is needed */ +#define AES_DECRYPT /* if support for decryption is needed */ +//#define AES_ERR_CHK /* for parameter checks & error return codes */ + +#if UCHAR_MAX == 0xff /* an unsigned 8 bit type */ + typedef unsigned char aes_08t; +#else +# error Please define aes_08t as an 8-bit unsigned integer type in aes.h +#endif + +#if UINT_MAX == 4294967295 /* an unsigned 32 bit type */ + typedef unsigned int aes_32t; +#elif ULONG_MAX == 4294967295ul + typedef unsigned long aes_32t; +#else +# error Please define aes_32t as a 32-bit unsigned integer type in aes.h +#endif + +#define AES_BLOCK_SIZE 16 /* the AES block size in bytes */ +#define N_COLS 4 /* the number of columns in the state */ + +/* The key schedule length is 11, 13 or 15 16-byte blocks for 128, */ +/* 192 or 256-bit keys respectively. That is 176, 208 or 240 bytes */ +/* or 44, 52 or 60 32-bit words. For simplicity this code allocates */ +/* the maximum 60 word array for the key schedule for all key sizes */ + +#if defined( AES_VAR ) || defined( AES_256 ) +#define KS_LENGTH 60 +#elif defined( AES_192 ) +#define KS_LENGTH 52 +#else +#define KS_LENGTH 44 +#endif + +#if defined( AES_ERR_CHK ) +#define aes_ret int +#define aes_good 0 +#define aes_error -1 +#else +#define aes_ret void +#endif + +#if !defined( AES_DLL ) /* implement normal/DLL functions */ +#define aes_rval aes_ret +#else +#define aes_rval aes_ret __declspec(dllexport) _stdcall +#endif + +typedef struct +{ aes_32t ks[KS_LENGTH]; + aes_32t rn; +} aes_encrypt_ctx; + +typedef struct +{ aes_32t ks[KS_LENGTH]; + aes_32t rn; +} aes_decrypt_ctx; + +typedef struct +{ + aes_decrypt_ctx decrypt; + aes_encrypt_ctx encrypt; +} aes_ctx; + + +/* This routine must be called before first use if non-static */ +/* tables are being used */ + +void gen_tabs(void); + +/* The key length (klen) is input in bytes when it is in the range */ +/* 16 <= klen <= 32 or in bits when in the range 128 <= klen <= 256 */ + +#if defined( AES_ENCRYPT ) + +#if defined(AES_128) || defined(AES_VAR) +aes_rval aes_encrypt_key128(const unsigned char *in_key, aes_encrypt_ctx cx[1]); +#endif + +#if defined(AES_192) || defined(AES_VAR) +aes_rval aes_encrypt_key192(const unsigned char *in_key, aes_encrypt_ctx cx[1]); +#endif + +#if defined(AES_256) || defined(AES_VAR) +aes_rval aes_encrypt_key256(const unsigned char *in_key, aes_encrypt_ctx cx[1]); +#endif + +#if defined(AES_VAR) +aes_rval aes_encrypt_key(const unsigned char *in_key, int key_len, aes_encrypt_ctx cx[1]); +#endif + +aes_rval aes_encrypt_cbc(const unsigned char *in_blk, const unsigned char *in_iv, unsigned int num_blk, + unsigned char *out_blk, const aes_encrypt_ctx cx[1]); +#endif + +#if defined( AES_DECRYPT ) + +#if defined(AES_128) || defined(AES_VAR) +aes_rval aes_decrypt_key128(const unsigned char *in_key, aes_decrypt_ctx cx[1]); +#endif + +#if defined(AES_192) || defined(AES_VAR) +aes_rval aes_decrypt_key192(const unsigned char *in_key, aes_decrypt_ctx cx[1]); +#endif + +#if defined(AES_256) || defined(AES_VAR) +aes_rval aes_decrypt_key256(const unsigned char *in_key, aes_decrypt_ctx cx[1]); +#endif + +#if defined(AES_VAR) +aes_rval aes_decrypt_key(const unsigned char *in_key, int key_len, aes_decrypt_ctx cx[1]); +#endif + +aes_rval aes_decrypt_cbc(const unsigned char *in_blk, const unsigned char *in_iv, unsigned int num_blk, + unsigned char *out_blk, const aes_decrypt_ctx cx[1]); +#endif + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/bootx.tproj/sl.subproj/aescrypt.c b/bootx.tproj/sl.subproj/aescrypt.c new file mode 100755 index 0000000..141cd3f --- /dev/null +++ b/bootx.tproj/sl.subproj/aescrypt.c @@ -0,0 +1,407 @@ +/* + --------------------------------------------------------------------------- + Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved. + + LICENSE TERMS + + The free distribution and use of this software in both source and binary + form is allowed (with or without changes) provided that: + + 1. distributions of this source code include the above copyright + notice, this list of conditions and the following disclaimer; + + 2. distributions in binary form include the above copyright + notice, this list of conditions and the following disclaimer + in the documentation and/or other associated materials; + + 3. the copyright holder's name is not used to endorse products + built using this software without specific written permission. + + ALTERNATIVELY, provided that this notice is retained in full, this product + may be distributed under the terms of the GNU General Public License (GPL), + in which case the provisions of the GPL apply INSTEAD OF those given above. + + DISCLAIMER + + This software is provided 'as is' with no explicit or implied warranties + in respect of its properties, including, but not limited to, correctness + and/or fitness for purpose. + --------------------------------------------------------------------------- + Issue 28/01/2004 + + This file contains the code for implementing encryption and decryption + for AES (Rijndael) for block and key sizes of 16, 24 and 32 bytes. It + can optionally be replaced by code written in assembler using NASM. For + further details see the file aesopt.h +*/ + +#include "aesopt.h" +#include "aestab.h" + +#if defined(__cplusplus) +extern "C" +{ +#endif + +#define ki(y,x,k,c) (s(y,c) = s(x, c) ^ (k)[c]) +#define xo(y,x,c) (s(y,c) ^= s(x, c)) +#define si(y,x,c) (s(y,c) = word_in(x, c)) +#define so(y,x,c) word_out(y, c, s(x,c)) + +#if defined(ARRAYS) +#define locals(y,x) x[4],y[4] +#else +#define locals(y,x) x##0,x##1,x##2,x##3,y##0,y##1,y##2,y##3 +#endif + +#define dtables(tab) const aes_32t *tab##0, *tab##1, *tab##2, *tab##3 +#define itables(tab) tab##0 = tab[0]; tab##1 = tab[1]; tab##2 = tab[2]; tab##3 = tab[3] + +#define l_copy(y, x) s(y,0) = s(x,0); s(y,1) = s(x,1); \ + s(y,2) = s(x,2); s(y,3) = s(x,3); + +#define key_in(y,x,k) ki(y,x,k,0); ki(y,x,k,1); ki(y,x,k,2); ki(y,x,k,3) +#define cbc(y,x) xo(y,x,0); xo(y,x,1); xo(y,x,2); xo(y,x,3) +#define state_in(y,x) si(y,x,0); si(y,x,1); si(y,x,2); si(y,x,3) +#define state_out(y,x) so(y,x,0); so(y,x,1); so(y,x,2); so(y,x,3) +#define round(rm,y,x,k) rm(y,x,k,0); rm(y,x,k,1); rm(y,x,k,2); rm(y,x,k,3) + +#if defined(ENCRYPTION) && !defined(AES_ASM) + +/* Visual C++ .Net v7.1 provides the fastest encryption code when using + Pentium optimiation with small code but this is poor for decryption + so we need to control this with the following VC++ pragmas +*/ + +#if defined(_MSC_VER) +#pragma optimize( "s", on ) +#endif + +/* Given the column (c) of the output state variable, the following + macros give the input state variables which are needed in its + computation for each row (r) of the state. All the alternative + macros give the same end values but expand into different ways + of calculating these values. In particular the complex macro + used for dynamically variable block sizes is designed to expand + to a compile time constant whenever possible but will expand to + conditional clauses on some branches (I am grateful to Frank + Yellin for this construction) +*/ + +#define fwd_var(x,r,c)\ + ( r == 0 ? ( c == 0 ? s(x,0) : c == 1 ? s(x,1) : c == 2 ? s(x,2) : s(x,3))\ + : r == 1 ? ( c == 0 ? s(x,1) : c == 1 ? s(x,2) : c == 2 ? s(x,3) : s(x,0))\ + : r == 2 ? ( c == 0 ? s(x,2) : c == 1 ? s(x,3) : c == 2 ? s(x,0) : s(x,1))\ + : ( c == 0 ? s(x,3) : c == 1 ? s(x,0) : c == 2 ? s(x,1) : s(x,2))) + +#if defined(FT4_SET) +#undef dec_fmvars +# if defined(ENC_ROUND_CACHE_TABLES) +#define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_cached_tables(x,t_fn,fwd_var,rf1,c)) +# else +#define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_fn,fwd_var,rf1,c)) +# endif +#elif defined(FT1_SET) +#undef dec_fmvars +#define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,upr,t_fn,fwd_var,rf1,c)) +#else +#define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ fwd_mcol(no_table(x,t_sbox,fwd_var,rf1,c))) +#endif + +#if defined(FL4_SET) +# if defined(LAST_ENC_ROUND_CACHE_TABLES) +#define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_cached_tables(x,t_fl,fwd_var,rf1,c)) +# else +#define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_fl,fwd_var,rf1,c)) +# endif +#elif defined(FL1_SET) +#define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,ups,t_fl,fwd_var,rf1,c)) +#else +#define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ no_table(x,t_sbox,fwd_var,rf1,c)) +#endif + +aes_rval aes_encrypt_cbc(const unsigned char *in, const unsigned char *in_iv, unsigned int num_blk, + unsigned char *out, const aes_encrypt_ctx cx[1]) +{ aes_32t locals(b0, b1); + const aes_32t *kp = cx->ks; +#if defined(ENC_ROUND_CACHE_TABLES) + dtables(t_fn); +#endif +#if defined(LAST_ENC_ROUND_CACHE_TABLES) + dtables(t_fl); +#endif + +#if defined( dec_fmvars ) + dec_fmvars; /* declare variables for fwd_mcol() if needed */ +#endif + +#if defined( AES_ERR_CHK ) + if( cx->rn != 10 && cx->rn != 12 && cx->rn != 14 ) + return aes_error; +#endif + + // Load IV into b0. + state_in(b0, in_iv); + + for (;num_blk; in += AES_BLOCK_SIZE, out += AES_BLOCK_SIZE, --num_blk) + { +#if 0 + // Read the plaintext into b1 + state_in(b1, in); + // Do the CBC with b0 which is either the iv or the ciphertext of the previous block. + cbc(b1, b0); + + // Xor b1 with the key schedule to get things started. + key_in(b0, b1, kp); +#else + // Since xor is associative we mess with the ordering here to get the loads started early + key_in(b1, b0, kp); // Xor b0(IV) with the key schedule and assign to b1 + state_in(b0, in); // Load block into b0 + cbc(b0, b1); // Xor b0 with b1 and store in b0 +#endif + +#if defined(ENC_ROUND_CACHE_TABLES) + itables(t_fn); +#endif + +#if (ENC_UNROLL == FULL) + + switch(cx->rn) + { + case 14: + round(fwd_rnd, b1, b0, kp + 1 * N_COLS); + round(fwd_rnd, b0, b1, kp + 2 * N_COLS); + kp += 2 * N_COLS; + case 12: + round(fwd_rnd, b1, b0, kp + 1 * N_COLS); + round(fwd_rnd, b0, b1, kp + 2 * N_COLS); + kp += 2 * N_COLS; + case 10: + default: + round(fwd_rnd, b1, b0, kp + 1 * N_COLS); + round(fwd_rnd, b0, b1, kp + 2 * N_COLS); + round(fwd_rnd, b1, b0, kp + 3 * N_COLS); + round(fwd_rnd, b0, b1, kp + 4 * N_COLS); + round(fwd_rnd, b1, b0, kp + 5 * N_COLS); + round(fwd_rnd, b0, b1, kp + 6 * N_COLS); + round(fwd_rnd, b1, b0, kp + 7 * N_COLS); + round(fwd_rnd, b0, b1, kp + 8 * N_COLS); + round(fwd_rnd, b1, b0, kp + 9 * N_COLS); +#if defined(LAST_ENC_ROUND_CACHE_TABLES) + itables(t_fl); +#endif + round(fwd_lrnd, b0, b1, kp +10 * N_COLS); + } + +#else + + { aes_32t rnd; +#if (ENC_UNROLL == PARTIAL) + for(rnd = 0; rnd < (cx->rn >> 1) - 1; ++rnd) + { + kp += N_COLS; + round(fwd_rnd, b1, b0, kp); + kp += N_COLS; + round(fwd_rnd, b0, b1, kp); + } + kp += N_COLS; + round(fwd_rnd, b1, b0, kp); +#else + for(rnd = 0; rnd < cx->rn - 1; ++rnd) + { + kp += N_COLS; + round(fwd_rnd, b1, b0, kp); + l_copy(b0, b1); + } +#endif +#if defined(LAST_ENC_ROUND_CACHE_TABLES) + itables(t_fl); +#endif + kp += N_COLS; + round(fwd_lrnd, b0, b1, kp); + } +#endif + + state_out(out, b0); + } + +#if defined( AES_ERR_CHK ) + return aes_good; +#endif +} + +#endif + +#if defined(DECRYPTION) && !defined(AES_ASM) + +/* Visual C++ .Net v7.1 provides the fastest encryption code when using + Pentium optimiation with small code but this is poor for decryption + so we need to control this with the following VC++ pragmas +*/ + +#if defined(_MSC_VER) +#pragma optimize( "t", on ) +#endif + +/* Given the column (c) of the output state variable, the following + macros give the input state variables which are needed in its + computation for each row (r) of the state. All the alternative + macros give the same end values but expand into different ways + of calculating these values. In particular the complex macro + used for dynamically variable block sizes is designed to expand + to a compile time constant whenever possible but will expand to + conditional clauses on some branches (I am grateful to Frank + Yellin for this construction) +*/ + +#define inv_var(x,r,c)\ + ( r == 0 ? ( c == 0 ? s(x,0) : c == 1 ? s(x,1) : c == 2 ? s(x,2) : s(x,3))\ + : r == 1 ? ( c == 0 ? s(x,3) : c == 1 ? s(x,0) : c == 2 ? s(x,1) : s(x,2))\ + : r == 2 ? ( c == 0 ? s(x,2) : c == 1 ? s(x,3) : c == 2 ? s(x,0) : s(x,1))\ + : ( c == 0 ? s(x,1) : c == 1 ? s(x,2) : c == 2 ? s(x,3) : s(x,0))) + +#if defined(IT4_SET) +#undef dec_imvars +# if defined(DEC_ROUND_CACHE_TABLES) +#define inv_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_cached_tables(x,t_in,inv_var,rf1,c)) +# else +#define inv_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_in,inv_var,rf1,c)) +# endif +#elif defined(IT1_SET) +#undef dec_imvars +#define inv_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,upr,t_in,inv_var,rf1,c)) +#else +#define inv_rnd(y,x,k,c) (s(y,c) = inv_mcol((k)[c] ^ no_table(x,t_ibox,inv_var,rf1,c))) +#endif + +#if defined(IL4_SET) +# if defined(LAST_DEC_ROUND_CACHE_TABLES) +#define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_cached_tables(x,t_il,inv_var,rf1,c)) +# else +#define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_il,inv_var,rf1,c)) +# endif +#elif defined(IL1_SET) +#define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,ups,t_il,inv_var,rf1,c)) +#else +#define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ no_table(x,t_ibox,inv_var,rf1,c)) +#endif + +aes_rval aes_decrypt_cbc(const unsigned char *in, const unsigned char *in_iv, unsigned int num_blk, + unsigned char *out, const aes_decrypt_ctx cx[1]) +{ aes_32t locals(b0, b1); + const aes_32t *kp = cx->ks + cx->rn * N_COLS; +#if defined(DEC_ROUND_CACHE_TABLES) + dtables(t_in); +#endif +#if defined(LAST_DEC_ROUND_CACHE_TABLES) + dtables(t_il); +#endif + +#if defined( dec_imvars ) + dec_imvars; /* declare variables for inv_mcol() if needed */ +#endif + +#if defined( AES_ERR_CHK ) + if( cx->rn != 10 && cx->rn != 12 && cx->rn != 14 ) + return aes_error; +#endif + +#if defined(DEC_ROUND_CACHE_TABLES) + itables(t_in); +#endif + + in += AES_BLOCK_SIZE * (num_blk - 1); + out += AES_BLOCK_SIZE * (num_blk - 1); + // Load the last block's ciphertext into b1 + state_in(b1, in); + + for (;num_blk; out -= AES_BLOCK_SIZE, --num_blk) + { + // Do the xor part of state_in, where b1 is the previous block's ciphertext. + key_in(b0, b1, kp); + +#if (DEC_UNROLL == FULL) + + switch(cx->rn) + { + case 14: + round(inv_rnd, b1, b0, kp - 1 * N_COLS); + round(inv_rnd, b0, b1, kp - 2 * N_COLS); + kp -= 2 * N_COLS; + case 12: + round(inv_rnd, b1, b0, kp - 1 * N_COLS); + round(inv_rnd, b0, b1, kp - 2 * N_COLS); + kp -= 2 * N_COLS; + case 10: + default: + round(inv_rnd, b1, b0, kp - 1 * N_COLS); + round(inv_rnd, b0, b1, kp - 2 * N_COLS); + round(inv_rnd, b1, b0, kp - 3 * N_COLS); + round(inv_rnd, b0, b1, kp - 4 * N_COLS); + round(inv_rnd, b1, b0, kp - 5 * N_COLS); + round(inv_rnd, b0, b1, kp - 6 * N_COLS); + round(inv_rnd, b1, b0, kp - 7 * N_COLS); + round(inv_rnd, b0, b1, kp - 8 * N_COLS); + round(inv_rnd, b1, b0, kp - 9 * N_COLS); +#if defined(LAST_DEC_ROUND_CACHE_TABLES) + itables(t_il); +#endif + round(inv_lrnd, b0, b1, kp - 10 * N_COLS); + } + +#else + + { aes_32t rnd; +#if (DEC_UNROLL == PARTIAL) + for(rnd = 0; rnd < (cx->rn >> 1) - 1; ++rnd) + { + kp -= N_COLS; + round(inv_rnd, b1, b0, kp); + kp -= N_COLS; + round(inv_rnd, b0, b1, kp); + } + kp -= N_COLS; + round(inv_rnd, b1, b0, kp); +#else + for(rnd = 0; rnd < cx->rn - 1; ++rnd) + { + kp -= N_COLS; + round(inv_rnd, b1, b0, kp); + l_copy(b0, b1); + } +#endif +#if defined(LAST_DEC_ROUND_CACHE_TABLES) + itables(t_il); +#endif + kp -= N_COLS; + round(inv_lrnd, b0, b1, kp); + } +#endif + + if (num_blk == 1) + { + // We are doing the first block so we need the IV rather than the previous + // block for CBC (there is no previous block) + state_in(b1, in_iv); + } + else + { + in -= AES_BLOCK_SIZE; + state_in(b1, in); + } + + // Do the CBC with b1 which is either the IV or the ciphertext of the previous block. + cbc(b0, b1); + + state_out(out, b0); + } +#if defined( AES_ERR_CHK ) + return aes_good; +#endif +} + +#endif + +#if defined(__cplusplus) +} +#endif diff --git a/bootx.tproj/sl.subproj/aeskey.c b/bootx.tproj/sl.subproj/aeskey.c new file mode 100755 index 0000000..0120e0c --- /dev/null +++ b/bootx.tproj/sl.subproj/aeskey.c @@ -0,0 +1,455 @@ +/* + --------------------------------------------------------------------------- + Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved. + + LICENSE TERMS + + The free distribution and use of this software in both source and binary + form is allowed (with or without changes) provided that: + + 1. distributions of this source code include the above copyright + notice, this list of conditions and the following disclaimer; + + 2. distributions in binary form include the above copyright + notice, this list of conditions and the following disclaimer + in the documentation and/or other associated materials; + + 3. the copyright holder's name is not used to endorse products + built using this software without specific written permission. + + ALTERNATIVELY, provided that this notice is retained in full, this product + may be distributed under the terms of the GNU General Public License (GPL), + in which case the provisions of the GPL apply INSTEAD OF those given above. + + DISCLAIMER + + This software is provided 'as is' with no explicit or implied warranties + in respect of its properties, including, but not limited to, correctness + and/or fitness for purpose. + --------------------------------------------------------------------------- + Issue Date: 26/08/2003 + + This file contains the code for implementing the key schedule for AES + (Rijndael) for block and key sizes of 16, 24, and 32 bytes. See aesopt.h + for further details including optimisation. +*/ + +#include "aesopt.h" +#include "aestab.h" + +#if defined(__cplusplus) +extern "C" +{ +#endif + +/* Initialise the key schedule from the user supplied key. The key + length can be specified in bytes, with legal values of 16, 24 + and 32, or in bits, with legal values of 128, 192 and 256. These + values correspond with Nk values of 4, 6 and 8 respectively. + + The following macros implement a single cycle in the key + schedule generation process. The number of cycles needed + for each cx->n_col and nk value is: + + nk = 4 5 6 7 8 + ------------------------------ + cx->n_col = 4 10 9 8 7 7 + cx->n_col = 5 14 11 10 9 9 + cx->n_col = 6 19 15 12 11 11 + cx->n_col = 7 21 19 16 13 14 + cx->n_col = 8 29 23 19 17 14 +*/ + +#define ke4(k,i) \ +{ k[4*(i)+4] = ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[4*(i)+5] = ss[1] ^= ss[0]; \ + k[4*(i)+6] = ss[2] ^= ss[1]; k[4*(i)+7] = ss[3] ^= ss[2]; \ +} +#define kel4(k,i) \ +{ k[4*(i)+4] = ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[4*(i)+5] = ss[1] ^= ss[0]; \ + k[4*(i)+6] = ss[2] ^= ss[1]; k[4*(i)+7] = ss[3] ^= ss[2]; \ +} + +#define ke6(k,i) \ +{ k[6*(i)+ 6] = ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; k[6*(i)+ 7] = ss[1] ^= ss[0]; \ + k[6*(i)+ 8] = ss[2] ^= ss[1]; k[6*(i)+ 9] = ss[3] ^= ss[2]; \ + k[6*(i)+10] = ss[4] ^= ss[3]; k[6*(i)+11] = ss[5] ^= ss[4]; \ +} +#define kel6(k,i) \ +{ k[6*(i)+ 6] = ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; k[6*(i)+ 7] = ss[1] ^= ss[0]; \ + k[6*(i)+ 8] = ss[2] ^= ss[1]; k[6*(i)+ 9] = ss[3] ^= ss[2]; \ +} + +#define ke8(k,i) \ +{ k[8*(i)+ 8] = ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[8*(i)+ 9] = ss[1] ^= ss[0]; \ + k[8*(i)+10] = ss[2] ^= ss[1]; k[8*(i)+11] = ss[3] ^= ss[2]; \ + k[8*(i)+12] = ss[4] ^= ls_box(ss[3],0); k[8*(i)+13] = ss[5] ^= ss[4]; \ + k[8*(i)+14] = ss[6] ^= ss[5]; k[8*(i)+15] = ss[7] ^= ss[6]; \ +} +#define kel8(k,i) \ +{ k[8*(i)+ 8] = ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[8*(i)+ 9] = ss[1] ^= ss[0]; \ + k[8*(i)+10] = ss[2] ^= ss[1]; k[8*(i)+11] = ss[3] ^= ss[2]; \ +} + +#if defined(ENCRYPTION_KEY_SCHEDULE) + +#if defined(AES_128) || defined(AES_VAR) + +aes_rval aes_encrypt_key128(const unsigned char *key, aes_encrypt_ctx cx[1]) +{ aes_32t ss[4]; + + cx->ks[0] = ss[0] = word_in(key, 0); + cx->ks[1] = ss[1] = word_in(key, 1); + cx->ks[2] = ss[2] = word_in(key, 2); + cx->ks[3] = ss[3] = word_in(key, 3); + +#if ENC_UNROLL == NONE + { aes_32t i; + + for(i = 0; i < ((11 * N_COLS - 5) / 4); ++i) + ke4(cx->ks, i); + } +#else + ke4(cx->ks, 0); ke4(cx->ks, 1); + ke4(cx->ks, 2); ke4(cx->ks, 3); + ke4(cx->ks, 4); ke4(cx->ks, 5); + ke4(cx->ks, 6); ke4(cx->ks, 7); + ke4(cx->ks, 8); +#endif + kel4(cx->ks, 9); + cx->rn = 10; +#if defined( AES_ERR_CHK ) + return aes_good; +#endif +} + +#endif + +#if defined(AES_192) || defined(AES_VAR) + +aes_rval aes_encrypt_key192(const unsigned char *key, aes_encrypt_ctx cx[1]) +{ aes_32t ss[6]; + + cx->ks[0] = ss[0] = word_in(key, 0); + cx->ks[1] = ss[1] = word_in(key, 1); + cx->ks[2] = ss[2] = word_in(key, 2); + cx->ks[3] = ss[3] = word_in(key, 3); + cx->ks[4] = ss[4] = word_in(key, 4); + cx->ks[5] = ss[5] = word_in(key, 5); + +#if ENC_UNROLL == NONE + { aes_32t i; + + for(i = 0; i < (13 * N_COLS - 7) / 6; ++i) + ke6(cx->ks, i); + } +#else + ke6(cx->ks, 0); ke6(cx->ks, 1); + ke6(cx->ks, 2); ke6(cx->ks, 3); + ke6(cx->ks, 4); ke6(cx->ks, 5); + ke6(cx->ks, 6); +#endif + kel6(cx->ks, 7); + cx->rn = 12; +#if defined( AES_ERR_CHK ) + return aes_good; +#endif +} + +#endif + +#if defined(AES_256) || defined(AES_VAR) + +aes_rval aes_encrypt_key256(const unsigned char *key, aes_encrypt_ctx cx[1]) +{ aes_32t ss[8]; + + cx->ks[0] = ss[0] = word_in(key, 0); + cx->ks[1] = ss[1] = word_in(key, 1); + cx->ks[2] = ss[2] = word_in(key, 2); + cx->ks[3] = ss[3] = word_in(key, 3); + cx->ks[4] = ss[4] = word_in(key, 4); + cx->ks[5] = ss[5] = word_in(key, 5); + cx->ks[6] = ss[6] = word_in(key, 6); + cx->ks[7] = ss[7] = word_in(key, 7); + +#if ENC_UNROLL == NONE + { aes_32t i; + + for(i = 0; i < (15 * N_COLS - 9) / 8; ++i) + ke8(cx->ks, i); + } +#else + ke8(cx->ks, 0); ke8(cx->ks, 1); + ke8(cx->ks, 2); ke8(cx->ks, 3); + ke8(cx->ks, 4); ke8(cx->ks, 5); +#endif + kel8(cx->ks, 6); + cx->rn = 14; +#if defined( AES_ERR_CHK ) + return aes_good; +#endif +} + +#endif + +#if defined(AES_VAR) + +aes_rval aes_encrypt_key(const unsigned char *key, int key_len, aes_encrypt_ctx cx[1]) +{ + switch(key_len) + { +#if defined( AES_ERR_CHK ) + case 16: case 128: return aes_encrypt_key128(key, cx); + case 24: case 192: return aes_encrypt_key192(key, cx); + case 32: case 256: return aes_encrypt_key256(key, cx); + default: return aes_error; +#else + case 16: case 128: aes_encrypt_key128(key, cx); return; + case 24: case 192: aes_encrypt_key192(key, cx); return; + case 32: case 256: aes_encrypt_key256(key, cx); return; +#endif + } +} + +#endif + +#endif + +#if defined(DECRYPTION_KEY_SCHEDULE) + +#if DEC_ROUND == NO_TABLES +#define ff(x) (x) +#else +#define ff(x) inv_mcol(x) +#if defined( dec_imvars ) +#define d_vars dec_imvars +#endif +#endif + +#if 1 +#define kdf4(k,i) \ +{ ss[0] = ss[0] ^ ss[2] ^ ss[1] ^ ss[3]; ss[1] = ss[1] ^ ss[3]; ss[2] = ss[2] ^ ss[3]; ss[3] = ss[3]; \ + ss[4] = ls_box(ss[(i+3) % 4], 3) ^ t_use(r,c)[i]; ss[i % 4] ^= ss[4]; \ + ss[4] ^= k[4*(i)]; k[4*(i)+4] = ff(ss[4]); ss[4] ^= k[4*(i)+1]; k[4*(i)+5] = ff(ss[4]); \ + ss[4] ^= k[4*(i)+2]; k[4*(i)+6] = ff(ss[4]); ss[4] ^= k[4*(i)+3]; k[4*(i)+7] = ff(ss[4]); \ +} +#define kd4(k,i) \ +{ ss[4] = ls_box(ss[(i+3) % 4], 3) ^ t_use(r,c)[i]; ss[i % 4] ^= ss[4]; ss[4] = ff(ss[4]); \ + k[4*(i)+4] = ss[4] ^= k[4*(i)]; k[4*(i)+5] = ss[4] ^= k[4*(i)+1]; \ + k[4*(i)+6] = ss[4] ^= k[4*(i)+2]; k[4*(i)+7] = ss[4] ^= k[4*(i)+3]; \ +} +#define kdl4(k,i) \ +{ ss[4] = ls_box(ss[(i+3) % 4], 3) ^ t_use(r,c)[i]; ss[i % 4] ^= ss[4]; \ + k[4*(i)+4] = (ss[0] ^= ss[1]) ^ ss[2] ^ ss[3]; k[4*(i)+5] = ss[1] ^ ss[3]; \ + k[4*(i)+6] = ss[0]; k[4*(i)+7] = ss[1]; \ +} +#else +#define kdf4(k,i) \ +{ ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[4*(i)+ 4] = ff(ss[0]); ss[1] ^= ss[0]; k[4*(i)+ 5] = ff(ss[1]); \ + ss[2] ^= ss[1]; k[4*(i)+ 6] = ff(ss[2]); ss[3] ^= ss[2]; k[4*(i)+ 7] = ff(ss[3]); \ +} +#define kd4(k,i) \ +{ ss[4] = ls_box(ss[3],3) ^ t_use(r,c)[i]; \ + ss[0] ^= ss[4]; ss[4] = ff(ss[4]); k[4*(i)+ 4] = ss[4] ^= k[4*(i)]; \ + ss[1] ^= ss[0]; k[4*(i)+ 5] = ss[4] ^= k[4*(i)+ 1]; \ + ss[2] ^= ss[1]; k[4*(i)+ 6] = ss[4] ^= k[4*(i)+ 2]; \ + ss[3] ^= ss[2]; k[4*(i)+ 7] = ss[4] ^= k[4*(i)+ 3]; \ +} +#define kdl4(k,i) \ +{ ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[4*(i)+ 4] = ss[0]; ss[1] ^= ss[0]; k[4*(i)+ 5] = ss[1]; \ + ss[2] ^= ss[1]; k[4*(i)+ 6] = ss[2]; ss[3] ^= ss[2]; k[4*(i)+ 7] = ss[3]; \ +} +#endif + +#define kdf6(k,i) \ +{ ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; k[6*(i)+ 6] = ff(ss[0]); ss[1] ^= ss[0]; k[6*(i)+ 7] = ff(ss[1]); \ + ss[2] ^= ss[1]; k[6*(i)+ 8] = ff(ss[2]); ss[3] ^= ss[2]; k[6*(i)+ 9] = ff(ss[3]); \ + ss[4] ^= ss[3]; k[6*(i)+10] = ff(ss[4]); ss[5] ^= ss[4]; k[6*(i)+11] = ff(ss[5]); \ +} +#define kd6(k,i) \ +{ ss[6] = ls_box(ss[5],3) ^ t_use(r,c)[i]; \ + ss[0] ^= ss[6]; ss[6] = ff(ss[6]); k[6*(i)+ 6] = ss[6] ^= k[6*(i)]; \ + ss[1] ^= ss[0]; k[6*(i)+ 7] = ss[6] ^= k[6*(i)+ 1]; \ + ss[2] ^= ss[1]; k[6*(i)+ 8] = ss[6] ^= k[6*(i)+ 2]; \ + ss[3] ^= ss[2]; k[6*(i)+ 9] = ss[6] ^= k[6*(i)+ 3]; \ + ss[4] ^= ss[3]; k[6*(i)+10] = ss[6] ^= k[6*(i)+ 4]; \ + ss[5] ^= ss[4]; k[6*(i)+11] = ss[6] ^= k[6*(i)+ 5]; \ +} +#define kdl6(k,i) \ +{ ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; k[6*(i)+ 6] = ss[0]; ss[1] ^= ss[0]; k[6*(i)+ 7] = ss[1]; \ + ss[2] ^= ss[1]; k[6*(i)+ 8] = ss[2]; ss[3] ^= ss[2]; k[6*(i)+ 9] = ss[3]; \ +} + +#define kdf8(k,i) \ +{ ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[8*(i)+ 8] = ff(ss[0]); ss[1] ^= ss[0]; k[8*(i)+ 9] = ff(ss[1]); \ + ss[2] ^= ss[1]; k[8*(i)+10] = ff(ss[2]); ss[3] ^= ss[2]; k[8*(i)+11] = ff(ss[3]); \ + ss[4] ^= ls_box(ss[3],0); k[8*(i)+12] = ff(ss[4]); ss[5] ^= ss[4]; k[8*(i)+13] = ff(ss[5]); \ + ss[6] ^= ss[5]; k[8*(i)+14] = ff(ss[6]); ss[7] ^= ss[6]; k[8*(i)+15] = ff(ss[7]); \ +} +#define kd8(k,i) \ +{ aes_32t g = ls_box(ss[7],3) ^ t_use(r,c)[i]; \ + ss[0] ^= g; g = ff(g); k[8*(i)+ 8] = g ^= k[8*(i)]; \ + ss[1] ^= ss[0]; k[8*(i)+ 9] = g ^= k[8*(i)+ 1]; \ + ss[2] ^= ss[1]; k[8*(i)+10] = g ^= k[8*(i)+ 2]; \ + ss[3] ^= ss[2]; k[8*(i)+11] = g ^= k[8*(i)+ 3]; \ + g = ls_box(ss[3],0); \ + ss[4] ^= g; g = ff(g); k[8*(i)+12] = g ^= k[8*(i)+ 4]; \ + ss[5] ^= ss[4]; k[8*(i)+13] = g ^= k[8*(i)+ 5]; \ + ss[6] ^= ss[5]; k[8*(i)+14] = g ^= k[8*(i)+ 6]; \ + ss[7] ^= ss[6]; k[8*(i)+15] = g ^= k[8*(i)+ 7]; \ +} +#define kdl8(k,i) \ +{ ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[8*(i)+ 8] = ss[0]; ss[1] ^= ss[0]; k[8*(i)+ 9] = ss[1]; \ + ss[2] ^= ss[1]; k[8*(i)+10] = ss[2]; ss[3] ^= ss[2]; k[8*(i)+11] = ss[3]; \ +} + +#if defined(AES_128) || defined(AES_VAR) + +aes_rval aes_decrypt_key128(const unsigned char *key, aes_decrypt_ctx cx[1]) +{ aes_32t ss[5]; +#if defined( d_vars ) + d_vars; +#endif + cx->ks[0] = ss[0] = word_in(key, 0); + cx->ks[1] = ss[1] = word_in(key, 1); + cx->ks[2] = ss[2] = word_in(key, 2); + cx->ks[3] = ss[3] = word_in(key, 3); + +#if DEC_UNROLL == NONE + { aes_32t i; + + for(i = 0; i < (11 * N_COLS - 5) / 4; ++i) + ke4(cx->ks, i); + kel4(cx->ks, 9); +#if !(DEC_ROUND == NO_TABLES) + for(i = N_COLS; i < 10 * N_COLS; ++i) + cx->ks[i] = inv_mcol(cx->ks[i]); +#endif + } +#else + kdf4(cx->ks, 0); kd4(cx->ks, 1); + kd4(cx->ks, 2); kd4(cx->ks, 3); + kd4(cx->ks, 4); kd4(cx->ks, 5); + kd4(cx->ks, 6); kd4(cx->ks, 7); + kd4(cx->ks, 8); kdl4(cx->ks, 9); +#endif + cx->rn = 10; +#if defined( AES_ERR_CHK ) + return aes_good; +#endif +} + +#endif + +#if defined(AES_192) || defined(AES_VAR) + +aes_rval aes_decrypt_key192(const unsigned char *key, aes_decrypt_ctx cx[1]) +{ aes_32t ss[7]; +#if defined( d_vars ) + d_vars; +#endif + cx->ks[0] = ss[0] = word_in(key, 0); + cx->ks[1] = ss[1] = word_in(key, 1); + cx->ks[2] = ss[2] = word_in(key, 2); + cx->ks[3] = ss[3] = word_in(key, 3); + +#if DEC_UNROLL == NONE + cx->ks[4] = ss[4] = word_in(key, 4); + cx->ks[5] = ss[5] = word_in(key, 5); + { aes_32t i; + + for(i = 0; i < (13 * N_COLS - 7) / 6; ++i) + ke6(cx->ks, i); + kel6(cx->ks, 7); +#if !(DEC_ROUND == NO_TABLES) + for(i = N_COLS; i < 12 * N_COLS; ++i) + cx->ks[i] = inv_mcol(cx->ks[i]); +#endif + } +#else + cx->ks[4] = ff(ss[4] = word_in(key, 4)); + cx->ks[5] = ff(ss[5] = word_in(key, 5)); + kdf6(cx->ks, 0); kd6(cx->ks, 1); + kd6(cx->ks, 2); kd6(cx->ks, 3); + kd6(cx->ks, 4); kd6(cx->ks, 5); + kd6(cx->ks, 6); kdl6(cx->ks, 7); +#endif + cx->rn = 12; +#if defined( AES_ERR_CHK ) + return aes_good; +#endif +} + +#endif + +#if defined(AES_256) || defined(AES_VAR) + +aes_rval aes_decrypt_key256(const unsigned char *key, aes_decrypt_ctx cx[1]) +{ aes_32t ss[8]; +#if defined( d_vars ) + d_vars; +#endif + cx->ks[0] = ss[0] = word_in(key, 0); + cx->ks[1] = ss[1] = word_in(key, 1); + cx->ks[2] = ss[2] = word_in(key, 2); + cx->ks[3] = ss[3] = word_in(key, 3); + +#if DEC_UNROLL == NONE + cx->ks[4] = ss[4] = word_in(key, 4); + cx->ks[5] = ss[5] = word_in(key, 5); + cx->ks[6] = ss[6] = word_in(key, 6); + cx->ks[7] = ss[7] = word_in(key, 7); + { aes_32t i; + + for(i = 0; i < (15 * N_COLS - 9) / 8; ++i) + ke8(cx->ks, i); + kel8(cx->ks, i); +#if !(DEC_ROUND == NO_TABLES) + for(i = N_COLS; i < 14 * N_COLS; ++i) + cx->ks[i] = inv_mcol(cx->ks[i]); + +#endif + } +#else + cx->ks[4] = ff(ss[4] = word_in(key, 4)); + cx->ks[5] = ff(ss[5] = word_in(key, 5)); + cx->ks[6] = ff(ss[6] = word_in(key, 6)); + cx->ks[7] = ff(ss[7] = word_in(key, 7)); + kdf8(cx->ks, 0); kd8(cx->ks, 1); + kd8(cx->ks, 2); kd8(cx->ks, 3); + kd8(cx->ks, 4); kd8(cx->ks, 5); + kdl8(cx->ks, 6); +#endif + cx->rn = 14; +#if defined( AES_ERR_CHK ) + return aes_good; +#endif +} + +#endif + +#if defined(AES_VAR) + +aes_rval aes_decrypt_key(const unsigned char *key, int key_len, aes_decrypt_ctx cx[1]) +{ + switch(key_len) + { +#if defined( AES_ERR_CHK ) + case 16: case 128: return aes_decrypt_key128(key, cx); + case 24: case 192: return aes_decrypt_key192(key, cx); + case 32: case 256: return aes_decrypt_key256(key, cx); + default: return aes_error; +#else + case 16: case 128: aes_decrypt_key128(key, cx); return; + case 24: case 192: aes_decrypt_key192(key, cx); return; + case 32: case 256: aes_decrypt_key256(key, cx); return; +#endif + } +} + +#endif + +#endif + +#if defined(__cplusplus) +} +#endif diff --git a/bootx.tproj/sl.subproj/aesopt.h b/bootx.tproj/sl.subproj/aesopt.h new file mode 100755 index 0000000..7b2ea04 --- /dev/null +++ b/bootx.tproj/sl.subproj/aesopt.h @@ -0,0 +1,753 @@ +/* + --------------------------------------------------------------------------- + Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved. + + LICENSE TERMS + + The free distribution and use of this software in both source and binary + form is allowed (with or without changes) provided that: + + 1. distributions of this source code include the above copyright + notice, this list of conditions and the following disclaimer; + + 2. distributions in binary form include the above copyright + notice, this list of conditions and the following disclaimer + in the documentation and/or other associated materials; + + 3. the copyright holder's name is not used to endorse products + built using this software without specific written permission. + + ALTERNATIVELY, provided that this notice is retained in full, this product + may be distributed under the terms of the GNU General Public License (GPL), + in which case the provisions of the GPL apply INSTEAD OF those given above. + + DISCLAIMER + + This software is provided 'as is' with no explicit or implied warranties + in respect of its properties, including, but not limited to, correctness + and/or fitness for purpose. + --------------------------------------------------------------------------- + Issue 28/01/2004 + + My thanks go to Dag Arne Osvik for devising the schemes used here for key + length derivation from the form of the key schedule + + This file contains the compilation options for AES (Rijndael) and code + that is common across encryption, key scheduling and table generation. + + OPERATION + + These source code files implement the AES algorithm Rijndael designed by + Joan Daemen and Vincent Rijmen. This version is designed for the standard + block size of 16 bytes and for key sizes of 128, 192 and 256 bits (16, 24 + and 32 bytes). + + This version is designed for flexibility and speed using operations on + 32-bit words rather than operations on bytes. It can be compiled with + either big or little endian internal byte order but is faster when the + native byte order for the processor is used. + + THE CIPHER INTERFACE + + The cipher interface is implemented as an array of bytes in which lower + AES bit sequence indexes map to higher numeric significance within bytes. + + aes_08t (an unsigned 8-bit type) + aes_32t (an unsigned 32-bit type) + struct aes_encrypt_ctx (structure for the cipher encryption context) + struct aes_decrypt_ctx (structure for the cipher decryption context) + aes_rval the function return type + + C subroutine calls: + + aes_rval aes_encrypt_key128(const unsigned char *key, aes_encrypt_ctx cx[1]); + aes_rval aes_encrypt_key192(const unsigned char *key, aes_encrypt_ctx cx[1]); + aes_rval aes_encrypt_key256(const unsigned char *key, aes_encrypt_ctx cx[1]); + aes_rval aes_encrypt(const unsigned char *in, unsigned char *out, + const aes_encrypt_ctx cx[1]); + + aes_rval aes_decrypt_key128(const unsigned char *key, aes_decrypt_ctx cx[1]); + aes_rval aes_decrypt_key192(const unsigned char *key, aes_decrypt_ctx cx[1]); + aes_rval aes_decrypt_key256(const unsigned char *key, aes_decrypt_ctx cx[1]); + aes_rval aes_decrypt(const unsigned char *in, unsigned char *out, + const aes_decrypt_ctx cx[1]); + + IMPORTANT NOTE: If you are using this C interface with dynamic tables make sure that + you call genTabs() before AES is used so that the tables are initialised. + + C++ aes class subroutines: + + Class AESencrypt for encryption + + Construtors: + AESencrypt(void) + AESencrypt(const unsigned char *key) - 128 bit key + Members: + aes_rval key128(const unsigned char *key) + aes_rval key192(const unsigned char *key) + aes_rval key256(const unsigned char *key) + aes_rval encrypt(const unsigned char *in, unsigned char *out) const + + Class AESdecrypt for encryption + Construtors: + AESdecrypt(void) + AESdecrypt(const unsigned char *key) - 128 bit key + Members: + aes_rval key128(const unsigned char *key) + aes_rval key192(const unsigned char *key) + aes_rval key256(const unsigned char *key) + aes_rval decrypt(const unsigned char *in, unsigned char *out) const + + COMPILATION + + The files used to provide AES (Rijndael) are + + a. aes.h for the definitions needed for use in C. + b. aescpp.h for the definitions needed for use in C++. + c. aesopt.h for setting compilation options (also includes common code). + d. aescrypt.c for encryption and decrytpion, or + e. aeskey.c for key scheduling. + f. aestab.c for table loading or generation. + g. aescrypt.asm for encryption and decryption using assembler code. + h. aescrypt.mmx.asm for encryption and decryption using MMX assembler. + + To compile AES (Rijndael) for use in C code use aes.h and set the + defines here for the facilities you need (key lengths, encryption + and/or decryption). Do not define AES_DLL or AES_CPP. Set the options + for optimisations and table sizes here. + + To compile AES (Rijndael) for use in in C++ code use aescpp.h but do + not define AES_DLL + + To compile AES (Rijndael) in C as a Dynamic Link Library DLL) use + aes.h and include the AES_DLL define. + + CONFIGURATION OPTIONS (here and in aes.h) + + a. set AES_DLL in aes.h if AES (Rijndael) is to be compiled as a DLL + b. You may need to set PLATFORM_BYTE_ORDER to define the byte order. + c. If you want the code to run in a specific internal byte order, then + ALGORITHM_BYTE_ORDER must be set accordingly. + d. set other configuration options decribed below. +*/ + +#if !defined( _AESOPT_H ) +#define _AESOPT_H + +#include "aes.h" + +/* CONFIGURATION - USE OF DEFINES + + Later in this section there are a number of defines that control the + operation of the code. In each section, the purpose of each define is + explained so that the relevant form can be included or excluded by + setting either 1's or 0's respectively on the branches of the related + #if clauses. + + PLATFORM SPECIFIC INCLUDES AND BYTE ORDER IN 32-BIT WORDS + + To obtain the highest speed on processors with 32-bit words, this code + needs to determine the byte order of the target machine. The following + block of code is an attempt to capture the most obvious ways in which + various environemnts define byte order. It may well fail, in which case + the definitions will need to be set by editing at the points marked + **** EDIT HERE IF NECESSARY **** below. My thanks go to Peter Gutmann + for his assistance with this endian detection nightmare. +*/ + +#define BRG_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */ +#define BRG_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */ + +#if defined(__GNUC__) || defined(__GNU_LIBRARY__) +# if defined(__FreeBSD__) || defined(__OpenBSD__) +# include +# elif defined( BSD ) && BSD >= 199103 +# include +# elif defined(__APPLE__) +# if defined(__BIG_ENDIAN__) && !defined( BIG_ENDIAN ) +# define BIG_ENDIAN +# elif defined(__LITTLE_ENDIAN__) && !defined( LITTLE_ENDIAN ) +# define LITTLE_ENDIAN +# endif +# else +# include +# if defined(__BEOS__) +# include +# endif +# endif +#endif + +#if !defined(PLATFORM_BYTE_ORDER) +# if defined(LITTLE_ENDIAN) || defined(BIG_ENDIAN) +# if defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) +# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN +# elif !defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) +# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN +# elif defined(BYTE_ORDER) && (BYTE_ORDER == LITTLE_ENDIAN) +# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN +# elif defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN) +# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN +# endif +# elif defined(_LITTLE_ENDIAN) || defined(_BIG_ENDIAN) +# if defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) +# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN +# elif !defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN) +# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN +# elif defined(_BYTE_ORDER) && (_BYTE_ORDER == _LITTLE_ENDIAN) +# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN +# elif defined(_BYTE_ORDER) && (_BYTE_ORDER == _BIG_ENDIAN) +# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN +# endif +# elif defined(__LITTLE_ENDIAN__) || defined(__BIG_ENDIAN__) +# if defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) +# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN +# elif !defined(__LITTLE_ENDIAN__) && defined(__BIG_ENDIAN__) +# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN +# elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __LITTLE_ENDIAN__) +# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN +# elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __BIG_ENDIAN__) +# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN +# endif +# endif +#endif + +/* if the platform is still unknown, try to find its byte order */ +/* from commonly used machine defines */ + +#if !defined(PLATFORM_BYTE_ORDER) + +#if defined( __alpha__ ) || defined( __alpha ) || defined( i386 ) || \ + defined( __i386__ ) || defined( _M_I86 ) || defined( _M_IX86 ) || \ + defined( __OS2__ ) || defined( sun386 ) || defined( __TURBOC__ ) || \ + defined( vax ) || defined( vms ) || defined( VMS ) || \ + defined( __VMS ) +# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN + +#elif defined( AMIGA ) || defined( applec ) || defined( __AS400__ ) || \ + defined( _CRAY ) || defined( __hppa ) || defined( __hp9000 ) || \ + defined( ibm370 ) || defined( mc68000 ) || defined( m68k ) || \ + defined( __MRC__ ) || defined( __MVS__ ) || defined( __MWERKS__ ) || \ + defined( sparc ) || defined( __sparc) || defined( SYMANTEC_C ) || \ + defined( __TANDEM ) || defined( THINK_C ) || defined( __VMCMS__ ) +# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN + +#elif 0 /* **** EDIT HERE IF NECESSARY **** */ +# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN +#elif 0 /* **** EDIT HERE IF NECESSARY **** */ +# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN +#else +# error Please edit aesopt.h (line 234 or 236) to set the platform byte order +#endif + +#endif + +/* SOME LOCAL DEFINITIONS */ + +#define NO_TABLES 0 +#define ONE_TABLE 1 +#define FOUR_TABLES 4 +#define NONE 0 +#define PARTIAL 1 +#define FULL 2 + +#if defined(bswap32) +#define aes_sw32 bswap32 +#elif defined(bswap_32) +#define aes_sw32 bswap_32 +#else +#define brot(x,n) (((aes_32t)(x) << n) | ((aes_32t)(x) >> (32 - n))) +#define aes_sw32(x) ((brot((x),8) & 0x00ff00ff) | (brot((x),24) & 0xff00ff00)) +#endif + +/* 1. FUNCTIONS REQUIRED + + This implementation provides subroutines for encryption, decryption + and for setting the three key lengths (separately) for encryption + and decryption. When the assembler code is not being used the following + definition blocks allow the selection of the routines that are to be + included in the compilation. +*/ +#if defined( AES_ENCRYPT ) +#define ENCRYPTION +#define ENCRYPTION_KEY_SCHEDULE +#endif + +#if defined( AES_DECRYPT ) +#define DECRYPTION +#define DECRYPTION_KEY_SCHEDULE +#endif + +/* 2. ASSEMBLER SUPPORT + + This define (which can be on the command line) enables the use of the + assembler code routines for encryption and decryption with the C code + only providing key scheduling +*/ +#if 0 && !defined(AES_ASM) +#define AES_ASM +#endif + +/* 3. BYTE ORDER WITHIN 32 BIT WORDS + + The fundamental data processing units in Rijndael are 8-bit bytes. The + input, output and key input are all enumerated arrays of bytes in which + bytes are numbered starting at zero and increasing to one less than the + number of bytes in the array in question. This enumeration is only used + for naming bytes and does not imply any adjacency or order relationship + from one byte to another. When these inputs and outputs are considered + as bit sequences, bits 8*n to 8*n+7 of the bit sequence are mapped to + byte[n] with bit 8n+i in the sequence mapped to bit 7-i within the byte. + In this implementation bits are numbered from 0 to 7 starting at the + numerically least significant end of each byte (bit n represents 2^n). + + However, Rijndael can be implemented more efficiently using 32-bit + words by packing bytes into words so that bytes 4*n to 4*n+3 are placed + into word[n]. While in principle these bytes can be assembled into words + in any positions, this implementation only supports the two formats in + which bytes in adjacent positions within words also have adjacent byte + numbers. This order is called big-endian if the lowest numbered bytes + in words have the highest numeric significance and little-endian if the + opposite applies. + + This code can work in either order irrespective of the order used by the + machine on which it runs. Normally the internal byte order will be set + to the order of the processor on which the code is to be run but this + define can be used to reverse this in special situations + + NOTE: Assembler code versions rely on PLATFORM_BYTE_ORDER being set +*/ +#if 1 || defined(AES_ASM) +#define ALGORITHM_BYTE_ORDER PLATFORM_BYTE_ORDER +#elif 0 +#define ALGORITHM_BYTE_ORDER BRG_LITTLE_ENDIAN +#elif 0 +#define ALGORITHM_BYTE_ORDER BRG_BIG_ENDIAN +#else +#error The algorithm byte order is not defined +#endif + +/* 4. FAST INPUT/OUTPUT OPERATIONS. + + On some machines it is possible to improve speed by transferring the + bytes in the input and output arrays to and from the internal 32-bit + variables by addressing these arrays as if they are arrays of 32-bit + words. On some machines this will always be possible but there may + be a large performance penalty if the byte arrays are not aligned on + the normal word boundaries. On other machines this technique will + lead to memory access errors when such 32-bit word accesses are not + properly aligned. The option SAFE_IO avoids such problems but will + often be slower on those machines that support misaligned access + (especially so if care is taken to align the input and output byte + arrays on 32-bit word boundaries). If SAFE_IO is not defined it is + assumed that access to byte arrays as if they are arrays of 32-bit + words will not cause problems when such accesses are misaligned. +*/ +#if 0 && !defined(_MSC_VER) +#define SAFE_IO +#endif + +/* 5. LOOP UNROLLING + + The code for encryption and decrytpion cycles through a number of rounds + that can be implemented either in a loop or by expanding the code into a + long sequence of instructions, the latter producing a larger program but + one that will often be much faster. The latter is called loop unrolling. + There are also potential speed advantages in expanding two iterations in + a loop with half the number of iterations, which is called partial loop + unrolling. The following options allow partial or full loop unrolling + to be set independently for encryption and decryption +*/ +#if 1 +#define ENC_UNROLL FULL +#elif 0 +#define ENC_UNROLL PARTIAL +#else +#define ENC_UNROLL NONE +#endif + +#if 1 +#define DEC_UNROLL FULL +#elif 0 +#define DEC_UNROLL PARTIAL +#else +#define DEC_UNROLL NONE +#endif + +/* 6. FAST FINITE FIELD OPERATIONS + + If this section is included, tables are used to provide faster finite + field arithmetic (this has no effect if FIXED_TABLES is defined). +*/ +#if 1 +#define FF_TABLES +#endif + +/* 7. INTERNAL STATE VARIABLE FORMAT + + The internal state of Rijndael is stored in a number of local 32-bit + word varaibles which can be defined either as an array or as individual + names variables. Include this section if you want to store these local + varaibles in arrays. Otherwise individual local variables will be used. +*/ +#if 0 +#define ARRAYS +#endif + +/* In this implementation the columns of the state array are each held in + 32-bit words. The state array can be held in various ways: in an array + of words, in a number of individual word variables or in a number of + processor registers. The following define maps a variable name x and + a column number c to the way the state array variable is to be held. + The first define below maps the state into an array x[c] whereas the + second form maps the state into a number of individual variables x0, + x1, etc. Another form could map individual state colums to machine + register names. +*/ + +#if defined(ARRAYS) +#define s(x,c) x[c] +#else +#define s(x,c) x##c +#endif + +/* 8. FIXED OR DYNAMIC TABLES + + When this section is included the tables used by the code are compiled + statically into the binary file. Otherwise the subroutine gen_tabs() + must be called to compute them before the code is first used. +*/ +#if 1 +#define FIXED_TABLES +#endif + +/* 9. TABLE ALIGNMENT + + On some sytsems speed will be improved by aligning the AES large lookup + tables on particular boundaries. This define should be set to a power of + two giving the desired alignment. It can be left undefined if alignment + is not needed. This option is specific to the Microsft VC++ compiler - + it seems to sometimes cause trouble for the VC++ version 6 compiler. +*/ + +#if 0 && defined(_MSC_VER) && (_MSC_VER >= 1300) +#define TABLE_ALIGN 64 +#endif + +/* 10. INTERNAL TABLE CONFIGURATION + + This cipher proceeds by repeating in a number of cycles known as 'rounds' + which are implemented by a round function which can optionally be speeded + up using tables. The basic tables are each 256 32-bit words, with either + one or four tables being required for each round function depending on + how much speed is required. The encryption and decryption round functions + are different and the last encryption and decrytpion round functions are + different again making four different round functions in all. + + This means that: + 1. Normal encryption and decryption rounds can each use either 0, 1 + or 4 tables and table spaces of 0, 1024 or 4096 bytes each. + 2. The last encryption and decryption rounds can also use either 0, 1 + or 4 tables and table spaces of 0, 1024 or 4096 bytes each. + + Include or exclude the appropriate definitions below to set the number + of tables used by this implementation. +*/ + +#if 1 /* set tables for the normal encryption round */ +#define ENC_ROUND FOUR_TABLES +#elif 0 +#define ENC_ROUND ONE_TABLE +#else +#define ENC_ROUND NO_TABLES +#endif + +#if 1 /* set tables for the last encryption round */ +#define LAST_ENC_ROUND FOUR_TABLES +#elif 0 +#define LAST_ENC_ROUND ONE_TABLE +#else +#define LAST_ENC_ROUND NO_TABLES +#endif + +#if 1 /* set tables for the normal decryption round */ +#define DEC_ROUND FOUR_TABLES +#elif 0 +#define DEC_ROUND ONE_TABLE +#else +#define DEC_ROUND NO_TABLES +#endif + +#if 1 /* set tables for the last decryption round */ +#define LAST_DEC_ROUND FOUR_TABLES +#elif 0 +#define LAST_DEC_ROUND ONE_TABLE +#else +#define LAST_DEC_ROUND NO_TABLES +#endif + +/* The decryption key schedule can be speeded up with tables in the same + way that the round functions can. Include or exclude the following + defines to set this requirement. +*/ +#if 1 +#define KEY_SCHED FOUR_TABLES +#elif 0 +#define KEY_SCHED ONE_TABLE +#else +#define KEY_SCHED NO_TABLES +#endif + +/* 11. TABLE POINTER CACHING + + Normally tables are referenced directly, Enable this option if you wish to + cache pointers to the tables in the encrypt/decrypt code. Note that this + only works if you are using FOUR_TABLES for the ROUND you enable this for. +*/ +#if 1 +#define ENC_ROUND_CACHE_TABLES +#endif +#if 1 +#define LAST_ENC_ROUND_CACHE_TABLES +#endif +#if 1 +#define DEC_ROUND_CACHE_TABLES +#endif +#if 1 +#define LAST_DEC_ROUND_CACHE_TABLES +#endif + + +/* END OF CONFIGURATION OPTIONS */ + +#define RC_LENGTH (5 * (AES_BLOCK_SIZE / 4 - 2)) + +/* Disable or report errors on some combinations of options */ + +#if ENC_ROUND == NO_TABLES && LAST_ENC_ROUND != NO_TABLES +#undef LAST_ENC_ROUND +#define LAST_ENC_ROUND NO_TABLES +#elif ENC_ROUND == ONE_TABLE && LAST_ENC_ROUND == FOUR_TABLES +#undef LAST_ENC_ROUND +#define LAST_ENC_ROUND ONE_TABLE +#endif + +#if ENC_ROUND == NO_TABLES && ENC_UNROLL != NONE +#undef ENC_UNROLL +#define ENC_UNROLL NONE +#endif + +#if DEC_ROUND == NO_TABLES && LAST_DEC_ROUND != NO_TABLES +#undef LAST_DEC_ROUND +#define LAST_DEC_ROUND NO_TABLES +#elif DEC_ROUND == ONE_TABLE && LAST_DEC_ROUND == FOUR_TABLES +#undef LAST_DEC_ROUND +#define LAST_DEC_ROUND ONE_TABLE +#endif + +#if DEC_ROUND == NO_TABLES && DEC_UNROLL != NONE +#undef DEC_UNROLL +#define DEC_UNROLL NONE +#endif + +/* upr(x,n): rotates bytes within words by n positions, moving bytes to + higher index positions with wrap around into low positions + ups(x,n): moves bytes by n positions to higher index positions in + words but without wrap around + bval(x,n): extracts a byte from a word + + NOTE: The definitions given here are intended only for use with + unsigned variables and with shift counts that are compile + time constants +*/ + +#if (ALGORITHM_BYTE_ORDER == BRG_LITTLE_ENDIAN) +#define upr(x,n) (((aes_32t)(x) << (8 * (n))) | ((aes_32t)(x) >> (32 - 8 * (n)))) +#define ups(x,n) ((aes_32t) (x) << (8 * (n))) +#define bval(x,n) ((aes_08t)((x) >> (8 * (n)))) +#define bytes2word(b0, b1, b2, b3) \ + (((aes_32t)(b3) << 24) | ((aes_32t)(b2) << 16) | ((aes_32t)(b1) << 8) | (b0)) +#endif + +#if (ALGORITHM_BYTE_ORDER == BRG_BIG_ENDIAN) +#define upr(x,n) (((aes_32t)(x) >> (8 * (n))) | ((aes_32t)(x) << (32 - 8 * (n)))) +#define ups(x,n) ((aes_32t) (x) >> (8 * (n)))) +#define bval(x,n) ((aes_08t)((x) >> (24 - 8 * (n)))) +#define bytes2word(b0, b1, b2, b3) \ + (((aes_32t)(b0) << 24) | ((aes_32t)(b1) << 16) | ((aes_32t)(b2) << 8) | (b3)) +#endif + +#if defined(SAFE_IO) + +#define word_in(x,c) bytes2word(((aes_08t*)(x)+4*c)[0], ((aes_08t*)(x)+4*c)[1], \ + ((aes_08t*)(x)+4*c)[2], ((aes_08t*)(x)+4*c)[3]) +#define word_out(x,c,v) { ((aes_08t*)(x)+4*c)[0] = bval(v,0); ((aes_08t*)(x)+4*c)[1] = bval(v,1); \ + ((aes_08t*)(x)+4*c)[2] = bval(v,2); ((aes_08t*)(x)+4*c)[3] = bval(v,3); } + +#elif (ALGORITHM_BYTE_ORDER == PLATFORM_BYTE_ORDER) + +#define word_in(x,c) (*((aes_32t*)(x)+(c))) +#define word_out(x,c,v) (*((aes_32t*)(x)+(c)) = (v)) + +#else + +#define word_in(x,c) aes_sw32(*((aes_32t*)(x)+(c))) +#define word_out(x,c,v) (*((aes_32t*)(x)+(c)) = aes_sw32(v)) + +#endif + +/* the finite field modular polynomial and elements */ + +#define WPOLY 0x011b +#define BPOLY 0x1b + +/* multiply four bytes in GF(2^8) by 'x' {02} in parallel */ + +#define m1 0x80808080 +#define m2 0x7f7f7f7f +#define gf_mulx(x) ((((x) & m2) << 1) ^ ((((x) & m1) >> 7) * BPOLY)) + +/* The following defines provide alternative definitions of gf_mulx that might + give improved performance if a fast 32-bit multiply is not available. Note + that a temporary variable u needs to be defined where gf_mulx is used. + +#define gf_mulx(x) (u = (x) & m1, u |= (u >> 1), ((x) & m2) << 1) ^ ((u >> 3) | (u >> 6)) +#define m4 (0x01010101 * BPOLY) +#define gf_mulx(x) (u = (x) & m1, ((x) & m2) << 1) ^ ((u - (u >> 7)) & m4) +*/ + +/* Work out which tables are needed for the different options */ + +#if defined( AES_ASM ) +#if defined( ENC_ROUND ) +#undef ENC_ROUND +#endif +#define ENC_ROUND FOUR_TABLES +#if defined( LAST_ENC_ROUND ) +#undef LAST_ENC_ROUND +#endif +#define LAST_ENC_ROUND FOUR_TABLES +#if defined( DEC_ROUND ) +#undef DEC_ROUND +#endif +#define DEC_ROUND FOUR_TABLES +#if defined( LAST_DEC_ROUND ) +#undef LAST_DEC_ROUND +#endif +#define LAST_DEC_ROUND FOUR_TABLES +#if defined( KEY_SCHED ) +#undef KEY_SCHED +#define KEY_SCHED FOUR_TABLES +#endif +#endif + +#if defined(ENCRYPTION) || defined(AES_ASM) +#if ENC_ROUND == ONE_TABLE +#define FT1_SET +#elif ENC_ROUND == FOUR_TABLES +#define FT4_SET +#else +#define SBX_SET +#endif +#if LAST_ENC_ROUND == ONE_TABLE +#define FL1_SET +#elif LAST_ENC_ROUND == FOUR_TABLES +#define FL4_SET +#elif !defined(SBX_SET) +#define SBX_SET +#endif +#endif + +#if defined(DECRYPTION) || defined(AES_ASM) +#if DEC_ROUND == ONE_TABLE +#define IT1_SET +#elif DEC_ROUND == FOUR_TABLES +#define IT4_SET +#else +#define ISB_SET +#endif +#if LAST_DEC_ROUND == ONE_TABLE +#define IL1_SET +#elif LAST_DEC_ROUND == FOUR_TABLES +#define IL4_SET +#elif !defined(ISB_SET) +#define ISB_SET +#endif +#endif + +#if defined(ENCRYPTION_KEY_SCHEDULE) || defined(DECRYPTION_KEY_SCHEDULE) +#if KEY_SCHED == ONE_TABLE +#define LS1_SET +#define IM1_SET +#elif KEY_SCHED == FOUR_TABLES +#define LS4_SET +#define IM4_SET +#elif !defined(SBX_SET) +#define SBX_SET +#endif +#endif + +/* generic definitions of Rijndael macros that use tables */ + +#define no_table(x,box,vf,rf,c) bytes2word( \ + box[bval(vf(x,0,c),rf(0,c))], \ + box[bval(vf(x,1,c),rf(1,c))], \ + box[bval(vf(x,2,c),rf(2,c))], \ + box[bval(vf(x,3,c),rf(3,c))]) + +#define one_table(x,op,tab,vf,rf,c) \ + ( tab[bval(vf(x,0,c),rf(0,c))] \ + ^ op(tab[bval(vf(x,1,c),rf(1,c))],1) \ + ^ op(tab[bval(vf(x,2,c),rf(2,c))],2) \ + ^ op(tab[bval(vf(x,3,c),rf(3,c))],3)) + +#define four_tables(x,tab,vf,rf,c) \ + ( tab[0][bval(vf(x,0,c),rf(0,c))] \ + ^ tab[1][bval(vf(x,1,c),rf(1,c))] \ + ^ tab[2][bval(vf(x,2,c),rf(2,c))] \ + ^ tab[3][bval(vf(x,3,c),rf(3,c))]) + +#define four_cached_tables(x,tab,vf,rf,c) \ +( tab##0[bval(vf(x,0,c),rf(0,c))] \ + ^ tab##1[bval(vf(x,1,c),rf(1,c))] \ + ^ tab##2[bval(vf(x,2,c),rf(2,c))] \ + ^ tab##3[bval(vf(x,3,c),rf(3,c))]) + +#define vf1(x,r,c) (x) +#define rf1(r,c) (r) +#define rf2(r,c) ((8+r-c)&3) + +/* perform forward and inverse column mix operation on four bytes in long word x in */ +/* parallel. NOTE: x must be a simple variable, NOT an expression in these macros. */ + +#if defined(FM4_SET) /* not currently used */ +#define fwd_mcol(x) four_tables(x,t_use(f,m),vf1,rf1,0) +#elif defined(FM1_SET) /* not currently used */ +#define fwd_mcol(x) one_table(x,upr,t_use(f,m),vf1,rf1,0) +#else +#define dec_fmvars aes_32t g2 +#define fwd_mcol(x) (g2 = gf_mulx(x), g2 ^ upr((x) ^ g2, 3) ^ upr((x), 2) ^ upr((x), 1)) +#endif + +#if defined(IM4_SET) +#define inv_mcol(x) four_tables(x,t_use(i,m),vf1,rf1,0) +#elif defined(IM1_SET) +#define inv_mcol(x) one_table(x,upr,t_use(i,m),vf1,rf1,0) +#else +#define dec_imvars aes_32t g2, g4, g9 +#define inv_mcol(x) (g2 = gf_mulx(x), g4 = gf_mulx(g2), g9 = (x) ^ gf_mulx(g4), g4 ^= g9, \ + (x) ^ g2 ^ g4 ^ upr(g2 ^ g9, 3) ^ upr(g4, 2) ^ upr(g9, 1)) +#endif + +#if defined(FL4_SET) +#define ls_box(x,c) four_tables(x,t_use(f,l),vf1,rf2,c) +#elif defined(LS4_SET) +#define ls_box(x,c) four_tables(x,t_use(l,s),vf1,rf2,c) +#elif defined(FL1_SET) +#define ls_box(x,c) one_table(x,upr,t_use(f,l),vf1,rf2,c) +#elif defined(LS1_SET) +#define ls_box(x,c) one_table(x,upr,t_use(l,s),vf1,rf2,c) +#else +#define ls_box(x,c) no_table(x,t_use(s,box),vf1,rf2,c) +#endif + +#endif diff --git a/bootx.tproj/sl.subproj/aestab.c b/bootx.tproj/sl.subproj/aestab.c new file mode 100755 index 0000000..7997f29 --- /dev/null +++ b/bootx.tproj/sl.subproj/aestab.c @@ -0,0 +1,384 @@ +/* + --------------------------------------------------------------------------- + Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved. + + LICENSE TERMS + + The free distribution and use of this software in both source and binary + form is allowed (with or without changes) provided that: + + 1. distributions of this source code include the above copyright + notice, this list of conditions and the following disclaimer; + + 2. distributions in binary form include the above copyright + notice, this list of conditions and the following disclaimer + in the documentation and/or other associated materials; + + 3. the copyright holder's name is not used to endorse products + built using this software without specific written permission. + + ALTERNATIVELY, provided that this notice is retained in full, this product + may be distributed under the terms of the GNU General Public License (GPL), + in which case the provisions of the GPL apply INSTEAD OF those given above. + + DISCLAIMER + + This software is provided 'as is' with no explicit or implied warranties + in respect of its properties, including, but not limited to, correctness + and/or fitness for purpose. + --------------------------------------------------------------------------- + Issue 28/01/2004 + +*/ + +#if defined(__cplusplus) +extern "C" +{ +#endif + +#define DO_TABLES + +#include "aesopt.h" + +#if defined(FIXED_TABLES) + +#define sb_data(w) {\ + w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\ + w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\ + w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\ + w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\ + w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\ + w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\ + w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\ + w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\ + w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\ + w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\ + w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\ + w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\ + w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\ + w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\ + w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\ + w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\ + w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\ + w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\ + w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\ + w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\ + w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\ + w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\ + w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\ + w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\ + w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\ + w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\ + w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\ + w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\ + w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\ + w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\ + w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\ + w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) } + +#define isb_data(w) {\ + w(0x52), w(0x09), w(0x6a), w(0xd5), w(0x30), w(0x36), w(0xa5), w(0x38),\ + w(0xbf), w(0x40), w(0xa3), w(0x9e), w(0x81), w(0xf3), w(0xd7), w(0xfb),\ + w(0x7c), w(0xe3), w(0x39), w(0x82), w(0x9b), w(0x2f), w(0xff), w(0x87),\ + w(0x34), w(0x8e), w(0x43), w(0x44), w(0xc4), w(0xde), w(0xe9), w(0xcb),\ + w(0x54), w(0x7b), w(0x94), w(0x32), w(0xa6), w(0xc2), w(0x23), w(0x3d),\ + w(0xee), w(0x4c), w(0x95), w(0x0b), w(0x42), w(0xfa), w(0xc3), w(0x4e),\ + w(0x08), w(0x2e), w(0xa1), w(0x66), w(0x28), w(0xd9), w(0x24), w(0xb2),\ + w(0x76), w(0x5b), w(0xa2), w(0x49), w(0x6d), w(0x8b), w(0xd1), w(0x25),\ + w(0x72), w(0xf8), w(0xf6), w(0x64), w(0x86), w(0x68), w(0x98), w(0x16),\ + w(0xd4), w(0xa4), w(0x5c), w(0xcc), w(0x5d), w(0x65), w(0xb6), w(0x92),\ + w(0x6c), w(0x70), w(0x48), w(0x50), w(0xfd), w(0xed), w(0xb9), w(0xda),\ + w(0x5e), w(0x15), w(0x46), w(0x57), w(0xa7), w(0x8d), w(0x9d), w(0x84),\ + w(0x90), w(0xd8), w(0xab), w(0x00), w(0x8c), w(0xbc), w(0xd3), w(0x0a),\ + w(0xf7), w(0xe4), w(0x58), w(0x05), w(0xb8), w(0xb3), w(0x45), w(0x06),\ + w(0xd0), w(0x2c), w(0x1e), w(0x8f), w(0xca), w(0x3f), w(0x0f), w(0x02),\ + w(0xc1), w(0xaf), w(0xbd), w(0x03), w(0x01), w(0x13), w(0x8a), w(0x6b),\ + w(0x3a), w(0x91), w(0x11), w(0x41), w(0x4f), w(0x67), w(0xdc), w(0xea),\ + w(0x97), w(0xf2), w(0xcf), w(0xce), w(0xf0), w(0xb4), w(0xe6), w(0x73),\ + w(0x96), w(0xac), w(0x74), w(0x22), w(0xe7), w(0xad), w(0x35), w(0x85),\ + w(0xe2), w(0xf9), w(0x37), w(0xe8), w(0x1c), w(0x75), w(0xdf), w(0x6e),\ + w(0x47), w(0xf1), w(0x1a), w(0x71), w(0x1d), w(0x29), w(0xc5), w(0x89),\ + w(0x6f), w(0xb7), w(0x62), w(0x0e), w(0xaa), w(0x18), w(0xbe), w(0x1b),\ + w(0xfc), w(0x56), w(0x3e), w(0x4b), w(0xc6), w(0xd2), w(0x79), w(0x20),\ + w(0x9a), w(0xdb), w(0xc0), w(0xfe), w(0x78), w(0xcd), w(0x5a), w(0xf4),\ + w(0x1f), w(0xdd), w(0xa8), w(0x33), w(0x88), w(0x07), w(0xc7), w(0x31),\ + w(0xb1), w(0x12), w(0x10), w(0x59), w(0x27), w(0x80), w(0xec), w(0x5f),\ + w(0x60), w(0x51), w(0x7f), w(0xa9), w(0x19), w(0xb5), w(0x4a), w(0x0d),\ + w(0x2d), w(0xe5), w(0x7a), w(0x9f), w(0x93), w(0xc9), w(0x9c), w(0xef),\ + w(0xa0), w(0xe0), w(0x3b), w(0x4d), w(0xae), w(0x2a), w(0xf5), w(0xb0),\ + w(0xc8), w(0xeb), w(0xbb), w(0x3c), w(0x83), w(0x53), w(0x99), w(0x61),\ + w(0x17), w(0x2b), w(0x04), w(0x7e), w(0xba), w(0x77), w(0xd6), w(0x26),\ + w(0xe1), w(0x69), w(0x14), w(0x63), w(0x55), w(0x21), w(0x0c), w(0x7d) } + +#define mm_data(w) {\ + w(0x00), w(0x01), w(0x02), w(0x03), w(0x04), w(0x05), w(0x06), w(0x07),\ + w(0x08), w(0x09), w(0x0a), w(0x0b), w(0x0c), w(0x0d), w(0x0e), w(0x0f),\ + w(0x10), w(0x11), w(0x12), w(0x13), w(0x14), w(0x15), w(0x16), w(0x17),\ + w(0x18), w(0x19), w(0x1a), w(0x1b), w(0x1c), w(0x1d), w(0x1e), w(0x1f),\ + w(0x20), w(0x21), w(0x22), w(0x23), w(0x24), w(0x25), w(0x26), w(0x27),\ + w(0x28), w(0x29), w(0x2a), w(0x2b), w(0x2c), w(0x2d), w(0x2e), w(0x2f),\ + w(0x30), w(0x31), w(0x32), w(0x33), w(0x34), w(0x35), w(0x36), w(0x37),\ + w(0x38), w(0x39), w(0x3a), w(0x3b), w(0x3c), w(0x3d), w(0x3e), w(0x3f),\ + w(0x40), w(0x41), w(0x42), w(0x43), w(0x44), w(0x45), w(0x46), w(0x47),\ + w(0x48), w(0x49), w(0x4a), w(0x4b), w(0x4c), w(0x4d), w(0x4e), w(0x4f),\ + w(0x50), w(0x51), w(0x52), w(0x53), w(0x54), w(0x55), w(0x56), w(0x57),\ + w(0x58), w(0x59), w(0x5a), w(0x5b), w(0x5c), w(0x5d), w(0x5e), w(0x5f),\ + w(0x60), w(0x61), w(0x62), w(0x63), w(0x64), w(0x65), w(0x66), w(0x67),\ + w(0x68), w(0x69), w(0x6a), w(0x6b), w(0x6c), w(0x6d), w(0x6e), w(0x6f),\ + w(0x70), w(0x71), w(0x72), w(0x73), w(0x74), w(0x75), w(0x76), w(0x77),\ + w(0x78), w(0x79), w(0x7a), w(0x7b), w(0x7c), w(0x7d), w(0x7e), w(0x7f),\ + w(0x80), w(0x81), w(0x82), w(0x83), w(0x84), w(0x85), w(0x86), w(0x87),\ + w(0x88), w(0x89), w(0x8a), w(0x8b), w(0x8c), w(0x8d), w(0x8e), w(0x8f),\ + w(0x90), w(0x91), w(0x92), w(0x93), w(0x94), w(0x95), w(0x96), w(0x97),\ + w(0x98), w(0x99), w(0x9a), w(0x9b), w(0x9c), w(0x9d), w(0x9e), w(0x9f),\ + w(0xa0), w(0xa1), w(0xa2), w(0xa3), w(0xa4), w(0xa5), w(0xa6), w(0xa7),\ + w(0xa8), w(0xa9), w(0xaa), w(0xab), w(0xac), w(0xad), w(0xae), w(0xaf),\ + w(0xb0), w(0xb1), w(0xb2), w(0xb3), w(0xb4), w(0xb5), w(0xb6), w(0xb7),\ + w(0xb8), w(0xb9), w(0xba), w(0xbb), w(0xbc), w(0xbd), w(0xbe), w(0xbf),\ + w(0xc0), w(0xc1), w(0xc2), w(0xc3), w(0xc4), w(0xc5), w(0xc6), w(0xc7),\ + w(0xc8), w(0xc9), w(0xca), w(0xcb), w(0xcc), w(0xcd), w(0xce), w(0xcf),\ + w(0xd0), w(0xd1), w(0xd2), w(0xd3), w(0xd4), w(0xd5), w(0xd6), w(0xd7),\ + w(0xd8), w(0xd9), w(0xda), w(0xdb), w(0xdc), w(0xdd), w(0xde), w(0xdf),\ + w(0xe0), w(0xe1), w(0xe2), w(0xe3), w(0xe4), w(0xe5), w(0xe6), w(0xe7),\ + w(0xe8), w(0xe9), w(0xea), w(0xeb), w(0xec), w(0xed), w(0xee), w(0xef),\ + w(0xf0), w(0xf1), w(0xf2), w(0xf3), w(0xf4), w(0xf5), w(0xf6), w(0xf7),\ + w(0xf8), w(0xf9), w(0xfa), w(0xfb), w(0xfc), w(0xfd), w(0xfe), w(0xff) } + +#define rc_data(w) {\ + w(0x01), w(0x02), w(0x04), w(0x08), w(0x10),w(0x20), w(0x40), w(0x80),\ + w(0x1b), w(0x36) } + +#define h0(x) (x) + +#define w0(p) bytes2word(p, 0, 0, 0) +#define w1(p) bytes2word(0, p, 0, 0) +#define w2(p) bytes2word(0, 0, p, 0) +#define w3(p) bytes2word(0, 0, 0, p) + +#define u0(p) bytes2word(f2(p), p, p, f3(p)) +#define u1(p) bytes2word(f3(p), f2(p), p, p) +#define u2(p) bytes2word(p, f3(p), f2(p), p) +#define u3(p) bytes2word(p, p, f3(p), f2(p)) + +#define v0(p) bytes2word(fe(p), f9(p), fd(p), fb(p)) +#define v1(p) bytes2word(fb(p), fe(p), f9(p), fd(p)) +#define v2(p) bytes2word(fd(p), fb(p), fe(p), f9(p)) +#define v3(p) bytes2word(f9(p), fd(p), fb(p), fe(p)) + +#endif + +#if defined(FIXED_TABLES) || !defined(FF_TABLES) + +#define f2(x) ((x<<1) ^ (((x>>7) & 1) * WPOLY)) +#define f4(x) ((x<<2) ^ (((x>>6) & 1) * WPOLY) ^ (((x>>6) & 2) * WPOLY)) +#define f8(x) ((x<<3) ^ (((x>>5) & 1) * WPOLY) ^ (((x>>5) & 2) * WPOLY) \ + ^ (((x>>5) & 4) * WPOLY)) +#define f3(x) (f2(x) ^ x) +#define f9(x) (f8(x) ^ x) +#define fb(x) (f8(x) ^ f2(x) ^ x) +#define fd(x) (f8(x) ^ f4(x) ^ x) +#define fe(x) (f8(x) ^ f4(x) ^ f2(x)) + +#else + +#define f2(x) ((x) ? pow[log[x] + 0x19] : 0) +#define f3(x) ((x) ? pow[log[x] + 0x01] : 0) +#define f9(x) ((x) ? pow[log[x] + 0xc7] : 0) +#define fb(x) ((x) ? pow[log[x] + 0x68] : 0) +#define fd(x) ((x) ? pow[log[x] + 0xee] : 0) +#define fe(x) ((x) ? pow[log[x] + 0xdf] : 0) +#define fi(x) ((x) ? pow[ 255 - log[x]] : 0) + +#endif + +#include "aestab.h" + +#if defined(FIXED_TABLES) + +/* implemented in case of wrong call for fixed tables */ + +void gen_tabs(void) +{ +} + +#else /* dynamic table generation */ + +#if !defined(FF_TABLES) + +/* Generate the tables for the dynamic table option + + It will generally be sensible to use tables to compute finite + field multiplies and inverses but where memory is scarse this + code might sometimes be better. But it only has effect during + initialisation so its pretty unimportant in overall terms. +*/ + +/* return 2 ^ (n - 1) where n is the bit number of the highest bit + set in x with x in the range 1 < x < 0x00000200. This form is + used so that locals within fi can be bytes rather than words +*/ + +static aes_08t hibit(const aes_32t x) +{ aes_08t r = (aes_08t)((x >> 1) | (x >> 2)); + + r |= (r >> 2); + r |= (r >> 4); + return (r + 1) >> 1; +} + +/* return the inverse of the finite field element x */ + +static aes_08t fi(const aes_08t x) +{ aes_08t p1 = x, p2 = BPOLY, n1 = hibit(x), n2 = 0x80, v1 = 1, v2 = 0; + + if(x < 2) return x; + + for(;;) + { + if(!n1) return v1; + + while(n2 >= n1) + { + n2 /= n1; p2 ^= p1 * n2; v2 ^= v1 * n2; n2 = hibit(p2); + } + + if(!n2) return v2; + + while(n1 >= n2) + { + n1 /= n2; p1 ^= p2 * n1; v1 ^= v2 * n1; n1 = hibit(p1); + } + } +} + +#endif + +/* The forward and inverse affine transformations used in the S-box */ + +#define fwd_affine(x) \ + (w = (aes_32t)x, w ^= (w<<1)^(w<<2)^(w<<3)^(w<<4), 0x63^(aes_08t)(w^(w>>8))) + +#define inv_affine(x) \ + (w = (aes_32t)x, w = (w<<1)^(w<<3)^(w<<6), 0x05^(aes_08t)(w^(w>>8))) + +static int init = 0; + +void gen_tabs(void) +{ aes_32t i, w; + +#if defined(FF_TABLES) + + aes_08t pow[512], log[256]; + + if(init) return; + /* log and power tables for GF(2^8) finite field with + WPOLY as modular polynomial - the simplest primitive + root is 0x03, used here to generate the tables + */ + + i = 0; w = 1; + do + { + pow[i] = (aes_08t)w; + pow[i + 255] = (aes_08t)w; + log[w] = (aes_08t)i++; + w ^= (w << 1) ^ (w & 0x80 ? WPOLY : 0); + } + while (w != 1); + +#else + if(init) return; +#endif + + for(i = 0, w = 1; i < RC_LENGTH; ++i) + { + t_set(r,c)[i] = bytes2word(w, 0, 0, 0); + w = f2(w); + } + + for(i = 0; i < 256; ++i) + { aes_08t b; + + b = fwd_affine(fi((aes_08t)i)); + w = bytes2word(f2(b), b, b, f3(b)); + +#if defined( SBX_SET ) + t_set(s,box)[i] = b; +#endif + +#if defined( FT1_SET ) /* tables for a normal encryption round */ + t_set(f,n)[i] = w; +#endif +#if defined( FT4_SET ) + t_set(f,n)[0][i] = w; + t_set(f,n)[1][i] = upr(w,1); + t_set(f,n)[2][i] = upr(w,2); + t_set(f,n)[3][i] = upr(w,3); +#endif + w = bytes2word(b, 0, 0, 0); + +#if defined( FL1_SET ) /* tables for last encryption round (may also */ + t_set(f,l)[i] = w; /* be used in the key schedule) */ +#endif +#if defined( FL4_SET ) + t_set(f,l)[0][i] = w; + t_set(f,l)[1][i] = upr(w,1); + t_set(f,l)[2][i] = upr(w,2); + t_set(f,l)[3][i] = upr(w,3); +#endif + +#if defined( LS1_SET ) /* table for key schedule if t_set(f,l) above is */ + t_set(l,s)[i] = w; /* not of the required form */ +#endif +#if defined( LS4_SET ) + t_set(l,s)[0][i] = w; + t_set(l,s)[1][i] = upr(w,1); + t_set(l,s)[2][i] = upr(w,2); + t_set(l,s)[3][i] = upr(w,3); +#endif + + b = fi(inv_affine((aes_08t)i)); + w = bytes2word(fe(b), f9(b), fd(b), fb(b)); + +#if defined( IM1_SET ) /* tables for the inverse mix column operation */ + t_set(i,m)[b] = w; +#endif +#if defined( IM4_SET ) + t_set(i,m)[0][b] = w; + t_set(i,m)[1][b] = upr(w,1); + t_set(i,m)[2][b] = upr(w,2); + t_set(i,m)[3][b] = upr(w,3); +#endif + +#if defined( ISB_SET ) + t_set(i,box)[i] = b; +#endif +#if defined( IT1_SET ) /* tables for a normal decryption round */ + t_set(i,n)[i] = w; +#endif +#if defined( IT4_SET ) + t_set(i,n)[0][i] = w; + t_set(i,n)[1][i] = upr(w,1); + t_set(i,n)[2][i] = upr(w,2); + t_set(i,n)[3][i] = upr(w,3); +#endif + w = bytes2word(b, 0, 0, 0); +#if defined( IL1_SET ) /* tables for last decryption round */ + t_set(i,l)[i] = w; +#endif +#if defined( IL4_SET ) + t_set(i,l)[0][i] = w; + t_set(i,l)[1][i] = upr(w,1); + t_set(i,l)[2][i] = upr(w,2); + t_set(i,l)[3][i] = upr(w,3); +#endif + } + init = 1; +} + +#endif + +#if defined(__cplusplus) +} +#endif + diff --git a/bootx.tproj/sl.subproj/aestab.h b/bootx.tproj/sl.subproj/aestab.h new file mode 100755 index 0000000..c610f9d --- /dev/null +++ b/bootx.tproj/sl.subproj/aestab.h @@ -0,0 +1,175 @@ +/* + --------------------------------------------------------------------------- + Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved. + + LICENSE TERMS + + The free distribution and use of this software in both source and binary + form is allowed (with or without changes) provided that: + + 1. distributions of this source code include the above copyright + notice, this list of conditions and the following disclaimer; + + 2. distributions in binary form include the above copyright + notice, this list of conditions and the following disclaimer + in the documentation and/or other associated materials; + + 3. the copyright holder's name is not used to endorse products + built using this software without specific written permission. + + ALTERNATIVELY, provided that this notice is retained in full, this product + may be distributed under the terms of the GNU General Public License (GPL), + in which case the provisions of the GPL apply INSTEAD OF those given above. + + DISCLAIMER + + This software is provided 'as is' with no explicit or implied warranties + in respect of its properties, including, but not limited to, correctness + and/or fitness for purpose. + --------------------------------------------------------------------------- + Issue 28/01/2004 + + This file contains the code for declaring the tables needed to implement + AES. The file aesopt.h is assumed to be included before this header file. + If there are no global variables, the definitions here can be used to put + the AES tables in a structure so that a pointer can then be added to the + AES context to pass them to the AES routines that need them. If this + facility is used, the calling program has to ensure that this pointer is + managed appropriately. In particular, the value of the t_dec(in,it) item + in the table structure must be set to zero in order to ensure that the + tables are initialised. In practice the three code sequences in aeskey.c + that control the calls to gen_tabs() and the gen_tabs() routine itself will + have to be changed for a specific implementation. If global variables are + available it will generally be preferable to use them with the precomputed + FIXED_TABLES option that uses static global tables. + + The following defines can be used to control the way the tables + are defined, initialised and used in embedded environments that + require special features for these purposes + + the 't_dec' construction is used to declare fixed table arrays + the 't_set' construction is used to set fixed table values + the 't_use' construction is used to access fixed table values + + 256 byte tables: + + t_xxx(s,box) => forward S box + t_xxx(i,box) => inverse S box + + 256 32-bit word OR 4 x 256 32-bit word tables: + + t_xxx(f,n) => forward normal round + t_xxx(f,l) => forward last round + t_xxx(i,n) => inverse normal round + t_xxx(i,l) => inverse last round + t_xxx(l,s) => key schedule table + t_xxx(i,m) => key schedule table + + Other variables and tables: + + t_xxx(r,c) => the rcon table +*/ + +#if !defined( _AESTAB_H ) +#define _AESTAB_H + +#define t_dec(m,n) t_##m##n +#define t_set(m,n) t_##m##n +#define t_use(m,n) t_##m##n + +#if defined(FIXED_TABLES) +#define Const const +#else +#define Const +#endif + +#if defined(DO_TABLES) +#define Extern +#else +#define Extern extern +#endif + +#if defined(_MSC_VER) && defined(TABLE_ALIGN) +#define Align __declspec(align(TABLE_ALIGN)) +#else +#define Align +#endif + +#if defined(__cplusplus) +extern "C" +{ +#endif + +#if defined(DO_TABLES) && defined(FIXED_TABLES) +#define d_1(t,n,b,e) Align Const t n[256] = b(e) +#define d_4(t,n,b,e,f,g,h) Align Const t n[4][256] = { b(e), b(f), b(g), b(h) } +Extern Align Const aes_32t t_dec(r,c)[RC_LENGTH] = rc_data(w0); +#else +#define d_1(t,n,b,e) Extern Align Const t n[256] +#define d_4(t,n,b,e,f,g,h) Extern Align Const t n[4][256] +Extern Align Const aes_32t t_dec(r,c)[RC_LENGTH]; +#endif + +#if defined( SBX_SET ) + d_1(aes_08t, t_dec(s,box), sb_data, h0); +#endif +#if defined( ISB_SET ) + d_1(aes_08t, t_dec(i,box), isb_data, h0); +#endif + +#if defined( FT1_SET ) + d_1(aes_32t, t_dec(f,n), sb_data, u0); +#endif +#if defined( FT4_SET ) + d_4(aes_32t, t_dec(f,n), sb_data, u0, u1, u2, u3); +#endif + +#if defined( FL1_SET ) + d_1(aes_32t, t_dec(f,l), sb_data, w0); +#endif +#if defined( FL4_SET ) + d_4(aes_32t, t_dec(f,l), sb_data, w0, w1, w2, w3); +#endif + +#if defined( IT1_SET ) + d_1(aes_32t, t_dec(i,n), isb_data, v0); +#endif +#if defined( IT4_SET ) + d_4(aes_32t, t_dec(i,n), isb_data, v0, v1, v2, v3); +#endif + +#if defined( IL1_SET ) + d_1(aes_32t, t_dec(i,l), isb_data, w0); +#endif +#if defined( IL4_SET ) + d_4(aes_32t, t_dec(i,l), isb_data, w0, w1, w2, w3); +#endif + +#if defined( LS1_SET ) +#if defined( FL1_SET ) +#undef LS1_SET +#else + d_1(aes_32t, t_dec(l,s), sb_data, w0); +#endif +#endif + +#if defined( LS4_SET ) +#if defined( FL4_SET ) +#undef LS4_SET +#else + d_4(aes_32t, t_dec(l,s), sb_data, w0, w1, w2, w3); +#endif +#endif + +#if defined( IM1_SET ) + d_1(aes_32t, t_dec(i,m), mm_data, v0); +#endif +#if defined( IM4_SET ) + d_4(aes_32t, t_dec(i,m), mm_data, v0, v1, v2, v3); +#endif + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/bootx.tproj/sl.subproj/appleboot.h b/bootx.tproj/sl.subproj/appleboot.h index 4e32e02..8d77fa2 100644 --- a/bootx.tproj/sl.subproj/appleboot.h +++ b/bootx.tproj/sl.subproj/appleboot.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/sl.subproj/bmdecompress.c b/bootx.tproj/sl.subproj/bmdecompress.c new file mode 100644 index 0000000..e8c70f5 --- /dev/null +++ b/bootx.tproj/sl.subproj/bmdecompress.c @@ -0,0 +1,256 @@ +/* + * Copyright (c) 1995-2002 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. + * + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include +#include + +typedef uint8_t UInt8; +typedef uint16_t UInt16; +typedef uint32_t UInt32; +typedef int8_t SInt8; +typedef int16_t SInt16; +typedef int32_t SInt32; + +enum { false = 0, true = 1 }; + +static void +PreviewDecompress16(uint32_t * compressBuffer, + uint32_t width, uint32_t height, uint32_t row, + uint16_t * output) +{ + int i, j; + uint32_t * input; + + uint16_t * sc0 = malloc((width+2) * sizeof(uint16_t)); + uint16_t * sc1 = malloc((width+2) * sizeof(uint16_t)); + uint16_t * sc2 = malloc((width+2) * sizeof(uint16_t)); + uint16_t * sc3 = malloc((width+2) * sizeof(uint16_t)); + uint32_t sr0, sr1, sr2, sr3; + + bzero(sc0, (width+2) * sizeof(uint16_t)); + bzero(sc1, (width+2) * sizeof(uint16_t)); + bzero(sc2, (width+2) * sizeof(uint16_t)); + bzero(sc3, (width+2) * sizeof(uint16_t)); + + uint32_t tmp1, tmp2, out; + for (j = 0; j < (height + 2); j++) + { + input = compressBuffer; + if (j < height) + input += j; + else + input += height - 1; + input = (uint32_t *)(input[3] + ((uint8_t *)compressBuffer)); + + uint32_t data, repeat, fetch, count = 0; + sr0 = sr1 = sr2 = sr3 = 0; + + for (i = 0; i < (width + 2); i++) + { + if (i < width) + { + if (!count) + { + count = *input++; + repeat = (count & 0xff000000); + count ^= repeat; + fetch = true; + } + else + fetch = (0 == repeat); + + count--; + + if (fetch) + { + data = *((uint16_t *)input)++; + + // grayscale + // srgb 13933, 46871, 4732 + // ntsc 19595, 38470, 7471 + data = 13933 * (0x1f & (data >> 10)) + + 46871 * (0x1f & (data >> 5)) + + 4732 * (0x1f & data); + data >>= 13; + + // 70% white, 30 % black + data *= 19661; + data += (103 << 16); + data >>= 16; + } + } + + // gauss blur + tmp2 = sr0 + data; + sr0 = data; + tmp1 = sr1 + tmp2; + sr1 = tmp2; + tmp2 = sr2 + tmp1; + sr2 = tmp1; + tmp1 = sr3 + tmp2; + sr3 = tmp2; + + tmp2 = sc0[i] + tmp1; + sc0[i] = tmp1; + tmp1 = sc1[i] + tmp2; + sc1[i] = tmp2; + tmp2 = sc2[i] + tmp1; + sc2[i] = tmp1; + out = (128 + sc3[i] + tmp2) >> 11; + sc3[i] = tmp2; + + out &= 0x1f; + if ((i > 1) && (j > 1)) + output[i-2] = out | (out << 5) | (out << 10); + } + + if (j > 1) + output += row; + } + free(sc3); + free(sc2); + free(sc1); + free(sc0); +} + +static void +PreviewDecompress32(uint32_t * compressBuffer, + uint32_t width, uint32_t height, uint32_t row, + uint32_t * output) +{ + int i, j; + uint32_t * input; + + uint16_t * sc0 = malloc((width+2) * sizeof(uint16_t)); + uint16_t * sc1 = malloc((width+2) * sizeof(uint16_t)); + uint16_t * sc2 = malloc((width+2) * sizeof(uint16_t)); + uint16_t * sc3 = malloc((width+2) * sizeof(uint16_t)); + uint32_t sr0, sr1, sr2, sr3; + + bzero(sc0, (width+2) * sizeof(uint16_t)); + bzero(sc1, (width+2) * sizeof(uint16_t)); + bzero(sc2, (width+2) * sizeof(uint16_t)); + bzero(sc3, (width+2) * sizeof(uint16_t)); + + uint32_t tmp1, tmp2, out; + for (j = 0; j < (height + 2); j++) + { + input = compressBuffer; + if (j < height) + input += j; + else + input += height - 1; + input = (uint32_t *)(input[3] + ((uint8_t *)compressBuffer)); + + uint32_t data, repeat, fetch, count = 0; + sr0 = sr1 = sr2 = sr3 = 0; + + for (i = 0; i < (width + 2); i++) + { + if (i < width) + { + if (!count) + { + count = *input++; + repeat = (count & 0xff000000); + count ^= repeat; + fetch = true; + } + else + fetch = (0 == repeat); + + count--; + + if (fetch) + { + data = *input++; + + // grayscale + // srgb 13933, 46871, 4732 + // ntsc 19595, 38470, 7471 + data = 13933 * (0xff & (data >> 24)) + + 46871 * (0xff & (data >> 16)) + + 4732 * (0xff & data); + data >>= 16; + + // 70% white, 30 % black + data *= 19661; + data += (103 << 16); + data >>= 16; + } + } + + // gauss blur + tmp2 = sr0 + data; + sr0 = data; + tmp1 = sr1 + tmp2; + sr1 = tmp2; + tmp2 = sr2 + tmp1; + sr2 = tmp1; + tmp1 = sr3 + tmp2; + sr3 = tmp2; + + tmp2 = sc0[i] + tmp1; + sc0[i] = tmp1; + tmp1 = sc1[i] + tmp2; + sc1[i] = tmp2; + tmp2 = sc2[i] + tmp1; + sc2[i] = tmp1; + out = (128 + sc3[i] + tmp2) >> 8; + sc3[i] = tmp2; + + out &= 0xff; + if ((i > 1) && (j > 1)) + output[i-2] = out | (out << 8) | (out << 16); + } + + if (j > 1) + output += row; + } + + free(sc3); + free(sc2); + free(sc1); + free(sc0); +} + +int +DecompressData(void *srcbase, void *dstbase, + int dw, int dh, int bytesPerPixel, int rowbytes) +{ + uint32_t * src = (uint32_t *) srcbase; + + if ((bytesPerPixel != (int) src[0]) || (dw != (int) src[1]) || (dh != (int) src[2])) + return (false); + + switch(bytesPerPixel) + { + case 4: + PreviewDecompress32((uint32_t *)srcbase, dw, dh, rowbytes >> 2, (uint32_t *) dstbase); + return (true); + case 2: + PreviewDecompress16((uint32_t *)srcbase, dw, dh, rowbytes >> 1, (uint16_t *) dstbase); + return (true); + default: + return (false); + } +} diff --git a/bootx.tproj/sl.subproj/clut.h b/bootx.tproj/sl.subproj/clut.h index 280ee09..867b03b 100644 --- a/bootx.tproj/sl.subproj/clut.h +++ b/bootx.tproj/sl.subproj/clut.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/sl.subproj/device_tree.c b/bootx.tproj/sl.subproj/device_tree.c index 0cc8994..8cbd4dc 100644 --- a/bootx.tproj/sl.subproj/device_tree.c +++ b/bootx.tproj/sl.subproj/device_tree.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/sl.subproj/display.c b/bootx.tproj/sl.subproj/display.c index 997de21..700e870 100644 --- a/bootx.tproj/sl.subproj/display.c +++ b/bootx.tproj/sl.subproj/display.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -51,10 +48,10 @@ struct DisplayInfo { typedef struct DisplayInfo DisplayInfo, *DisplayInfoPtr; -static long FindDisplays(void); -static long OpenDisplays(void); -static long OpenDisplay(long displayNum); -static long InitDisplay(long displayNum); +static long FindDisplays(); +static long OpenDisplays(int fill); +static long OpenDisplay(long displayNum, int fill); +static long InitDisplay(long displayNum, int fill); static long LookUpCLUTIndex(long index, long depth); static long gNumDisplays; @@ -67,14 +64,22 @@ static unsigned char *gFailedBoot; // Public Functions -long InitDisplays(void) +long InitDisplays(int fill) { FindDisplays(); - OpenDisplays(); + OpenDisplays(fill); return 0; } +void CloseDisplays(void) +{ + int cnt; + for (cnt = 0; cnt < gNumDisplays; cnt++) { + if (gDisplays[cnt].screenIH) + Close(gDisplays[cnt].screenIH); + } +} long DrawSplashScreen(long stage) { @@ -234,7 +239,7 @@ long DrawFailedBootPicture(void) } -void GetMainScreenPH(Boot_Video_Ptr video) +void GetMainScreenPH(Boot_Video_Ptr video, int setProperties) { DisplayInfoPtr display; long address, size; @@ -255,9 +260,11 @@ void GetMainScreenPH(Boot_Video_Ptr video) video->v_height = display->height; video->v_depth = display->depth; } - - // Allocate memory and a range for the CLUT. + + if (!setProperties) return; + size = 256 * 3; + // Allocate memory and a range for the CLUT. address = AllocateKernelMemory(size); AllocateMemoryRange("BootCLUT", address, size); bcopy((char *)gClut, (char *)address, size); @@ -296,6 +303,7 @@ static long FindDisplays(void) // Find the main screen using the screen alias or chaos/control. gMainDisplayNum = -1; screenPH = FindDevice("screen"); + gDisplays[gNumDisplays++].screenPH = screenPH; if (screenPH == -1) screenPH = controlPH; for (cnt = 0; cnt < gNumDisplays; cnt++) if (gDisplays[cnt].screenPH == screenPH) gMainDisplayNum = cnt; @@ -304,16 +312,16 @@ static long FindDisplays(void) } -static long OpenDisplays(void) +static long OpenDisplays(int fill) { long cnt; // Open the main screen or // look for a main screen if we don't have one. - if ((gMainDisplayNum == -1) || !OpenDisplay(gMainDisplayNum)) { + if ((gMainDisplayNum == -1) || !OpenDisplay(gMainDisplayNum, fill)) { gMainDisplayNum = -1; for (cnt = 0; cnt < gNumDisplays; cnt++) { - if (OpenDisplay(cnt)) { + if (OpenDisplay(cnt, fill)) { gMainDisplayNum = cnt; break; } @@ -323,7 +331,7 @@ static long OpenDisplays(void) // Open the rest of the displays if (gOFVersion >= kOFVersion3x) { for (cnt = 0; cnt < gNumDisplays; cnt++) { - OpenDisplay(cnt); + OpenDisplay(cnt, 1); } } @@ -331,7 +339,7 @@ static long OpenDisplays(void) } -static long OpenDisplay(long displayNum) +static long OpenDisplay(long displayNum, int fill) { char screenPath[258], displayType[32]; CICell screenPH, screenIH; @@ -380,13 +388,13 @@ static long OpenDisplay(long displayNum) gDisplays[displayNum].screenIH = screenIH; // Initialize the display. - if (screenIH != 0) InitDisplay(displayNum); + if (screenIH != 0) InitDisplay(displayNum, fill); return screenIH != 0; } -static long InitDisplay(long displayNum) +static long InitDisplay(long displayNum, int fill) { DisplayInfoPtr display = &gDisplays[displayNum]; CICell screenPH = display->screenPH; @@ -449,8 +457,9 @@ static long InitDisplay(long displayNum) CallMethod(3, 0, screenIH, "set-colors", (long)gClut, 0, 256); } - // Set the screen to 75% grey. - CallMethod(5, 0, screenIH, "fill-rectangle", + if (fill) + // Set the screen to 75% grey. + CallMethod(5, 0, screenIH, "fill-rectangle", LookUpCLUTIndex(0x01, display->depth), 0, 0, display->width, display->height); diff --git a/bootx.tproj/sl.subproj/drivers.c b/bootx.tproj/sl.subproj/drivers.c index 619e7ff..99d3430 100644 --- a/bootx.tproj/sl.subproj/drivers.c +++ b/bootx.tproj/sl.subproj/drivers.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -34,30 +31,6 @@ #define DRIVER_DEBUG 0 -enum { - kTagTypeNone = 0, - kTagTypeDict, - kTagTypeKey, - kTagTypeString, - kTagTypeInteger, - kTagTypeData, - kTagTypeDate, - kTagTypeFalse, - kTagTypeTrue, - kTagTypeArray -}; - -#define kXMLTagPList "plist " -#define kXMLTagDict "dict" -#define kXMLTagKey "key" -#define kXMLTagString "string" -#define kXMLTagInteger "integer" -#define kXMLTagData "data" -#define kXMLTagDate "date" -#define kXMLTagFalse "false/" -#define kXMLTagTrue "true/" -#define kXMLTagArray "array" - #define kPropCFBundleIdentifier ("CFBundleIdentifier") #define kPropCFBundleExecutable ("CFBundleExecutable") #define kPropOSBundleRequired ("OSBundleRequired") @@ -65,14 +38,6 @@ enum { #define kPropIOKitPersonalities ("IOKitPersonalities") #define kPropIONameMatch ("IONameMatch") -struct Tag { - long type; - char *string; - struct Tag *tag; - struct Tag *tagNext; -}; -typedef struct Tag Tag, *TagPtr; - struct Module { struct Module *nextModule; long willLoad; @@ -98,7 +63,7 @@ struct DriversPackage { unsigned long signature1; unsigned long signature2; unsigned long length; - unsigned long alder32; + unsigned long adler32; unsigned long version; unsigned long numDrivers; unsigned long reserved1; @@ -118,26 +83,8 @@ static long LoadDriverPList(char *dirSpec, char *name, long bundleType); static long LoadMatchedModules(void); static long MatchPersonalities(void); static long MatchLibraries(void); -static TagPtr GetProperty(TagPtr dict, char *key); static ModulePtr FindModule(char *name); -static long ParseXML(char *buffer, ModulePtr *module, TagPtr *personalities); -static long ParseNextTag(char *buffer, TagPtr *tag); -static long ParseTagList(char *buffer, TagPtr *tag, long type, long empty); -static long ParseTagKey(char *buffer, TagPtr *tag); -static long ParseTagString(char *buffer, TagPtr *tag); -static long ParseTagInteger(char *buffer, TagPtr *tag); -static long ParseTagData(char *buffer, TagPtr *tag); -static long ParseTagDate(char *buffer, TagPtr *tag); -static long ParseTagBoolean(char *buffer, TagPtr *tag, long type); -static long GetNextTag(char *buffer, char **tag, long *start); -static long FixDataMatchingTag(char *buffer, char *tag); -static TagPtr NewTag(void); -static void FreeTag(TagPtr tag); -static char *NewSymbol(char *string); -static void FreeSymbol(char *string); -#if DRIVER_DEBUG -static void DumpTag(TagPtr tag, long depth); -#endif +static long XML2Module(char *buffer, ModulePtr *module, TagPtr *personalities); static ModulePtr gModuleHead, gModuleTail; static TagPtr gPersonalityHead, gPersonalityTail; @@ -178,24 +125,29 @@ static long FileLoadDrivers(char *dirSpec, long plugin) ret = GetFileInfo(dirSpec, "Extensions.mkext", &flags, &time); if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat)) { ret = GetFileInfo(dirSpec, "Extensions", &flags, &time2); - if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeDirectory) || - (((gBootMode & kBootModeSafe) == 0) && (time > time2))) { + // use mkext if if it looks right or if the folder was bad + if ((ret != 0) || + ((flags & kFileTypeMask) != kFileTypeDirectory) || + (((gBootMode & kBootModeSafe) == 0) && (time == (time2 + 1)))) { sprintf(gDriverSpec, "%sExtensions.mkext", dirSpec); - printf("LoadDrivers: Loading from [%s]\n", gDriverSpec); + printf("FileLoadDrivers: Loading from [%s]\n", gDriverSpec); if (LoadDriverMKext(gDriverSpec) == 0) return 0; - } + } else if(time != (time2 + 1)) { + printf("mkext timestamp isn't quite right (delta: %d); ignoring...\n", + time2 - time); + } } strcat(dirSpec, "Extensions"); } - printf("LoadDrivers: Loading from [%s]\n", dirSpec); + printf("FileLoadDrivers: Loading from [%s]\n", dirSpec); index = 0; while (1) { ret = GetDirEntry(dirSpec, &index, &name, &flags, &time); if (ret == -1) break; - + // Make sure this is a directory. if ((flags & kFileTypeMask ) != kFileTypeDirectory) continue; @@ -218,9 +170,6 @@ static long FileLoadDrivers(char *dirSpec, long plugin) } ret = LoadDriverPList(dirSpec, gFileName, bundleType); - if (ret != 0) { - printf("LoadDrivers: failed\n"); - } if (!plugin) { ret = FileLoadDrivers(gDriverSpec, 1); @@ -262,19 +211,17 @@ static long LoadDriverMKext(char *fileSpec) { unsigned long driversAddr, driversLength, length; char segName[32]; - DriversPackage *package = (DriversPackage *)kLoadAddr; + DriversPackage *package; // Load the MKext. - length = LoadFile(fileSpec); + length = LoadThinFatFile(fileSpec, (void **)&package); if (length == -1) return -1; - ThinFatBinary((void **)&package, &length); - // Verify the MKext. if ((package->signature1 != kDriverPackageSignature1) || (package->signature2 != kDriverPackageSignature2)) return -1; if (package->length > kLoadSize) return -1; - if (package->alder32 != Alder32((char *)&package->version, + if (package->adler32 != Adler32((char *)&package->version, package->length - 0x10)) return -1; // Make space for the MKext. @@ -316,6 +263,7 @@ static long LoadDriverPList(char *dirSpec, char *name, long bundleType) (bundleType == kCFBundleType2) ? "Contents\\" : ""); length = LoadFile(gFileSpec); + *((char*)kLoadAddr + length) = '\0'; // terminate for parser safety if (length == -1) { free(tmpDriverPath); return -1; @@ -328,9 +276,10 @@ static long LoadDriverPList(char *dirSpec, char *name, long bundleType) } strncpy(buffer, (char *)kLoadAddr, length); - ret = ParseXML(buffer, &module, &personalities); + ret = XML2Module(buffer, &module, &personalities); free(buffer); if (ret != 0) { + // could trap ret == -2 and report missing OSBundleRequired free(tmpDriverPath); return -1; } @@ -357,7 +306,7 @@ static long LoadDriverPList(char *dirSpec, char *name, long bundleType) else gModuleTail->nextModule = module; gModuleTail = module; - // Add the persionalities to the personality list. + // Add the extracted personalities to the list. if (personalities) personalities = personalities->tag; while (personalities != 0) { if (gPersonalityHead == 0) gPersonalityHead = personalities->tag; @@ -387,14 +336,9 @@ static long LoadMatchedModules(void) if (prop != 0) { fileName = prop->string; sprintf(gFileSpec, "%s%s", module->driverPath, fileName); - length = LoadFile(gFileSpec); + length = LoadThinFatFile(gFileSpec, &driverModuleAddr); } else length = 0; if (length != -1) { - if (length != 0) { - driverModuleAddr = (void *)kLoadAddr; - ThinFatBinary(&driverModuleAddr, &length); - } - // Make make in the image area. driverLength = sizeof(DriverInfo) + module->plistLength + length; driverAddr = AllocateKernelMemory(driverLength); @@ -512,27 +456,6 @@ static long MatchLibraries(void) } -static TagPtr GetProperty(TagPtr dict, char *key) -{ - TagPtr tagList, tag; - - if (dict->type != kTagTypeDict) return 0; - - tag = 0; - tagList = dict->tag; - while (tagList) { - tag = tagList; - tagList = tag->tagNext; - - if ((tag->type != kTagTypeKey) || (tag->string == 0)) continue; - - if (!strcmp(tag->string, key)) return tag->tag; - } - - return 0; -} - - static ModulePtr FindModule(char *name) { ModulePtr module; @@ -549,33 +472,20 @@ static ModulePtr FindModule(char *name) return module; } - -static long ParseXML(char *buffer, ModulePtr *module, TagPtr *personalities) +/* turn buffer of XML into a ModulePtr for driver analysis */ +static long XML2Module(char *buffer, ModulePtr *module, TagPtr *personalities) { - long length, pos; - TagPtr moduleDict, required; + TagPtr moduleDict = NULL, required; ModulePtr tmpModule; - - pos = 0; - while (1) { - length = ParseNextTag(buffer + pos, &moduleDict); - if (length == -1) break; - pos += length; - - if (moduleDict == 0) continue; - - if (moduleDict->type == kTagTypeDict) break; - - FreeTag(moduleDict); - } - - if (length == -1) return -1; - + + if(ParseXML(buffer, &moduleDict) < 0) + return -1; + required = GetProperty(moduleDict, kPropOSBundleRequired); if ((required == 0) || (required->type != kTagTypeString) || !strcmp(required->string, "Safe Boot")) { FreeTag(moduleDict); - return -1; + return -2; } tmpModule = AllocateBootXMemory(sizeof(Module)); @@ -595,572 +505,3 @@ static long ParseXML(char *buffer, ModulePtr *module, TagPtr *personalities) return 0; } - - -static long ParseNextTag(char *buffer, TagPtr *tag) -{ - long length, pos; - char *tagName; - - length = GetNextTag(buffer, &tagName, 0); - if (length == -1) return -1; - - pos = length; - if (!strncmp(tagName, kXMLTagPList, 6)) { - length = 0; - } else if (!strcmp(tagName, kXMLTagDict)) { - length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0); - } else if (!strcmp(tagName, kXMLTagDict "/")) { - length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1); - } else if (!strcmp(tagName, kXMLTagKey)) { - length = ParseTagKey(buffer + pos, tag); - } else if (!strcmp(tagName, kXMLTagString)) { - length = ParseTagString(buffer + pos, tag); - } else if (!strcmp(tagName, kXMLTagInteger)) { - length = ParseTagInteger(buffer + pos, tag); - } else if (!strcmp(tagName, kXMLTagData)) { - length = ParseTagData(buffer + pos, tag); - } else if (!strcmp(tagName, kXMLTagDate)) { - length = ParseTagDate(buffer + pos, tag); - } else if (!strcmp(tagName, kXMLTagFalse)) { - length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse); - } else if (!strcmp(tagName, kXMLTagTrue)) { - length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue); - } else if (!strcmp(tagName, kXMLTagArray)) { - length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0); - } else if (!strcmp(tagName, kXMLTagArray "/")) { - length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1); - } else { - *tag = 0; - length = 0; - } - - if (length == -1) return -1; - - return pos + length; -} - - -static long ParseTagList(char *buffer, TagPtr *tag, long type, long empty) -{ - long length, pos; - TagPtr tagList, tmpTag; - - tagList = 0; - pos = 0; - - if (!empty) { - while (1) { - length = ParseNextTag(buffer + pos, &tmpTag); - if (length == -1) break; - pos += length; - - if (tmpTag == 0) break; - tmpTag->tagNext = tagList; - tagList = tmpTag; - } - - if (length == -1) { - FreeTag(tagList); - return -1; - } - } - - tmpTag = NewTag(); - if (tmpTag == 0) { - FreeTag(tagList); - return -1; - } - - tmpTag->type = type; - tmpTag->string = 0; - tmpTag->tag = tagList; - tmpTag->tagNext = 0; - - *tag = tmpTag; - - return pos; -} - - -static long ParseTagKey(char *buffer, TagPtr *tag) -{ - long length, length2; - char *string; - TagPtr tmpTag, subTag; - - length = FixDataMatchingTag(buffer, kXMLTagKey); - if (length == -1) return -1; - - length2 = ParseNextTag(buffer + length, &subTag); - if (length2 == -1) return -1; - - tmpTag = NewTag(); - if (tmpTag == 0) { - FreeTag(subTag); - return -1; - } - - string = NewSymbol(buffer); - if (string == 0) { - FreeTag(subTag); - FreeTag(tmpTag); - return -1; - } - - tmpTag->type = kTagTypeKey; - tmpTag->string = string; - tmpTag->tag = subTag; - tmpTag->tagNext = 0; - - *tag = tmpTag; - - return length + length2; -} - - -static long ParseTagString(char *buffer, TagPtr *tag) -{ - long length; - char *string; - TagPtr tmpTag; - - length = FixDataMatchingTag(buffer, kXMLTagString); - if (length == -1) return -1; - - tmpTag = NewTag(); - if (tmpTag == 0) return -1; - - string = NewSymbol(buffer); - if (string == 0) { - FreeTag(tmpTag); - return -1; - } - - tmpTag->type = kTagTypeString; - tmpTag->string = string; - tmpTag->tag = 0; - tmpTag->tagNext = 0; - - *tag = tmpTag; - - return length; -} - - -static long ParseTagInteger(char *buffer, TagPtr *tag) -{ - long length, integer; - TagPtr tmpTag; - - length = FixDataMatchingTag(buffer, kXMLTagInteger); - if (length == -1) return -1; - - tmpTag = NewTag(); - if (tmpTag == 0) return -1; - - integer = 0; - - tmpTag->type = kTagTypeInteger; - tmpTag->string = (char *)integer; - tmpTag->tag = 0; - tmpTag->tagNext = 0; - - *tag = tmpTag; - - return length; -} - - -static long ParseTagData(char *buffer, TagPtr *tag) -{ - long length; - TagPtr tmpTag; - - length = FixDataMatchingTag(buffer, kXMLTagData); - if (length == -1) return -1; - - tmpTag = NewTag(); - if (tmpTag == 0) return -1; - - tmpTag->type = kTagTypeData; - tmpTag->string = 0; - tmpTag->tag = 0; - tmpTag->tagNext = 0; - - *tag = tmpTag; - - return length; -} - - -static long ParseTagDate(char *buffer, TagPtr *tag) -{ - long length; - TagPtr tmpTag; - - length = FixDataMatchingTag(buffer, kXMLTagDate); - if (length == -1) return -1; - - tmpTag = NewTag(); - if (tmpTag == 0) return -1; - - tmpTag->type = kTagTypeDate; - tmpTag->string = 0; - tmpTag->tag = 0; - tmpTag->tagNext = 0; - - *tag = tmpTag; - - return length; -} - - -static long ParseTagBoolean(char *buffer, TagPtr *tag, long type) -{ - TagPtr tmpTag; - - tmpTag = NewTag(); - if (tmpTag == 0) return -1; - - tmpTag->type = type; - tmpTag->string = 0; - tmpTag->tag = 0; - tmpTag->tagNext = 0; - - *tag = tmpTag; - - return 0; -} - - -static long GetNextTag(char *buffer, char **tag, long *start) -{ - long cnt, cnt2; - - if (tag == 0) return -1; - - // Find the start of the tag. - cnt = 0; - while ((buffer[cnt] != '\0') && (buffer[cnt] != '<')) cnt++; - if (buffer[cnt] == '\0') return -1; - - // Find the end of the tag. - cnt2 = cnt + 1; - while ((buffer[cnt2] != '\0') && (buffer[cnt2] != '>')) cnt2++; - if (buffer[cnt2] == '\0') return -1; - - // Fix the tag data. - *tag = buffer + cnt + 1; - buffer[cnt2] = '\0'; - if (start) *start = cnt; - - return cnt2 + 1; -} - - -static long FixDataMatchingTag(char *buffer, char *tag) -{ - long length, start, stop; - char *endTag; - - start = 0; - while (1) { - length = GetNextTag(buffer + start, &endTag, &stop); - if (length == -1) return -1; - - if ((*endTag == '/') && !strcmp(endTag + 1, tag)) break; - start += length; - } - - buffer[start + stop] = '\0'; - - return start + length; -} - - -#define kTagsPerBlock (0x1000) - -static TagPtr gTagsFree; - -static TagPtr NewTag(void) -{ - long cnt; - TagPtr tag; - - if (gTagsFree == 0) { - tag = (TagPtr)AllocateBootXMemory(kTagsPerBlock * sizeof(Tag)); - if (tag == 0) return 0; - - // Initalize the new tags. - for (cnt = 0; cnt < kTagsPerBlock; cnt++) { - tag[cnt].type = kTagTypeNone; - tag[cnt].string = 0; - tag[cnt].tag = 0; - tag[cnt].tagNext = tag + cnt + 1; - } - tag[kTagsPerBlock - 1].tagNext = 0; - - gTagsFree = tag; - } - - tag = gTagsFree; - gTagsFree = tag->tagNext; - - return tag; -} - - -static void FreeTag(TagPtr tag) -{ - return; - if (tag == 0) return; - - if (tag->string) FreeSymbol(tag->string); - - FreeTag(tag->tag); - FreeTag(tag->tagNext); - - // Clear and free the tag. - tag->type = kTagTypeNone; - tag->string = 0; - tag->tag = 0; - tag->tagNext = gTagsFree; - gTagsFree = tag; -} - - -struct Symbol { - long refCount; - struct Symbol *next; - char string[1]; -}; -typedef struct Symbol Symbol, *SymbolPtr; - -static SymbolPtr FindSymbol(char *string, SymbolPtr *prevSymbol); - -static SymbolPtr gSymbolsHead; - - -static char *NewSymbol(char *string) -{ - SymbolPtr symbol; - - // Look for string in the list of symbols. - symbol = FindSymbol(string, 0); - - // Add the new symbol. - if (symbol == 0) { - symbol = AllocateBootXMemory(sizeof(Symbol) + strlen(string)); - if (symbol == 0) return 0; - - // Set the symbol's data. - symbol->refCount = 0; - strcpy(symbol->string, string); - - // Add the symbol to the list. - symbol->next = gSymbolsHead; - gSymbolsHead = symbol; - } - - // Update the refCount and return the string. - symbol->refCount++; - return symbol->string; -} - - -static void FreeSymbol(char *string) -{ -#if 0 - SymbolPtr symbol, prev; - - // Look for string in the list of symbols. - symbol = FindSymbol(string, &prev); - if (symbol == 0) return; - - // Update the refCount. - symbol->refCount--; - - if (symbol->refCount != 0) return; - - // Remove the symbol from the list. - if (prev != 0) prev->next = symbol->next; - else gSymbolsHead = symbol->next; - - // Free the symbol's memory. - free(symbol); -#endif -} - - -static SymbolPtr FindSymbol(char *string, SymbolPtr *prevSymbol) -{ - SymbolPtr symbol, prev; - - symbol = gSymbolsHead; - prev = 0; - - while (symbol != 0) { - if (!strcmp(symbol->string, string)) break; - - prev = symbol; - symbol = symbol->next; - } - - if ((symbol != 0) && (prevSymbol != 0)) *prevSymbol = prev; - - return symbol; -} - -#if DRIVER_DEBUG -static void DumpTagDict(TagPtr tag, long depth); -static void DumpTagKey(TagPtr tag, long depth); -static void DumpTagString(TagPtr tag, long depth); -static void DumpTagInteger(TagPtr tag, long depth); -static void DumpTagData(TagPtr tag, long depth); -static void DumpTagDate(TagPtr tag, long depth); -static void DumpTagBoolean(TagPtr tag, long depth); -static void DumpTagArray(TagPtr tag, long depth); -static void DumpSpaces(long depth); - -static void DumpTag(TagPtr tag, long depth) -{ - if (tag == 0) return; - - switch (tag->type) { - case kTagTypeDict : - DumpTagDict(tag, depth); - break; - - case kTagTypeKey : - DumpTagKey(tag, depth); - break; - - case kTagTypeString : - DumpTagString(tag, depth); - break; - - case kTagTypeInteger : - DumpTagInteger(tag, depth); - break; - - case kTagTypeData : - DumpTagData(tag, depth); - break; - - case kTagTypeDate : - DumpTagDate(tag, depth); - break; - - case kTagTypeFalse : - case kTagTypeTrue : - DumpTagBoolean(tag, depth); - break; - - case kTagTypeArray : - DumpTagArray(tag, depth); - break; - - default : - break; - } -} - - -static void DumpTagDict(TagPtr tag, long depth) -{ - TagPtr tagList; - - if (tag->tag == 0) { - DumpSpaces(depth); - printf("<%s/>\n", kXMLTagDict); - } else { - DumpSpaces(depth); - printf("<%s>\n", kXMLTagDict); - - tagList = tag->tag; - while (tagList) { - DumpTag(tagList, depth + 1); - tagList = tagList->tagNext; - } - - DumpSpaces(depth); - printf("\n", kXMLTagDict); - } -} - - -static void DumpTagKey(TagPtr tag, long depth) -{ - DumpSpaces(depth); - printf("<%s>%s\n", kXMLTagKey, tag->string, kXMLTagKey); - - DumpTag(tag->tag, depth); -} - - -static void DumpTagString(TagPtr tag, long depth) -{ - DumpSpaces(depth); - printf("<%s>%s\n", kXMLTagString, tag->string, kXMLTagString); -} - - -static void DumpTagInteger(TagPtr tag, long depth) -{ - DumpSpaces(depth); - printf("<%s>%x\n", kXMLTagInteger, tag->string, kXMLTagInteger); -} - - -static void DumpTagData(TagPtr tag, long depth) -{ - DumpSpaces(depth); - printf("<%s>%x\n", kXMLTagData, tag->string, kXMLTagData); -} - - -static void DumpTagDate(TagPtr tag, long depth) -{ - DumpSpaces(depth); - printf("<%s>%x\n", kXMLTagDate, tag->string, kXMLTagDate); -} - - -static void DumpTagBoolean(TagPtr tag, long depth) -{ - DumpSpaces(depth); - printf("<%s>\n", (tag->type == kTagTypeTrue) ? kXMLTagTrue : kXMLTagFalse); -} - - -static void DumpTagArray(TagPtr tag, long depth) -{ - TagPtr tagList; - - if (tag->tag == 0) { - DumpSpaces(depth); - printf("<%s/>\n", kXMLTagArray); - } else { - DumpSpaces(depth); - printf("<%s>\n", kXMLTagArray); - - tagList = tag->tag; - while (tagList) { - DumpTag(tagList, depth + 1); - tagList = tagList->tagNext; - } - - DumpSpaces(depth); - printf("\n", kXMLTagArray); - } -} - - -static void DumpSpaces(long depth) -{ - long cnt; - - for (cnt = 0; cnt < (depth * 4); cnt++) putchar(' '); -} -#endif diff --git a/bootx.tproj/sl.subproj/elf.c b/bootx.tproj/sl.subproj/elf.c index 0b8f6e1..f1881be 100644 --- a/bootx.tproj/sl.subproj/elf.c +++ b/bootx.tproj/sl.subproj/elf.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/sl.subproj/elf.h b/bootx.tproj/sl.subproj/elf.h index 7de0c01..80c1e0e 100644 --- a/bootx.tproj/sl.subproj/elf.h +++ b/bootx.tproj/sl.subproj/elf.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/sl.subproj/failedboot.h b/bootx.tproj/sl.subproj/failedboot.h index 0b74984..51142fd 100644 --- a/bootx.tproj/sl.subproj/failedboot.h +++ b/bootx.tproj/sl.subproj/failedboot.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/sl.subproj/lzss.c b/bootx.tproj/sl.subproj/lzss.c index 579a573..ac251fb 100644 --- a/bootx.tproj/sl.subproj/lzss.c +++ b/bootx.tproj/sl.subproj/lzss.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/sl.subproj/macho.c b/bootx.tproj/sl.subproj/macho.c index c352e67..9fb35aa 100644 --- a/bootx.tproj/sl.subproj/macho.c +++ b/bootx.tproj/sl.subproj/macho.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -46,7 +43,7 @@ static unsigned long gPPCAddress; long ThinFatBinaryMachO(void **binary, unsigned long *length) { - unsigned long nfat, swapped, size; + unsigned long nfat, swapped, size = 0; struct fat_header *fhp = (struct fat_header *)*binary; struct fat_arch *fap = (struct fat_arch *)((unsigned long)*binary + sizeof(struct fat_header)); @@ -84,7 +81,7 @@ long DecodeMachO(void *binary) { struct mach_header *mH; long ncmds, cmdBase, cmd, cmdsize, headerBase, headerAddr, headerSize; - long cnt, ret; + long cnt, ret = 0; gPPCAddress = (unsigned long)binary; diff --git a/bootx.tproj/sl.subproj/main.c b/bootx.tproj/sl.subproj/main.c index d1a1e6a..fac6f82 100644 --- a/bootx.tproj/sl.subproj/main.c +++ b/bootx.tproj/sl.subproj/main.c @@ -3,40 +3,38 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ /* * main.c - Main functions for BootX. * - * Copyright (c) 1998-2003 Apple Computer, Inc. + * Copyright (c) 1998-2004 Apple Computer, Inc. * * DRI: Josh de Cesare */ #include +#include "aes.h" static void Start(void *unused1, void *unused2, ClientInterfacePtr ciPtr); static void Main(ClientInterfacePtr ciPtr); static long InitEverything(ClientInterfacePtr ciPtr); -static long DecodeKernel(void); +static long DecodeKernel(void *binary); static long SetUpBootArgs(void); static long CallKernel(void); static void FailToBoot(long num); @@ -44,6 +42,7 @@ static long InitMemoryMap(void); static long GetOFVersion(void); static long TestForKey(long key); static long GetBootPaths(void); +static long ReadBootPlist(char *devSpec); const unsigned long StartTVector[2] = {(unsigned long)Start, 0}; @@ -68,6 +67,7 @@ long gBootFileType; char gHaveKernelCache = 0; char gBootDevice[256]; char gBootFile[256]; +TagPtr gBootDict = NULL; static char gBootKernelCacheFile[512]; static char gExtensionsSpec[4096]; static char gCacheNameAdler[64 + sizeof(gBootFile)]; @@ -77,7 +77,7 @@ char gTempStr[4096]; long *gDeviceTreeMMTmp = 0; -long gOFVersion; +long gOFVersion = 0; char *gKeyMap; @@ -102,6 +102,8 @@ static unsigned long gOFSPRG1Save; static unsigned long gOFSPRG2Save; static unsigned long gOFSPRG3Save; +//int gDebugCount = 0; + // Private Functions static void Start(void *unused1, void *unused2, ClientInterfacePtr ciPtr) @@ -116,20 +118,25 @@ static void Start(void *unused1, void *unused2, ClientInterfacePtr ciPtr) } + static void Main(ClientInterfacePtr ciPtr) { long ret; int trycache; - long flags, cachetime, time; + long flags, cachetime, kerneltime, exttime = 0; + void *binary = (void *)kLoadAddr; ret = InitEverything(ciPtr); if (ret != 0) Exit(); - + + // Get or infer the boot paths. ret = GetBootPaths(); if (ret != 0) FailToBoot(1); +#if kFailToBoot DrawSplashScreen(0); +#endif while (ret == 0) { trycache = (0 == (gBootMode & kBootModeSafe)) @@ -138,20 +145,26 @@ static void Main(ClientInterfacePtr ciPtr) if (trycache && (gBootFileType == kBlockDeviceType)) do { // if we haven't found the kernel yet, don't use the cache - ret = GetFileInfo(NULL, gBootFile, &flags, &time); + ret = GetFileInfo(NULL, gBootFile, &flags, &kerneltime); if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)) { trycache = 0; break; } ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime); if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat) - || (cachetime < time)) { + || (cachetime < kerneltime)) { trycache = 0; break; } - ret = GetFileInfo(gExtensionsSpec, "Extensions", &flags, &time); + ret = GetFileInfo(gExtensionsSpec, "Extensions", &flags, &exttime); if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory) - && (cachetime < time)) { + && (cachetime < exttime)) { + trycache = 0; + break; + } + if (kerneltime > exttime) + exttime = kerneltime; + if (cachetime != (exttime + 1)) { trycache = 0; break; } @@ -160,13 +173,12 @@ static void Main(ClientInterfacePtr ciPtr) if (trycache) { ret = LoadFile(gBootKernelCacheFile); if (ret != -1) { - ret = DecodeKernel(); + ret = DecodeKernel(binary); if (ret != -1) break; } } - ret = LoadFile(gBootFile); - if (ret != -1) - ret = DecodeKernel(); + ret = LoadThinFatFile(gBootFile, &binary); + if (ret != -1) ret = DecodeKernel(binary); if (ret != -1) break; ret = GetBootPaths(); @@ -180,7 +192,9 @@ static void Main(ClientInterfacePtr ciPtr) if (ret != 0) FailToBoot(4); } +#if kFailToBoot DrawSplashScreen(1); +#endif ret = SetUpBootArgs(); if (ret != 0) FailToBoot(5); @@ -190,6 +204,30 @@ static void Main(ClientInterfacePtr ciPtr) FailToBoot(6); } +static uint32_t UnescapeData(const uint8_t * src, + uint32_t srcLen, + uint8_t * dst, + uint32_t dstMaxLen) +{ + uint32_t cnt, cnt2, dstLen = 0; + uint8_t byte; + + for (cnt = 0; cnt < srcLen;) { + byte = src[cnt++]; + if (byte == 0xFF) { + byte = src[cnt++]; + cnt2 = byte & 0x7F; + byte = (byte & 0x80) ? 0xFF : 0x00; + } else + cnt2 = 1; + while (cnt2--) { + if (dstLen >= dstMaxLen) + return (-1); + dst[dstLen++] = byte; + } + } + return (dstLen); +} static long InitEverything(ClientInterfacePtr ciPtr) { @@ -293,80 +331,82 @@ static long InitEverything(ClientInterfacePtr ciPtr) // printf now works. printf("\n\nMac OS X Loader\n"); - // Test for Safe Boot Mode. - if (((gBootMode & kBootModeSecure) == 0) && TestForKey(kShiftKey)) { + // Test for Safe Boot Mode; Shift and not Delete. + if (((gBootMode & kBootModeSecure) == 0) + && TestForKey(kShiftKey) && !TestForKey(kDeleteKey)) { gBootMode |= kBootModeSafe; } - - // Claim memory for the FS Cache. - if (Claim(kFSCacheAddr, kFSCacheSize, 0) == 0) { - printf("Claim for fs cache failed.\n"); - return -1; - } - - // Claim memory for malloc. - if (Claim(kMallocAddr, kMallocSize, 0) == 0) { - printf("Claim for malloc failed.\n"); - return -1; - } - malloc_init((char *)kMallocAddr, kMallocSize); - - // Claim memory for the Load Addr. - mem_base = Claim(kLoadAddr, kLoadSize, 0); - if (mem_base == 0) { - printf("Claim for Load Area failed.\n"); - return -1; - } - - // Claim the memory for the Image Addr - if (gOFVersion >= kOFVersion3x) { - mem_base = Claim(kImageAddr, kImageSize, 0); - if (mem_base == 0) { - printf("Claim for Image Area failed.\n"); + + { + // Claim memory for the FS Cache. + if (Claim(kFSCacheAddr, kFSCacheSize, 0) == 0) { + printf("Claim for fs cache failed.\n"); return -1; } - } else { - // Claim the 1:1 mapped chunks first. - mem_base = Claim(kImageAddr0, kImageSize0, 0); - mem_base2 = Claim(kImageAddr2, kImageSize2, 0); - if ((mem_base == 0) || (mem_base2 == 0)) { - printf("Claim for Image Area failed.\n"); + + // Claim memory for malloc. + if (Claim(kMallocAddr, kMallocSize, 0) == 0) { + printf("Claim for malloc failed.\n"); return -1; } + malloc_init((char *)kMallocAddr, kMallocSize); - // Unmap the old xcoff stack. - CallMethod(2, 0, gMMUIH, "unmap", 0x00380000, 0x00080000); - - // Grap the physical memory then the logical. - CallMethod(3, 1, gMemoryIH, "claim", - kImageAddr1Phys, kImageSize1, 0, &mem_base); - CallMethod(3, 1, gMMUIH, "claim", - kImageAddr1, kImageSize1, 0, &mem_base2); - if ((mem_base == 0) || (mem_base2 == 0)) { - printf("Claim for Image Area failed.\n"); + // Claim memory for the Load Addr. + mem_base = Claim(kLoadAddr, kLoadSize, 0); + if (mem_base == 0) { + printf("Claim for Load Area failed.\n"); return -1; } - // Map them together. - CallMethod(4, 0, gMMUIH, "map", - kImageAddr1Phys, kImageAddr1, kImageSize1, 0); - } - - bzero((char *)kImageAddr, kImageSize); - - // Allocate some space for the Vector Save area. - gVectorSaveAddr = AllocateBootXMemory(kVectorSize); - if (gVectorSaveAddr == 0) { - printf("Allocation for the Vector Save Area failed.\n"); - return -1; - } - - // Find all the displays and set them up. - ret = InitDisplays(); - if (ret != 0) { - printf("InitDisplays failed.\n"); - return -1; - } + // Claim the memory for the Image Addr + if (gOFVersion >= kOFVersion3x) { + mem_base = Claim(kImageAddr, kImageSize, 0); + if (mem_base == 0) { + printf("Claim for Image Area failed.\n"); + return -1; + } + } else { + // Claim the 1:1 mapped chunks first. + mem_base = Claim(kImageAddr0, kImageSize0, 0); + mem_base2 = Claim(kImageAddr2, kImageSize2, 0); + if ((mem_base == 0) || (mem_base2 == 0)) { + printf("Claim for Image Area failed.\n"); + return -1; + } + + // Unmap the old xcoff stack. + CallMethod(2, 0, gMMUIH, "unmap", 0x00380000, 0x00080000); + + // Grab the physical memory then the logical. + CallMethod(3, 1, gMemoryIH, "claim", + kImageAddr1Phys, kImageSize1, 0, &mem_base); + CallMethod(3, 1, gMMUIH, "claim", + kImageAddr1, kImageSize1, 0, &mem_base2); + if ((mem_base == 0) || (mem_base2 == 0)) { + printf("Claim for Image Area failed.\n"); + return -1; + } + + // Map them together. + CallMethod(4, 0, gMMUIH, "map", + kImageAddr1Phys, kImageAddr1, kImageSize1, 0); + } + + bzero((char *)kImageAddr, kImageSize); + + // Allocate some space for the Vector Save area. + gVectorSaveAddr = AllocateBootXMemory(kVectorSize); + if (gVectorSaveAddr == 0) { + printf("Allocation for the Vector Save Area failed.\n"); + return -1; + } + // Find all the displays and set them up. + ret = InitDisplays(1); + if (ret != 0) { + printf("InitDisplays failed.\n"); + return -1; + } + } return 0; } @@ -382,11 +422,10 @@ long ThinFatBinary(void **binary, unsigned long *length) return ret; } -static long DecodeKernel(void) +static long DecodeKernel(void *binary) { - void *binary = (void *)kLoadAddr; long ret; - compressed_kernel_header * kernel_header = (compressed_kernel_header *) kLoadAddr; + compressed_kernel_header *kernel_header = (compressed_kernel_header *)binary; u_int32_t size; if (kernel_header->signature == 'comp') { @@ -405,7 +444,7 @@ static long DecodeKernel(void) return -1; } if (kernel_header->adler32 != - Alder32(binary, kernel_header->uncompressed_size)) { + Adler32(binary, kernel_header->uncompressed_size)) { printf("adler mismatch\n"); return -1; } @@ -427,7 +466,7 @@ static long SetUpBootArgs(void) long graphicsBoot = 1; long ret, cnt, size, dash; long sKey, vKey, keyPos; - char ofBootArgs[128], *ofArgs, tc, keyStr[8]; + char ofBootArgs[240], *ofArgs, tc, keyStr[8]; unsigned char mem_regs[kMaxDRAMBanks*16]; unsigned long mem_banks, bank_shift; @@ -465,9 +504,9 @@ static long SetUpBootArgs(void) // Create the command line. if (gOFVersion < kOFVersion3x) { ofBootArgs[0] = ' '; - size = GetProp(gChosenPH, "machargs", ofBootArgs + 1, 126); + size = GetProp(gChosenPH, "machargs", ofBootArgs + 1, (sizeof(ofBootArgs) - 2)); if (size == -1) { - size = GetProp(gOptionsPH, "boot-command", ofBootArgs, 127); + size = GetProp(gOptionsPH, "boot-command", ofBootArgs, (sizeof(ofBootArgs) - 1)); if (size == -1) ofBootArgs[0] = '\0'; else ofBootArgs[size] = '\0'; // Look for " bootr" but skip the number. @@ -480,7 +519,7 @@ static long SetUpBootArgs(void) sprintf(gTempStr, "0 bootr%s", ofBootArgs); SetProp(gOptionsPH, "boot-command", gTempStr, strlen(gTempStr)); } else { - size = GetProp(gOptionsPH, "boot-args", ofBootArgs, 127); + size = GetProp(gOptionsPH, "boot-args", ofBootArgs, (sizeof(ofBootArgs) - 1)); if (size == -1) ofBootArgs[0] = '\0'; else ofBootArgs[size] = '\0'; } @@ -589,7 +628,7 @@ static long SetUpBootArgs(void) bzero(args->PhysicalDRAM + mem_banks, (kMaxDRAMBanks - mem_banks) * sizeof(DRAMBank)); // Get the video info - GetMainScreenPH(&args->Video); + GetMainScreenPH(&args->Video, 1); args->Video.v_display = graphicsBoot; // Add the DeviceTree to the memory-map. @@ -660,7 +699,7 @@ static long CallKernel(void) // Call the Kernel's entry point (*(void (*)())gKernelEntryPoint)(gBootArgsAddr, kMacOSXSignature); - + // Restore OF's Exception Vectors bcopy(gOFVectorSave, 0x0, 0x3000); for (cnt = 0; cnt < kVectorSize; cnt += 0x20) { @@ -685,12 +724,13 @@ static long CallKernel(void) static void FailToBoot(long num) { + // useful for those holding down command-v ... + printf("FailToBoot: %d\n", num); #if kFailToBoot DrawFailedBootPicture(); while (1); num = 0; #else - printf("FailToBoot: %d\n", num); Enter(); // For debugging #endif } @@ -733,7 +773,7 @@ static long GetOFVersion(void) tmpStr = versStr + 15; } else if (!strncmp(versStr, "OpenFirmware ", 13)) { tmpStr = versStr + 13; - } else return -1; + } else return -1; // Clasify by each instance as needed... switch (*tmpStr) { @@ -790,6 +830,7 @@ static long TestForKey(long key) case kOptKey : keyNum = 229; break; case kShiftKey : keyNum = 230; break; case kControlKey : keyNum = 231; break; + case kDeleteKey : keyNum = 45; break; default : keyNum = -1; break; } @@ -812,19 +853,46 @@ static long GetBootPaths(void) { long ret, cnt, cnt2, cnt3, cnt4, size, partNum, bootplen, bsdplen; unsigned long adler32; - char *filePath, *buffer; + char *filePath, *buffer, uuidStr[64]; if (gBootSourceNumber == -1) { - // Get the boot-device + // Get the boot device and derive its type + // (try chosen "bootpath", then boot-device in the options) size = GetProp(gChosenPH, "bootpath", gBootDevice, 255); gBootDevice[size] = '\0'; if (gBootDevice[0] == '\0') { size = GetProp(gOptionsPH, "boot-device", gBootDevice, 255); gBootDevice[size] = '\0'; } - gBootDeviceType = GetDeviceType(gBootDevice); +// hardcode to my Apple_Boot before my Apple_RAID +// debug: override boot device to boot from disk even if OF used TFTP +//printf("old gBootDevice: %s\n", gBootDevice); +//strcpy(gBootDevice, "fw/node@d0010100007a9d/sbp-2@c000/@0:12"); // SmartDisk +//strcpy(gBootDevice, "fw/node@d04b491d060252/sbp-2@c000/@0:9"); // mconcatI +//strcpy(gBootDevice, "fw/node@d04b491d060252/sbp-2@c000/@0:11"); // mconcatI +//strcpy(gBootDevice, "fw/node@d04b491d075f57/sbp-2@c000/@0:2"); // mconcatII +//strcpy(gBootDevice, "fw/node@d04b491d075f57/sbp-2@c000/@0:4"); // mconcatII +//strcpy(gBootDevice, "fw/node@50770e0000676f/sbp-2@4000/@0:3"); // m120 +//strcpy(gBootDevice, "fw/node@50770e0000725b/sbp-2@4000/@0:3"); // m120 + + + // Look for Boot.plist-based booter stuff (like RAID :) + ret = ReadBootPlist(gBootDevice); + if (ret == 0) { + // success -> gBootDevice = "AppleRAID/#:0,\\\\:tbxi" + (void)LookForRAID(gBootDict); // could take gBootDevice? + } - // Get the boot-file + + // note RAID itself is of "block" type like members + gBootDeviceType = GetDeviceType(gBootDevice); + if(gBootDeviceType == -1) { + printf("Could not find boot device %s\n", gBootDevice); + return -1; + } + + + // Get the boot file (e.g. mach_kernel) size = GetProp(gChosenPH, "bootargs", gBootFile, 256); gBootFile[size] = '\0'; @@ -843,6 +911,7 @@ static long GetBootPaths(void) } } } +// gBootSourceNumberMax = 2; // helpful to prevent lots of probing if (gBootFileType == kNetworkDeviceType) { SetProp(Peer(0), "net-boot", NULL, 0); @@ -948,7 +1017,7 @@ static long GetBootPaths(void) bzero(gCacheNameAdler + 64, sizeof(gBootFile)); strcpy(gCacheNameAdler + 64, gBootFile); - adler32 = Alder32(gCacheNameAdler, sizeof(gCacheNameAdler)); + adler32 = Adler32(gCacheNameAdler, sizeof(gCacheNameAdler)); strncpy(gBootKernelCacheFile, gBootDevice, cnt + 1); sprintf(gBootKernelCacheFile + cnt + 1, @@ -964,7 +1033,10 @@ static long GetBootPaths(void) // Figure out the root dir. ret = ConvertFileSpec(gBootFile, gExtensionsSpec, &filePath); - if (ret == -1) return -1; + if (ret == -1) { + printf("Failed to determine root directory\n"); + return -1; + } strcat(gExtensionsSpec, ","); @@ -989,13 +1061,49 @@ static long GetBootPaths(void) strcpy(gExtensionsSpec + cnt, "System\\Library\\"); } + // technically could just do this once at the end SetProp(gChosenPH, "rootpath", gBootFile, strlen(gBootFile) + 1); + + if (GetFSUUID(gBootFile, uuidStr) == 0) { + printf("setting boot-uuid to: %s\n", uuidStr); + SetProp(gChosenPH, "boot-uuid", uuidStr, strlen(uuidStr) + 1); + } gBootSourceNumber++; return 0; } +#define BOOTPLIST_PATH "com.apple.Boot.plist" + +// ReadBootPlist could live elsewhere +static long ReadBootPlist(char *devSpec) +{ + char plistSpec[256]; + int len; + + do { + // construct the Boot.plist spec + if (ConvertFileSpec(devSpec, plistSpec, NULL)) break; + strncat(plistSpec, ",\\\\", 255-strlen(plistSpec)); + strncat(plistSpec, BOOTPLIST_PATH, 255-strlen(plistSpec)); + + // load the contents + if ((len = LoadFile(plistSpec)) < 0) break; + // we could try for the root as well as the blessed folder + *((char*)kLoadAddr + len) = '\0'; // terminate for parser safety + + if (ParseXML((char*)kLoadAddr, &gBootDict) < 0 || !gBootDict) { + printf("couldn't parse %s\n", BOOTPLIST_PATH); + break; + } + + return 0; + } while(0); + + return -1; +} + // Public Functions long GetDeviceType(char *devSpec) @@ -1004,6 +1112,9 @@ long GetDeviceType(char *devSpec) long size; char deviceType[32]; + if (isRAIDPath(devSpec)) + return kBlockDeviceType; + ph = FindDevice(devSpec); if (ph == -1) return -1; @@ -1117,29 +1228,36 @@ long AllocateMemoryRange(char *rangeName, long start, long length) return 0; } +#define BASE 65521L /* largest prime smaller than 65536 */ +#define NMAX 5000 +// NMAX (was 5521) the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 + +#define DO1(buf,i) {s1 += buf[i]; s2 += s1;} +#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); +#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); +#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); +#define DO16(buf) DO8(buf,0); DO8(buf,8); -unsigned long Alder32(unsigned char *buffer, long length) +unsigned long Adler32(unsigned char *buf, long len) { - long cnt; - unsigned long result, lowHalf, highHalf; - - lowHalf = 1; - highHalf = 0; - - for (cnt = 0; cnt < length; cnt++) { - if ((cnt % 5000) == 0) { - lowHalf %= 65521L; - highHalf %= 65521L; - } - - lowHalf += buffer[cnt]; - highHalf += lowHalf; - } + unsigned long s1 = 1; // adler & 0xffff; + unsigned long s2 = 0; // (adler >> 16) & 0xffff; + int k; - lowHalf %= 65521L; - highHalf %= 65521L; - - result = (highHalf << 16) | lowHalf; - - return result; + while (len > 0) { + k = len < NMAX ? len : NMAX; + len -= k; + while (k >= 16) { + DO16(buf); + buf += 16; + k -= 16; + } + if (k != 0) do { + s1 += *buf++; + s2 += s1; + } while (--k); + s1 %= BASE; + s2 %= BASE; + } + return (s2 << 16) | s1; } diff --git a/bootx.tproj/sl.subproj/netboot.h b/bootx.tproj/sl.subproj/netboot.h index 730e2ac..67c984f 100644 --- a/bootx.tproj/sl.subproj/netboot.h +++ b/bootx.tproj/sl.subproj/netboot.h @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/bootx.tproj/sl.subproj/plist.c b/bootx.tproj/sl.subproj/plist.c new file mode 100644 index 0000000..fb8c6c2 --- /dev/null +++ b/bootx.tproj/sl.subproj/plist.c @@ -0,0 +1,840 @@ +/* + * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. + * + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * plist.c - plist parsing functions + * + * Copyright (c) 2000-2005 Apple Computer, Inc. + * + * DRI: Josh de Cesare + * code split out from drivers.c by Soren Spies, 2005 + */ + +#include + +#define kXMLTagPList "plist" +#define kXMLTagDict "dict" +#define kXMLTagKey "key" +#define kXMLTagString "string" +#define kXMLTagInteger "integer" +#define kXMLTagData "data" +#define kXMLTagDate "date" +#define kXMLTagFalse "false/" +#define kXMLTagTrue "true/" +#define kXMLTagArray "array" +// for back-references used by libkern serializer +#define kXMLTagReference "reference" +#define kXMLTagID "ID=" +#define kXMLTagIDREF "IDREF=" + +static long ParseNextTag(char *buffer, TagPtr *tag); +static long ParseTagList(char *buffer, TagPtr *tag, long type, long empty); +static long ParseTagKey(char *buffer, TagPtr *tag); +static long ParseTagString(char *buffer, TagPtr *tag); +static long ParseTagInteger(char *buffer, TagPtr *tag); +static long ParseTagData(char *buffer, TagPtr *tag); +static long ParseTagDate(char *buffer, TagPtr *tag); +static long ParseTagBoolean(char *buffer, TagPtr *tag, long type); +static long GetNextTag(char *buffer, char **tag, long *start, long *empty); +static long FixDataMatchingTag(char *buffer, char *tag); +static TagPtr NewTag(void); +static char *NewSymbol(char *string); +static void FreeSymbol(char *string); + +#if PLIST_DEBUG +// for debugging parsing failures +static int gTagsParsed; +static char *gLastTag; +#endif + +TagPtr GetProperty(TagPtr dict, char *key) +{ + TagPtr tagList, tag; + + if (dict->type != kTagTypeDict) return 0; + + tag = 0; // ? + tagList = dict->tag; + while (tagList) { + tag = tagList; + tagList = tag->tagNext; + + if ((tag->type != kTagTypeKey) || (tag->string == 0)) continue; + + if (!strcmp(tag->string, key)) { + return tag->tag; + } + } + + return 0; +} + +// intended to look for two versions of the tag; now just for sizeof +#define MATCHTAG(parsedTag, keyTag) \ + (!strncmp(parsedTag, keyTag, sizeof(keyTag)-1)) + +// a tag cache for iokit's super-plists (alas, to merge w/"Symbol" cache?) +// we're not going to use the 0th element; it's used by the whole dict anyway +static int lastid; +static int numids = 0; // skipping 0th +static TagPtr *idtags; + +#define INITIALIDS 10 +static long InitTagCache() +{ + long rval = -1; + + do { + lastid = 0; + numids = INITIALIDS; + idtags = (TagPtr*)malloc(numids * sizeof(*idtags)); + if (!idtags) break; + bzero(idtags, numids * sizeof(*idtags)); + + rval = 0; + } while(0); + + return rval; +} + +static void FreeTagCache() +{ + if (idtags) + free(idtags); + idtags = NULL; +} + +// get the number from (e.g.): ID="3" +static int ExtractID(char *tagName, int tagLen) +{ + char *idptr = tagName + tagLen; + int rval = 0; + + while(*idptr != '>') { + idptr++; + if (MATCHTAG(idptr, kXMLTagID)) { + rval = strtol(idptr + sizeof(kXMLTagID)-1+1, 0, 0); // -NUL +" + break; + } else if (MATCHTAG(idptr, kXMLTagIDREF)) { + rval = strtol(idptr + sizeof(kXMLTagIDREF)-1+1, 0, 0); // -NUL +" + break; + } + // there can be multiple modifiers (integers have 'size' first) + while(*idptr != ' ' && *idptr != '>') idptr++; + } + + return rval; +} + +static TagPtr TagFromRef(char *tagName, int tagLen) +{ + int refidx = ExtractID(tagName, tagLen); + TagPtr rval = NULL; + + if (refidx <= lastid) + rval = idtags[refidx]; + + return rval; +} + +static long SaveTagRef(TagPtr tag, int tagid) +{ + + // bumped any time we skip an unsupported tag + if (tagid != ++lastid) { + if (tagid > lastid) { + lastid = tagid; + } + else { + printf("invalid plist: tagid (%d) < lastid (%d)??\n", tagid, lastid); + return -1; + } + } + + // upsize idtags if needed + if (numids <= lastid) { + while(numids <= lastid) + numids *= 2; + idtags = (TagPtr*)realloc(idtags, numids * sizeof(*idtags)); + if (!idtags) return -1; + } + + // and record for later + idtags[lastid] = tag; + + return 0; +} + +long ParseXML(char *buffer, TagPtr *dict) +{ + long length, pos; + TagPtr moduleDict; + +#if PLIST_DEBUG + gTagsParsed = 0; + gLastTag = NULL; +#endif + if (InitTagCache()) return -1; + pos = 0; + while (1) { + moduleDict = (TagPtr)-1; // have to detect changes to by-ref parameter + length = ParseNextTag(buffer + pos, &moduleDict); + if (length == -1) break; + pos += length; + + if (moduleDict == 0) continue; + + // did we actually create anything? + if (moduleDict != (TagPtr)-1) { + if (moduleDict->type == kTagTypeDict) break; + if (moduleDict->type == kTagTypeArray) break; + + FreeTag(moduleDict); + } + } + + *dict = moduleDict; + +#if PLIST_DEBUG + if (length == -1) + printf("ParseXML gagged (-1) after %s (%d tags); buf+pos: %s\n", + gLastTag,gTagsParsed,buffer+pos); +#endif + + // for tidyness even though kext parsing resets all of malloc + FreeTagCache(); + + // return 0 for no error + return (length != -1) ? 0 : -1; +} + +#define PARSESTASHINGTAG(tagBuf, keyTag, parseFunc) do { \ + TagPtr extantTag = TagFromRef(tagBuf, sizeof(keyTag)-1); \ + if (extantTag) { \ + *tag = extantTag; \ + length = 0; \ + } else { \ + int tagid = ExtractID(tagName, sizeof(keyTag)-1); \ + length = parseFunc(buffer + pos, tag); \ + if (tagid && length != -1) \ + if (-1 == SaveTagRef(*tag, tagid)) \ + return -1; \ + } \ + } while(0) + +static long ParseNextTag(char *buffer, TagPtr *tag) +{ + long length, pos, empty = 0; + char *tagName; + TagPtr refTag; + + length = GetNextTag(buffer, &tagName, 0, &empty); + if (length == -1) return -1; +#if PLIST_DEBUG + gLastTag = tagName; + gTagsParsed++; +#endif + + pos = length; + if (MATCHTAG(tagName, kXMLTagPList)) { + length = 0; // just a header; nothing to parse + // return-via-reference tag should be left alone + } else if (MATCHTAG(tagName, kXMLTagDict)) { + length = ParseTagList(buffer + pos, tag, kTagTypeDict, empty); + } else if (!strcmp(tagName, kXMLTagKey)) { + length = ParseTagKey(buffer + pos, tag); + } else if (MATCHTAG(tagName, kXMLTagReference) && + (refTag = TagFromRef(tagName, sizeof(kXMLTagReference)-1))) { + *tag = refTag; + length = 0; + } else if (MATCHTAG(tagName, kXMLTagString)) { + PARSESTASHINGTAG(tagName, kXMLTagString, ParseTagString); + } else if (MATCHTAG(tagName, kXMLTagInteger)) { + PARSESTASHINGTAG(tagName, kXMLTagInteger, ParseTagInteger); + } else if (!strcmp(tagName, kXMLTagData)) { + length = ParseTagData(buffer + pos, tag); + } else if (!strcmp(tagName, kXMLTagDate)) { + length = ParseTagDate(buffer + pos, tag); + } else if (!strcmp(tagName, kXMLTagFalse)) { + length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse); + } else if (!strcmp(tagName, kXMLTagTrue)) { + length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue); + } else if (MATCHTAG(tagName, kXMLTagArray)) { + length = ParseTagList(buffer + pos, tag, kTagTypeArray, empty); + } else { + // it wasn't parsed so we consumed no additional characters + length = 0; + if (tagName[0] == '/') // was it an end tag (indicated w/*tag = 0) + *tag = 0; + else { +//printf("ignored plist tag: %s (*tag: %x)\n", tagName, *tag); + *tag = (TagPtr)-1; // we're *not* returning a tag + } + } + + if (length == -1) return -1; + + return pos + length; +} + +static long ParseTagList(char *buffer, TagPtr *tag, long type, long empty) +{ + long length, pos; + TagPtr tagList, tmpTag = (TagPtr)-1; + + tagList = 0; + pos = 0; + + if (!empty) { + while (1) { + tmpTag = (TagPtr)-1; + length = ParseNextTag(buffer + pos, &tmpTag); + if (length == -1) break; + pos += length; + + // detect end of list + if (tmpTag == 0) break; + + // if we made a new tag, insert into list + if (tmpTag != (TagPtr)-1) { + tmpTag->tagNext = tagList; + tagList = tmpTag; + } + } + + if (length == -1) { + FreeTag(tagList); + return -1; + } + } + + tmpTag = NewTag(); + if (tmpTag == 0) { + FreeTag(tagList); + return -1; + } + + tmpTag->type = type; + tmpTag->string = 0; + tmpTag->tag = tagList; + tmpTag->tagNext = 0; + + *tag = tmpTag; + + return pos; +} + + +static long ParseTagKey(char *buffer, TagPtr *tag) +{ + long length, length2; + char *string; + TagPtr tmpTag, subTag = (TagPtr)-1; // eliminate possible stale tag + + length = FixDataMatchingTag(buffer, kXMLTagKey); + if (length == -1) return -1; + + length2 = ParseNextTag(buffer + length, &subTag); + if (length2 == -1) return -1; + + // XXXX revisit 4063982 if FreeTag becomes real + if(subTag == (TagPtr)-1) + subTag = NULL; + + tmpTag = NewTag(); + if (tmpTag == 0) { + FreeTag(subTag); + return -1; + } + + string = NewSymbol(buffer); + if (string == 0) { + FreeTag(subTag); + FreeTag(tmpTag); + return -1; + } + + tmpTag->type = kTagTypeKey; + tmpTag->string = string; + tmpTag->tag = subTag; + tmpTag->tagNext = 0; + + *tag = tmpTag; + + return length + length2; +} + + +static long ParseTagString(char *buffer, TagPtr *tag) +{ + long length; + char *string; + TagPtr tmpTag; + + length = FixDataMatchingTag(buffer, kXMLTagString); + if (length == -1) return -1; + + tmpTag = NewTag(); + if (tmpTag == 0) return -1; + + string = NewSymbol(buffer); + if (string == 0) { + FreeTag(tmpTag); + return -1; + } + + tmpTag->type = kTagTypeString; + tmpTag->string = string; + tmpTag->tag = 0; + tmpTag->tagNext = 0; + + *tag = tmpTag; + + return length; +} + + +static long ParseTagInteger(char *buffer, TagPtr *tag) +{ + long length; + char *intString; + TagPtr tmpTag; + + length = FixDataMatchingTag(buffer, kXMLTagInteger); + if (length == -1) return -1; + + tmpTag = NewTag(); + if (tmpTag == 0) return -1; + + intString = NewSymbol(buffer); + if (intString == 0) { + FreeTag(tmpTag); + return -1; + } + + tmpTag->type = kTagTypeInteger; + tmpTag->string = intString; + tmpTag->tag = 0; + tmpTag->tagNext = 0; + + *tag = tmpTag; + + return length; +} + + +static long ParseTagData(char *buffer, TagPtr *tag) +{ + long length; + TagPtr tmpTag; + + length = FixDataMatchingTag(buffer, kXMLTagData); + if (length == -1) return -1; + + tmpTag = NewTag(); + if (tmpTag == 0) return -1; + + tmpTag->type = kTagTypeData; + tmpTag->string = 0; + tmpTag->tag = 0; + tmpTag->tagNext = 0; + + *tag = tmpTag; + + return length; +} + + +static long ParseTagDate(char *buffer, TagPtr *tag) +{ + long length; + TagPtr tmpTag; + + length = FixDataMatchingTag(buffer, kXMLTagDate); + if (length == -1) return -1; + + tmpTag = NewTag(); + if (tmpTag == 0) return -1; + + tmpTag->type = kTagTypeDate; + tmpTag->string = 0; + tmpTag->tag = 0; + tmpTag->tagNext = 0; + + *tag = tmpTag; + + return length; +} + + +static long ParseTagBoolean(char *buffer, TagPtr *tag, long type) +{ + TagPtr tmpTag; + + tmpTag = NewTag(); + if (tmpTag == 0) return -1; + + tmpTag->type = type; + tmpTag->string = 0; + tmpTag->tag = 0; + tmpTag->tagNext = 0; + + *tag = tmpTag; + + return 0; +} + + +static long GetNextTag(char *buffer, char **tag, long *start, long *empty) +{ + long cnt, cnt2; + + if (tag == 0) return -1; + + // Find the start of the tag. + cnt = 0; + while ((buffer[cnt] != '\0') && (buffer[cnt] != '<')) cnt++; + if (buffer[cnt] == '\0') return -1; + + // Find the end of the tag. + cnt2 = cnt + 1; + while ((buffer[cnt2] != '\0') && (buffer[cnt2] != '>')) cnt2++; + if (buffer[cnt2] == '\0') return -1; + if (empty && cnt2 > 1) + *empty = buffer[cnt2-1] == '/'; + + // Fix the tag data. + *tag = buffer + cnt + 1; + buffer[cnt2] = '\0'; + if (start) *start = cnt; + + return cnt2 + 1; +} + + +static long FixDataMatchingTag(char *buffer, char *tag) +{ + long length, start, stop; + char *endTag; + + start = 0; + while (1) { + length = GetNextTag(buffer + start, &endTag, &stop, NULL); + if (length == -1) return -1; + + if ((*endTag == '/') && !strcmp(endTag + 1, tag)) break; + start += length; + } + + buffer[start + stop] = '\0'; + + return start + length; +} + + +#define kTagsPerBlock (0x1000) + +static TagPtr gTagsFree; + +static TagPtr NewTag(void) +{ + long cnt; + TagPtr tag; + + if (gTagsFree == 0) { + tag = (TagPtr)AllocateBootXMemory(kTagsPerBlock * sizeof(Tag)); + if (tag == 0) return 0; + + // Initalize the new tags. + for (cnt = 0; cnt < kTagsPerBlock; cnt++) { + tag[cnt].type = kTagTypeNone; + tag[cnt].string = 0; + tag[cnt].tag = 0; + tag[cnt].tagNext = tag + cnt + 1; + } + tag[kTagsPerBlock - 1].tagNext = 0; + + gTagsFree = tag; + } + + tag = gTagsFree; + gTagsFree = tag->tagNext; + + return tag; +} + + +// currently a no-op +void FreeTag(TagPtr tag) +{ + return; // XXXX revisit callers, particularly ParseTagKey (4063982) + if (tag == 0) return; + + if (tag->string) FreeSymbol(tag->string); + + FreeTag(tag->tag); + FreeTag(tag->tagNext); + + // Clear and free the tag. + tag->type = kTagTypeNone; + tag->string = 0; + tag->tag = 0; + tag->tagNext = gTagsFree; + gTagsFree = tag; +} + + +struct Symbol { + long refCount; + struct Symbol *next; + char string[1]; +}; +typedef struct Symbol Symbol, *SymbolPtr; + +static SymbolPtr FindSymbol(char *string, SymbolPtr *prevSymbol); + +static SymbolPtr gSymbolsHead; + + +static char *NewSymbol(char *string) +{ + SymbolPtr symbol; + + // Look for string in the list of symbols. + symbol = FindSymbol(string, 0); + + // Add the new symbol. + if (symbol == 0) { + symbol = AllocateBootXMemory(sizeof(Symbol) + strlen(string)); + if (symbol == 0) return 0; + + // Set the symbol's data. + symbol->refCount = 0; + strcpy(symbol->string, string); + + // Add the symbol to the list. + symbol->next = gSymbolsHead; + gSymbolsHead = symbol; + } + + // Update the refCount and return the string. + symbol->refCount++; + return symbol->string; +} + + +// currently a no-op +static void FreeSymbol(char *string) +{ +#if 0 + SymbolPtr symbol, prev; + + // Look for string in the list of symbols. + symbol = FindSymbol(string, &prev); + if (symbol == 0) return; + + // Update the refCount. + symbol->refCount--; + + if (symbol->refCount != 0) return; + + // Remove the symbol from the list. + if (prev != 0) prev->next = symbol->next; + else gSymbolsHead = symbol->next; + + // Free the symbol's memory. + free(symbol); +#endif +} + + +static SymbolPtr FindSymbol(char *string, SymbolPtr *prevSymbol) +{ + SymbolPtr symbol, prev; + + symbol = gSymbolsHead; + prev = 0; + + while (symbol != 0) { + if (!strcmp(symbol->string, string)) break; + + prev = symbol; + symbol = symbol->next; + } + + if ((symbol != 0) && (prevSymbol != 0)) *prevSymbol = prev; + + return symbol; +} + +#if PLIST_DEBUG +static void DumpTagDict(TagPtr tag, long depth); +static void DumpTagKey(TagPtr tag, long depth); +static void DumpTagString(TagPtr tag, long depth); +static void DumpTagInteger(TagPtr tag, long depth); +static void DumpTagData(TagPtr tag, long depth); +static void DumpTagDate(TagPtr tag, long depth); +static void DumpTagBoolean(TagPtr tag, long depth); +static void DumpTagArray(TagPtr tag, long depth); +static void DumpSpaces(long depth); + +void DumpTag(TagPtr tag, long depth) +{ + if (tag == 0) return; + + switch (tag->type) { + case kTagTypeDict : + DumpTagDict(tag, depth); + break; + + case kTagTypeKey : + DumpTagKey(tag, depth); + break; + + case kTagTypeString : + DumpTagString(tag, depth); + break; + + case kTagTypeInteger : + DumpTagInteger(tag, depth); + break; + + case kTagTypeData : + DumpTagData(tag, depth); + break; + + case kTagTypeDate : + DumpTagDate(tag, depth); + break; + + case kTagTypeFalse : + case kTagTypeTrue : + DumpTagBoolean(tag, depth); + break; + + case kTagTypeArray : + DumpTagArray(tag, depth); + break; + + default : + break; + } +} + + +static void DumpTagDict(TagPtr tag, long depth) +{ + TagPtr tagList; + + if (tag->tag == 0) { + DumpSpaces(depth); + printf("<%s/>\n", kXMLTagDict); + } else { + DumpSpaces(depth); + printf("<%s>\n", kXMLTagDict); + + tagList = tag->tag; + while (tagList) { + DumpTag(tagList, depth + 1); + tagList = tagList->tagNext; + } + + DumpSpaces(depth); + printf("\n", kXMLTagDict); + } +} + + +static void DumpTagKey(TagPtr tag, long depth) +{ + DumpSpaces(depth); + printf("<%s>%s\n", kXMLTagKey, tag->string, kXMLTagKey); + + DumpTag(tag->tag, depth); +} + + +static void DumpTagString(TagPtr tag, long depth) +{ + DumpSpaces(depth); + printf("<%s>%s\n", kXMLTagString, tag->string, kXMLTagString); +} + + +/* integers used to live as char*s but we need 64 bit ints */ +static void DumpTagInteger(TagPtr tag, long depth) +{ + DumpSpaces(depth); + printf("<%s>%s\n", kXMLTagInteger, tag->string, kXMLTagInteger); +} + + +static void DumpTagData(TagPtr tag, long depth) +{ + DumpSpaces(depth); + printf("<%s>%x\n", kXMLTagData, tag->string, kXMLTagData); +} + + +static void DumpTagDate(TagPtr tag, long depth) +{ + DumpSpaces(depth); + printf("<%s>%x\n", kXMLTagDate, tag->string, kXMLTagDate); +} + + +static void DumpTagBoolean(TagPtr tag, long depth) +{ + DumpSpaces(depth); + printf("<%s>\n", (tag->type == kTagTypeTrue) ? kXMLTagTrue : kXMLTagFalse); +} + + +static void DumpTagArray(TagPtr tag, long depth) +{ + TagPtr tagList; + + if (tag->tag == 0) { + DumpSpaces(depth); + printf("<%s/>\n", kXMLTagArray); + } else { + DumpSpaces(depth); + printf("<%s>\n", kXMLTagArray); + + tagList = tag->tag; + while (tagList) { + DumpTag(tagList, depth + 1); + tagList = tagList->tagNext; + } + + DumpSpaces(depth); + printf("\n", kXMLTagArray); + } +} + + +static void DumpSpaces(long depth) +{ + long cnt; + + for (cnt = 0; cnt < (depth * 4); cnt++) putchar(' '); +} +#endif diff --git a/bootx.tproj/sl.subproj/raid.c b/bootx.tproj/sl.subproj/raid.c new file mode 100644 index 0000000..b57d96b --- /dev/null +++ b/bootx.tproj/sl.subproj/raid.c @@ -0,0 +1,841 @@ + +/* + * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. + * + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * raid.c - Main functions for BootX. + * + * Copyright (c) 1998-2005 Apple Computer, Inc. + * + * DRI: Josh de Cesare (BootX), Soren Spies (RAID support) + */ + + +#include +#include + +typedef unsigned long long UInt64; +#define KERNEL +#include // hooray +//#include "/System/Library/Frameworks/IOKit.framework/Versions/A/PrivateHeaders/storage/RAID/AppleRAIDUserLib.h" + +/* things we could probably get from elsewhere */ +typedef enum RAIDType { + kRAIDTypeUseless = -1, + kRAIDTypeMirror, + kRAIDTypeStripe, + kRAIDTypeConcat, + // kRAIDTypeFive, +} RAIDType; + + +/* stolen from AppleRAIDMember.h */ + +#define kAppleRAIDSignature "AppleRAIDHeader" +#define kAppleRAIDHeaderSize 0x1000 + +#define ARHEADER_OFFSET(s) ((UInt64)(s) / kAppleRAIDHeaderSize * kAppleRAIDHeaderSize - kAppleRAIDHeaderSize ) + +struct AppleRAIDHeaderV2 { + char raidSignature[16]; + char raidUUID[64]; + char memberUUID[64]; + UInt64 size; + char plist[0]; +}; +typedef struct AppleRAIDHeaderV2 AppleRAIDHeaderV2; + + +/* our data structure */ +typedef struct RAIDMember { + // our providers + char path[256]; // sized like gBootDevice + UInt64 size; // becomes data-bearing portion once known + union { // switch on totMembers + struct RAIDMember **members; // dynamic array of pointers + // totMembers big; curMembers elements + CICell ih; // after we Open() path; NULL if useless + }; + + + // --- everything below here used for members; not leaves --- + UInt64 curOffset; // absolute for Seek/RAIDRead() + int curMembers; // updated as we add members and do I/O + + // derived from the header(s - struct and plist) stored in the providers + char setUUID[64]; // id used (w/seqNum) to find other members + RAIDType type; // mirror, stripe, concat + int seqNum; // member generation id + int totMembers; // total members in set + UInt64 chunkSize; // stripe width + UInt64 chunkCount; // number of chunks (unused?) +} RAIDDevice; // *RAIDDevicePtr; + +/* for our paths */ +#define kAppleRAIDOFPathPrefix "AppleRAID/" + +/* -- static variables -- */ +static int gMaxMembers; +static int gTotalMembers; +static struct RAIDMember *gMembers; // an array of structs +static RAIDDevicePtr gRAIDMaster = NULL; + +/* -- internal helper prototypes -- */ +static long FillInLeaf(TagPtr tagElem, RAIDDevicePtr member); +static long AssimilateMember(RAIDDevicePtr member); +static RAIDDevicePtr DetermineParent(TagPtr candidateDict, AppleRAIDHeaderV2*); +static long AdoptChild(RAIDDevicePtr parent, RAIDDevicePtr child, TagPtr cDict); +static long isComplete(RAIDDevicePtr member); +static long NextPartition(char *loaderDev, char *memberDev); // XX share? +// must call these with non-"-1" offsets +static long ReadMirror(RAIDDevicePtr raid, long buf, long nbytes,UInt64 offset); +static long ReadStripe(RAIDDevicePtr raid, long buf, long nbytes,UInt64 offset); +static long ReadConcat(RAIDDevicePtr raid, long buf, long nbytes,UInt64 offset); + +/* -- accessors -- */ +static RAIDType GetRAIDType(TagPtr dict); +static long long GetWholeNumber(TagPtr dict, char *key); + +/* -- cruft XX :) -- */ +static void problemCode(); // need to isolate crasher + +/* -- public helpers -- */ +int isRAIDPath(char *devSpec) +{ + int rval; + + rval = (devSpec && !strncmp(devSpec, kAppleRAIDOFPathPrefix, + sizeof(kAppleRAIDOFPathPrefix)-1)); + return rval; +} + +/* only publicly a RAID device if it has members */ +/* we could have magic in our struct to be really sure :) */ +int isRAIDDevice(void *ih) +{ + int rval; + + if(!ih) return 0; + + RAIDDevicePtr p = (RAIDDevicePtr)ih; + // is the pointer within range + rval = (p >= &gMembers[0] && p < &gMembers[gTotalMembers] && p->curMembers); + + return rval; +} + +// --- open/close/read/!/seek --- + +// RAIDClose() +void RAIDClose(RAIDDevicePtr raid) +{ + int i = raid->totMembers; + RAIDDevicePtr mem; + + if(raid->curMembers) { + while(i-- > 0) { + mem = raid->members[i]; + if(mem) { + RAIDClose(mem); + raid->members[i] = NULL; + if(raid->curMembers) + raid->curMembers--; + } + } + } + else if(raid->ih) + Close(raid->ih); +} + +// RAIDOpen() +RAIDDevicePtr RAIDOpen(char *devSpec) +{ + // steal RAID "devices" + int ridx; + char *p = devSpec, *endp; + RAIDDevicePtr rval = NULL; + + if(!devSpec) return NULL; + + // walk past kAppleRAIDOFPathPrefix + while (*p && *(p++) != '/'); + if(*p) { + ridx = strtol(p, &endp, 10); + if(ridx < gTotalMembers) + rval = &gMembers[ridx]; + } + + return rval; +} + +// RAIDSeek() +long RAIDSeek(RAIDDevicePtr raid, long long position) +{ + if(!raid) return -1; + if(position < 0) return -1; + + raid->curOffset = position; + return position; +} + +// RAIDRead() +long RAIDRead(RAIDDevicePtr raid, long buf, long nbytes, long long offset) +{ + long rval = -1; +static long logs = 0; + + // only RAIDRead() supports offset == -1 -> curOffset + if(offset == -1) + offset = raid->curOffset; + + if(offset > raid->size) { + printf("RAIDRead() error: offset (%x%x) > raid->size (%x%x)\n", + offset, raid->size); + return -1; + } + + if(raid->totMembers) { +if(++logs < 15) +printf("RAIDRead(%x (curMembers: %d), %x, %d, %x%x)\n", +raid, raid->curMembers, buf, nbytes, offset); + switch(raid->type) { + case kRAIDTypeMirror: + rval = ReadMirror(raid, buf, nbytes, offset); + break; + + case kRAIDTypeStripe: + rval = ReadStripe(raid, buf, nbytes, offset); + break; + + case kRAIDTypeConcat: + rval = ReadConcat(raid, buf, nbytes, offset); + break; + + // case kRAIDTypeFive: + default: + printf("unsupported RAID type id: %d\n", raid->type); // XX -> isComplete? + rval = -1; + } + } + else { // leaf member, read from the CI; we open on demand + do { + if(!raid->ih) { + // open underlying device + if(!(raid->ih = Open(raid->path))) break; + } + if(Seek(raid->ih, offset) < 0) break; +//if(logs < 25) +//printf("(RR): calling CI (%x from %x @ %x)\n", nbytes, raid->ih, (int)offset); + rval = Read(raid->ih, buf, nbytes); + } while(0); + } + +//if((raid->curMembers && logs < 15) || rval != nbytes) +//printf("RAIDRead() returning %d (vs. %d)\n", rval, nbytes); + + return rval; +} + +// read-only, man +// ! long WriteToRAID(RAIDDevicePtr ... ) + + +// simple for now (could spare out errors, etc) +static long ReadMirror(RAIDDevicePtr raid, long buf, long nbytes, UInt64 offset) +{ + int ridx = 0; + + // find a working member + while(ridx < raid->totMembers) { + if(raid->members[ridx]) + break; + else + ridx++; + } + + if(ridx == raid->totMembers) + return -1; + + return RAIDRead(raid->members[ridx], buf, nbytes, offset); +} + +static long ReadStripe(RAIDDevicePtr raid, long buf, long nbytes, UInt64 offset) +{ + UInt64 chunkSize = raid->chunkSize; + int nMems = raid->totMembers; + UInt64 subChunkStart = offset % chunkSize; // where in the final chunk? + + UInt64 chunkIdx = offset / chunkSize; // which chunk of all of them? + int midx = chunkIdx % nMems; // on which member? + UInt64 mChunk = chunkIdx / nMems; // which chunk in the member? + UInt64 mChunkOffset = mChunk * chunkSize; // which offset in the member? + + long thisTime, totalRead = 0; + long bytesRead, bytesLeft = nbytes; + + long bufp = buf; + + if(subChunkStart + nbytes > chunkSize) + thisTime = chunkSize - subChunkStart; + else + thisTime = nbytes; // nbytes is within the chunk + + // tempting to do a partial read here ... + + while(bytesLeft /* ALT: bufp < buf + nbytes */) { + bytesRead = RAIDRead(raid->members[midx], bufp, thisTime, mChunkOffset+subChunkStart); + if(bytesRead == -1) goto fail; + totalRead += bytesRead; // record what we read + bytesLeft -= bytesRead; + if(bytesRead != thisTime) break; // detect partial read and return + + // set up for next read + + // effect "chunkIdx++" by walking across the members + midx++; // next member + if(midx % nMems == 0) { // did we wrap? + midx = 0; // back to 0th member + mChunkOffset += chunkSize; // next chunk ("mChunk++") + } + + // adjust other parameters + bufp += bytesRead; // bytesRead == thisTime + if(bytesLeft > chunkSize) // are we in the last chunk yet? + thisTime = chunkSize; + else + thisTime = bytesLeft; + subChunkStart = 0; // reset after first read (& beyond :P) + } + + return totalRead; + +fail: + totalRead = -1; + return totalRead; +} + +// XX okay to compare UInt64 values to -1? +static long ReadConcat(RAIDDevicePtr raid, long buf, long nbytes, UInt64 offset) +{ +//static UInt64 predoffset = -1; + int midx; + UInt64 nextStart = 0, curStart = 0; + long totalRead = 0, bytesRead; + + // assume curMembers!=0 since RAIDRead() should be our only caller + for(midx = 0; midx < raid->curMembers; midx++) { + nextStart = curStart + raid->members[midx]->size; + + // are we in range yet? + if(offset < nextStart) { + long thisTime; + UInt64 curOffset = offset - curStart; + + // make sure we aren't reading out too far + if(offset + nbytes < nextStart) + thisTime = nbytes; + else + thisTime = nextStart - offset; // distance to the end + + bytesRead = RAIDRead(raid->members[midx],buf,thisTime,curOffset); + if(bytesRead == -1) goto fail; + totalRead += bytesRead; // record what was read + if(bytesRead != thisTime) break; // detect partial read and return + + // XX need to lay out a volume to test crossing boundary in one read + if(thisTime != nbytes) { +printf("ReadConcat crossing a boundary in a single read\n"); + offset = nextStart; + nbytes -= thisTime; + buf += thisTime; + continue; // take another spin around the loop + } + break; // exit from the enclosing loop + } + curStart = nextStart; + } + + return totalRead; + +fail: +printf("ReadConcat: %d for %x%x (ended %x%x..%x%x)\n", +totalRead, offset, curStart, nextStart); + totalRead = -1; + return totalRead; +} + + +// --- seek out RAID members and build sets --- + +/* + How we find and build RAID sets (not our first stab :): + if(have Boot.plist) + 1) initialize with the OF paths in Boot.plist (Tiger) + else + *) there is no else until we find a way to divine partition sizes + + while(unread potential members) + 3) read new members and populate structs + 4) assimilate them ("resistance is futile!") + * DetermineParent() looks through existing sets and creates on demand + * give the child to the parent for adoption + * if the parent becomes complete, proactively probe it as a member +*/ + +// process gBootDict looking for path/size pairs where we can sniff for RAID +// allocate gMembers (3x the number of members) +// make some stub members pointing to these paths +long LookForRAID(TagPtr bootDict) +{ + TagPtr partSpec; +int nsuccesses = 0; + + do { + // count and allocate gMembers array + // assume no Apple_RAID could contribute > 2 members + if(bootDict->type == kTagTypeArray) + for(partSpec = bootDict->tag; partSpec; partSpec = partSpec->tagNext) + gMaxMembers += 3; // XX [re]think degraded mirrors trying to stack + else + gMaxMembers = 3; + + gMembers = AllocateBootXMemory(gMaxMembers*sizeof(RAIDDevice)); + if(!gMembers) break; + bzero(gMembers, gMaxMembers*sizeof(RAIDDevice)); + + // walk list of potential members, skipping on error + // FillInLeaf() on each + // AssimilateMember() on each + if(bootDict->type == kTagTypeArray) { + char masterMemberPath[256]; + + if(NextPartition(gBootDevice, masterMemberPath)) break; + + for(partSpec = bootDict->tag; partSpec; partSpec = partSpec->tagNext) { + RAIDDevicePtr newLeaf = &gMembers[gTotalMembers++]; // burn entries + if(FillInLeaf(partSpec, newLeaf)) continue; + + // is this the master (from whose Apple_Boot we loaded? + if(FindDevice(newLeaf->path) == FindDevice(masterMemberPath)) { +printf("raid: found member affiliated with our boot device\n"); + gRAIDMaster = newLeaf; + } + + // assertion: leaves are always complete +printf("raid: assimilating leaf %x\n", newLeaf); + if(AssimilateMember(newLeaf)) continue; +nsuccesses++; + } + } + // even degraded mirror (one member) is in an array + else if(bootDict->type == kTagTypeDict) { + if(FillInLeaf(bootDict, &gMembers[0])) break; + if(AssimilateMember(&gMembers[0])) break; + gRAIDMaster = &gMembers[1]; + } + else + break; + +printf("LookForRAID() made %d happy structs ", nsuccesses); +printf("which resulted in %d total objects\n", gTotalMembers); + + if(isComplete(gRAIDMaster)) { + int masteridx = gRAIDMaster - gMembers; + sprintf(gBootDevice, "%s%d:0,\\\\tbxi",kAppleRAIDOFPathPrefix,masteridx); +printf("raid: set gBootDevice to %s\n", gBootDevice); + } else { + if(!gRAIDMaster) + printf("raid: boot-device didn't lead to a RAID device\n"); + else + printf("raid: master RAID device %x missing members (has %d of %d)\n", + gRAIDMaster, gRAIDMaster->curMembers, gRAIDMaster->totMembers); + break; + } + + return 0; + } while(0); + + return -1; +} + +// FillInLeaf() fills in a member's struct so the partition can later be probed +// (just need the path and size) +static long FillInLeaf(TagPtr partSpec, RAIDDevicePtr newMember) +{ + TagPtr prop; + long long size; + char *path; + long rval = -1; + + do { + prop = GetProperty(partSpec, kIOBootDevicePathKey); + if(!prop || prop->type != kTagTypeString) break; + path = prop->string + sizeof(kIODeviceTreePlane); // +1(':') -1('\0') + if((size = GetWholeNumber(partSpec, kIOBootDeviceSizeKey)) < 0) break; + +//printf("got path and size (%x%x)\n", size); + + // and copy in the values + if(!strcpy(newMember->path, path)) break; + newMember->size = size; + + // gMembers got the big bzero() so all else is fine + + rval = 0; + } while(0); + + return rval; +} + +// need to extract logical bits so we can find a parent +static long AssimilateMember(RAIDDevicePtr candidate) +{ + TagPtr candDict = NULL; + void *bufp = (char*)kLoadAddr; + AppleRAIDHeaderV2 *cHeader = (AppleRAIDHeaderV2*)bufp; + RAIDDevicePtr parent = NULL; + long rval = -1; + + do { + // suck headers from candidate + if(RAIDRead(candidate, (long)bufp, kAppleRAIDHeaderSize, + ARHEADER_OFFSET(candidate->size)) != kAppleRAIDHeaderSize) break; +printf("raid: checking for magic: %s\n", bufp); // should point to magic + + // validate the magic + if(strcmp(kAppleRAIDSignature, bufp)) { + printf("RAID magic not found in member %x\n", candidate); + break; + } +//printf("raid set UUID: %s\n", cHeader->raidUUID); +//printf("memberUUID: %s\n", cHeader->memberUUID); + + // batten down the size to hide the header +printf("raid: member size (%x%x) -> data size (%x%x)\n",candidate->size, +cHeader->size); + candidate->size = cHeader->size; // -msoft-flaot required! + + // and skip to and parse the embedded plist (to get the type, etc) + bufp += sizeof(AppleRAIDHeaderV2); +//printf("bufp: %s\n", bufp); + if((ParseXML(bufp, &candDict) < 0) || !candDict) break; +//printf("parsed RAID member dict (%x):\n", candDict); +//DumpTag(candDict, 0); +//printf("\n"); + + // DetermineParent will create a parent if it didn't already exist + if(!(parent = DetermineParent(candDict, cHeader))) break; +printf("raid: %x being given to %x for adoption\n", candidate, parent); + if(AdoptChild(parent, candidate, candDict)) break; + +printf("raid: checking if set is ready to be probed...\n"); + if(isComplete(parent)) + (void)AssimilateMember(parent); // we might be done ... + + rval = 0; + } while(0); + + return rval; +} + +static long AdoptChild(RAIDDevicePtr parent, RAIDDevicePtr child, TagPtr cDict) +{ + int candIdx, childSeq; + long rval = -1; + + do { + if((childSeq = GetWholeNumber(cDict, kAppleRAIDSequenceNumberKey)) < 0) + break; + + // check for "one"ness early (the child might be otherwise unwanted) + if(child == gRAIDMaster) { +printf("raid: SUCCESSION %x was master; now to parent %x\n", child, parent); + gRAIDMaster = parent; + } + + // do per-type actions (e.g. adjust size, cast out degraded mirrors, etc) + switch(parent->type) { + case kRAIDTypeMirror: + // only want the most up to date n-way twins (n=1..k) + if(childSeq < parent->seqNum) { +printf("child seq # (%d) < parent's (%d) skip\n",childSeq,parent->seqNum); + return 0; + } + if(childSeq > parent->seqNum) { + int midx; + // more recent; take the new seqNum and cast out old members +printf("child seq (%d) > parent's (%d) update\n",childSeq,parent->seqNum); + parent->seqNum = childSeq; + for(midx = 0; midx < parent->totMembers; midx++) + parent->members[midx] = NULL; + parent->curMembers = 0; + } + parent->size = child->size; + + break; + + case kRAIDTypeStripe: +printf("st parent->size(%x%x) += child->size(%x%x)\n",parent->size,child->size); + parent->size += child->size; + /* could validate that sizes/#totMembers match */ + + break; + + // yes, concat and stripe are the same for now + case kRAIDTypeConcat: + parent->size += child->size; + + break; + + case kRAIDTypeUseless: return -1; // yuck + } + + // get the index of this member in the set + if((candIdx = GetWholeNumber(cDict, kAppleRAIDMemberIndexKey)) == -1) break; + + // just in case we find the same member twice? + // invariant: curMembers == PopCount(members) + if(!parent->members[candIdx]) + parent->curMembers++; + else +printf("raid: members[%d] non-NULL: %x\n", candIdx, parent->members[candIdx]); + +printf("raid: assigning %x to parent->members[%d]\n", child, candIdx); + parent->members[candIdx] = child; + + rval = 0; + } while(0); + + return rval; +} + +// aka "MakeNewParent()" if parent doesn't exist +static RAIDDevicePtr DetermineParent(TagPtr cDict, AppleRAIDHeaderV2 *cHeader) +{ + int ridx; + RAIDDevicePtr rval = NULL; + int seqNum = GetWholeNumber(cDict, kAppleRAIDSequenceNumberKey); + int candIdx = GetWholeNumber(cDict, kAppleRAIDMemberIndexKey); + + if(seqNum == -1 || candIdx == -1) return rval; + + // search all non-leaf parents for a potential match + for(ridx = 0; ridx < gTotalMembers; ridx++) { + RAIDDevicePtr potential = &gMembers[ridx]; + if(!potential->totMembers) continue; // not interested in children + if(potential->totMembers <= candIdx) continue; // no slot for child + if(potential->type != kRAIDTypeMirror) // mirrors will consider any child + if(potential->seqNum != seqNum) continue; // wrong generation + + // XX could check for UUID in members-UUID array + + // if the IDs match, hooray + if(!strcmp(cHeader->raidUUID, potential->setUUID)) { +printf("raid: matched a child to a parent in %s\n", cHeader->raidUUID); + rval = potential; + break; + } + } + + + // If we didn't find a parent, make one + if(ridx == gTotalMembers) + // get values, minimally validate, and populate new parent + do { + RAIDDevicePtr parent = &gMembers[gTotalMembers++]; + int totMembers = 0; + RAIDType type; + TagPtr prop; + UInt64 chunkSize = 0; + UInt64 chunkCount = 0; + +printf("raid: making new parent %x\n", parent); + // count up totMembers + prop = GetProperty(cDict, kAppleRAIDMembersKey); + if(!prop || prop->type != kTagTypeArray) break; +//printf("cDict->raidMembers:\n"); +//DumpTag(prop, 0); +//printf("\n"); + + // count elements of the array + prop = prop->tag; + while(prop) { + totMembers++; + prop = prop->tagNext; + } +printf("raid: parent->totMembers: %d\n", totMembers); + if(totMembers <= candIdx) { +printf("raid: candidate claims index %d in a %d-member set; ignoring\n", +candIdx, totMembers); + break; + } + + // grab type, chunk info from child dict (sequence # above) + type = GetRAIDType(cDict); + if(type == kRAIDTypeUseless) break; + if(type == kRAIDTypeStripe) { + chunkSize = GetWholeNumber(cDict, kAppleRAIDChunkSizeKey); + if(chunkSize == -1) break; + chunkCount = GetWholeNumber(cDict, kAppleRAIDChunkCountKey); + if(chunkCount == -1) break; + } + + // and set up the parent structure's values + parent->size = 0; // let AssimilateMember increment the size + + parent->members = AllocateBootXMemory(totMembers*sizeof(RAIDDevicePtr)); + if(!parent->members) break; + bzero(parent->members, totMembers*sizeof(RAIDDevicePtr)); + + // curMembers, curOffset == 0 from initial bzero() + + if(!strcpy(parent->setUUID, cHeader->raidUUID)) break; + parent->type = type; + parent->seqNum = seqNum; + parent->totMembers = totMembers; + if(type == kRAIDTypeStripe) { + parent->chunkSize = chunkSize; + parent->chunkCount = chunkCount; +//printf("stripe: size * count %x%x vs. size %x%x\n", chunkSize * chunkCount, cHeader->size); + } + + rval = parent; + } while(0); + + return rval; +} + +static long NextPartition(char *loaderDev, char *memberDev) +{ + int cnt, cnt2, partNum; + // stolen from main.c + + // Find the first ':'. + cnt = 0; + while ((loaderDev[cnt] != '\0') && (loaderDev[cnt] != ':')) cnt++; + if (loaderDev[cnt] == '\0') return -1; + + // Find the comma after the ':'. + cnt2 = cnt + 1; + while ((loaderDev[cnt2] != '\0') && (loaderDev[cnt] != ',')) cnt2++; + + // Get just the partition number + strncpy(memberDev, loaderDev + cnt + 1, cnt2 - cnt - 1); + partNum = strtol(memberDev, 0, 10); + if (partNum == 0) partNum = strtol(gBootFile, 0, 16); + + // looking for the Apple_RAID following the Apple_Boot + partNum++; + + // Construct the boot-file + strncpy(memberDev, loaderDev, cnt + 1); + sprintf(memberDev + cnt + 1, "%d", partNum); + + return 0; +} + +static long isComplete(RAIDDevicePtr member) +{ + int rval = 0; + + do { + if(!member || !member->curMembers) break; + + switch(member->type) { + case kRAIDTypeMirror: + rval = (member->curMembers > 0); + break; + + case kRAIDTypeStripe: + case kRAIDTypeConcat: + rval = (member->curMembers == member->totMembers); + + default: + break; + } + } while(0); + +printf("raid: isComplete on %x (type %d, #mems %d): %d\n", +member, member->type, member->curMembers, rval); + return rval; +} + + +// --- dictionary accessors --- +static RAIDType GetRAIDType(TagPtr dict) +{ + RAIDType type = kRAIDTypeUseless; + TagPtr prop; + char *typeString; + + do { + prop = GetProperty(dict, kAppleRAIDLevelNameKey); + if(!prop || prop->type != kTagTypeString) break; + typeString = prop->string; + switch(typeString[0]) { + case 'M': type = kRAIDTypeMirror; break; + case 'S': type = kRAIDTypeStripe; break; + case 'C': type = kRAIDTypeConcat; break; + default: +printf("raid: didn't like level: %s\n", typeString); + type = kRAIDTypeUseless; + } + } while(0); + + return type; +} + +// "whole numbers are the counting numbers plus zero" - math team coach +// -1 indicates an error +static long long GetWholeNumber(TagPtr dict, char *key) +{ + long long num = -1; + char *endp; + TagPtr prop; + + do { + prop = GetProperty(dict, key); + if(!prop || prop->type != kTagTypeInteger) break; + num = strtouq(prop->string, &endp, 0); // as long as not > #mems :) + if(*endp != '\0') { + num = -1; + } + } while(0); + + return num; +} + + +// -- cruft -- +static void problemCode() +{ + RAIDDevice rmem, *tmem = &rmem; + AppleRAIDHeaderV2 rheader, *theader = &rheader; + void *fp = &problemCode; + +printf("\n ... calling probleCode() ...\n"); + fp += 1; +printf("populating a size member\n"); + theader->size = 123456789; +//printf("trying to copy tmem->size = theader->size"); + tmem->size = theader->size; +printf("dumping size: %x,%x\n", (int)(tmem->size>>32), (int)tmem); +} diff --git a/dpkg/control b/dpkg/control new file mode 100644 index 0000000..c3d9689 --- /dev/null +++ b/dpkg/control @@ -0,0 +1,5 @@ +Package: bootx +Maintainer: Darwin Developers +Vendor: Apple Computer, Inc. +Build-Depends: build-base +Description: Darwin booter. diff --git a/fcode-to-c.tproj/fcode-to-c.c b/fcode-to-c.tproj/fcode-to-c.c index d15066b..c566c38 100644 --- a/fcode-to-c.tproj/fcode-to-c.c +++ b/fcode-to-c.tproj/fcode-to-c.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ diff --git a/macho-to-xcoff.tproj/macho-to-xcoff.c b/macho-to-xcoff.tproj/macho-to-xcoff.c index 9d0586f..02e9af5 100644 --- a/macho-to-xcoff.tproj/macho-to-xcoff.c +++ b/macho-to-xcoff.tproj/macho-to-xcoff.c @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ -- 2.45.2