From: Apple Date: Tue, 23 Jan 2001 08:15:39 +0000 (+0000) Subject: boot-80.1.tar.gz X-Git-Tag: mac-os-x-100^0 X-Git-Url: https://git.saurik.com/apple/boot.git/commitdiff_plain/14c7c974991c850bfa0348affbd4bee3223205ee boot-80.1.tar.gz --- 14c7c974991c850bfa0348affbd4bee3223205ee diff --git a/APPLE_LICENSE b/APPLE_LICENSE new file mode 100644 index 0000000..84687a4 --- /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 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 b/Makefile new file mode 100644 index 0000000..8dd7149 --- /dev/null +++ b/Makefile @@ -0,0 +1,66 @@ +export USE_APPLE_PB_SUPPORT = all + +# Makefile for kernel booter + +# CFLAGS = -O $(MORECPP) -arch i386 -g -munaligned-text +DEFINES= +CONFIG = hd +LIBDIR = libsa +INC = -I. -I$(LIBDIR) +ifneq "" "$(wildcard /bin/mkdirs)" + MKDIRS = /bin/mkdirs +else + MKDIRS = /bin/mkdir -p +endif +AS = as +LD = ld +PAX = /bin/pax + +OBJROOT = `pwd`/obj +SYMROOT = `pwd`/sym +DSTROOT = `pwd`/dst +SRCROOT = /tmp +ARCHLESS_RC_CFLAGS=`echo $(RC_CFLAGS) | sed 's/-arch [a-z0-9]*//g'` + +VPATH = $(OBJROOT):$(SYMROOT) + +GENERIC_SUBDIRS = gen + +# +# Currently builds for i386 +# + +all tags clean debug install installhdrs: $(SYMROOT) $(OBJROOT) + @if [ -z "$(RC_ARCHS)" ]; then \ + RC_ARCHS="i386"; \ + fi; \ + SUBDIRS="$(GENERIC_SUBDIRS) $$RC_ARCHS"; \ + for i in $$SUBDIRS; \ + do \ + if [ -d $$i ]; then \ + echo ================= make $@ for $$i =================; \ + ( OBJROOT=$(OBJROOT)/$${i}; \ + SYMROOT=$(SYMROOT)/$${i}; \ + DSTROOT=$(DSTROOT); \ + echo "$$OBJROOT $$SYMROOT $$DSTROOT"; \ + cd $$i; ${MAKE} \ + "OBJROOT=$$OBJROOT" \ + "SYMROOT=$$SYMROOT" \ + "DSTROOT=$$DSTROOT" \ + "SRCROOT=$$SRCROOT" \ + "RC_ARCHS=$$RC_ARCHS" \ + "TARGET=$$i" \ + "RC_KANJI=$(RC_KANJI)" \ + "JAPANESE=$(JAPANESE)" \ + "RC_CFLAGS=$(ARCHLESS_RC_CFLAGS)" $@ \ + ) || exit $?; \ + else \ + echo "========= nothing to build for $$i ========="; \ + fi; \ + done + +installsrc: + gnutar cf - . | (cd ${SRCROOT}; gnutar xpf -) + +$(SYMROOT) $(OBJROOT) $(DSTROOT): + @$(MKDIRS) $@ diff --git a/dpkg/control b/dpkg/control new file mode 100644 index 0000000..96192b0 --- /dev/null +++ b/dpkg/control @@ -0,0 +1,4 @@ +Package: boot +Maintainer: Darwin Developers +Description: Kernel booter +Build-Depends: build-base, adv-cmds, libc-hdrs, objc4-hdrs diff --git a/gen/MakeInc.dir b/gen/MakeInc.dir new file mode 100644 index 0000000..474c4ae --- /dev/null +++ b/gen/MakeInc.dir @@ -0,0 +1,43 @@ +# +# Common makefile targets. +# +# Define these variables (if desired) in directory makefiles: +# DIRS_NEEDED +# INSTALLDIR +# SRCROOT +# +ifneq "" "$(wildcard /bin/mkdirs)" + MKDIRS = /bin/mkdirs +else + MKDIRS = /bin/mkdir -p +endif + +installsrc:: $(SRCROOT) + cp $(ALLSRC) $(SRCROOT) + cd $(SRCROOT); chmod a-w $(ALLSRC) + +install:: installhdrs all + +install_i386:: all + +installhdrs:: + +clean:: + /bin/rm -rf $(OBJROOT) *~ + +.SUFFIXES: .s .i .c .o + +.c.o .m.o: + $(CC) $(CFLAGS) $(DEFINES) -c $(INC) $< -o $(OBJROOT)/$*.o \ + -MD -dependency-file $(OBJROOT)/$*.d + md -u $(OBJROOT)/Makedep -f -d $(OBJROOT)/$*.d + +#.s.o: +# cc $(INC) -E $< > $(OBJROOT)/$*.o2 +# $(AS) -o $(OBJROOT)/$@ $(OBJROOT)/$*.o2 + +.s.o: + cc -c $(INC) -arch i386 -o $(OBJROOT)/$@ $< + +$(DIRS_NEEDED) $(INSTALLDIR) $(SRCROOT): + $(MKDIRS) $@ diff --git a/gen/MakePaths.dir b/gen/MakePaths.dir new file mode 100644 index 0000000..4eb6750 --- /dev/null +++ b/gen/MakePaths.dir @@ -0,0 +1,9 @@ +# +# Default paths for subdirectories. +# + +OBJROOT=../../obj/gen/$(DIR) +SYMROOT=../../sym/gen +DSTROOT=../../dst +SRCROOT=/tmp + diff --git a/gen/Makefile b/gen/Makefile new file mode 100644 index 0000000..b9ce995 --- /dev/null +++ b/gen/Makefile @@ -0,0 +1,49 @@ + +# +# Machine-independent code +# + +#CFLAGS = -O $(MORECPP) -arch i386 -g -munaligned-text +DEFINES= +CONFIG = hd +LIBDIR = libsa +INC = -I. -I$(LIBDIR) +ifneq "" "$(wildcard /bin/mkdirs)" + MKDIRS = /bin/mkdirs +else + MKDIRS = /bin/mkdir -p +endif +AS = as +LD = ld +# LIBS= -lc_static + +# +# these paths are only valid in subdirectories of this directory +# +OBJROOT=`pwd`/../../obj/gen +SYMROOT=`pwd`/../../sym +DSTROOT=`pwd`/../../dst +SRCROOT=/tmp + +VPATH = $(OBJROOT):$(SYMROOT) + +SUBDIRS = rcz + +all tags clean debug install installhdrs: + @for i in ${SUBDIRS}; \ + do \ + echo ================= make $@ for $$i =================; \ + ( cd $$i; ${MAKE} \ + "OBJROOT=$(OBJROOT)/$$i" \ + "SYMROOT=$(SYMROOT)" \ + "DSTROOT=$(DSTROOT)" \ + "SRCROOT=$(SRCROOT)" \ + "RC_ARCHS=$(RC_ARCHS)" \ + "RC_KANJI=$(RC_KANJI)" \ + "JAPANESE=$(JAPANESE)" \ + "RC_CFLAGS=$(RC_CFLAGS)" $@ \ + ) || exit $?; \ + done + +installsrc: + tar cf - . | (cd ${SRCROOT}; tar xfBp -) diff --git a/gen/libsa/Makefile b/gen/libsa/Makefile new file mode 100644 index 0000000..20c0a10 --- /dev/null +++ b/gen/libsa/Makefile @@ -0,0 +1,42 @@ + +DIR = libsa +include ../MakePaths.dir + +UTILDIR = ../util +INSTALL_MI_DIR = $(DSTROOT)/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/machdep/machine + +DEBUG = -O +CFLAGS = $(DEBUG) $(MORECPP) -arch i386 -g -Wmost -Wno-precomp -munaligned-text +DEFINES= +CONFIG = hd +INC = -I. -I$(SYMROOT) -I$(UTILDIR) +ifneq "" "$(wildcard /bin/mkdirs)" + MKDIRS = /bin/mkdirs +else + MKDIRS = /bin/mkdir -p +endif +AS = as +LD = ld +# LIBS= -lc_static +LIBS= + +VPATH = $(OBJROOT):$(SYMROOT) + +INSTALLED_MI_HFILES = kernBootStruct.h + +clean:: + @echo "Nothing to clean (yet)" + +all: + @echo "Nothing to build (yet)" + +$(INSTALL_MI_DIR): + $(MKDIRS) $@ + +installhdrs:: $(INSTALL_MI_DIR) + cp $(INSTALLED_MI_HFILES) $(INSTALL_MI_DIR) + +include ../MakeInc.dir + +# dependencies +-include $(OBJROOT)/Makedep diff --git a/gen/libsa/bsearch.c b/gen/libsa/bsearch.c new file mode 100644 index 0000000..48070a8 --- /dev/null +++ b/gen/libsa/bsearch.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* bsearch -- from libc */ +#include "libsa.h" + +#undef bsearch +void * +bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)) { + int l = 0; + int u = nmemb - 1; + int m; + void *mp; + int r; + + while (l <= u) { + m = (l + u) / 2; + mp = (void *)(((char *)base) + (m * size)); + if ((r = (*compar) (key, mp)) == 0) { + return mp; + } else if (r < 0) { + u = m - 1; + } else { + l = m + 1; + } + } + return NULL; +} diff --git a/gen/libsa/ctype.h b/gen/libsa/ctype.h new file mode 100644 index 0000000..9a56c58 --- /dev/null +++ b/gen/libsa/ctype.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* standalone ctype.h */ + +#define isdigit(c) ((c) >= '0' && (c) <= '9') +#define isspace(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || \ + (c) == '\r' || (c) == '\v' || (c) == '\f') +#define isupper(c) ((c) >= 'A' && (c) <= 'Z') +#define islower(c) ((c) >= 'a' && (c) <= 'z') +#define isdigit(c) ((c) >= '0' && (c) <= '9') +#define isalpha(c) (islower(c) || isupper(c)) +#define isalnum(c) (isalpha(c) || isdigit(c)) \ No newline at end of file diff --git a/gen/libsa/error.c b/gen/libsa/error.c new file mode 100644 index 0000000..0dafad8 --- /dev/null +++ b/gen/libsa/error.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* error handling */ + +#import "libsa.h" + +int errno; + +char *strerror(int errnum) +{ + static char error_string[32]; + sprintf(error_string,"Error %d",errnum); + return error_string; +} diff --git a/gen/libsa/fontio.h b/gen/libsa/fontio.h new file mode 100644 index 0000000..08b8e3d --- /dev/null +++ b/gen/libsa/fontio.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* Font I/O functions */ + +extern int strwidth( + register const char *str +); + +extern int strheight( + const char *str +); + +#define CENTER_H 1 +#define CENTER_V 2 + +extern int blit_string( + const char *str, + int xpos, + int ypos, + int color, + int center +); + +extern void blit_clear( + int maxwidth, + int xpos, + int ypos, + int center, + int color +); diff --git a/gen/libsa/getsegbyname.c b/gen/libsa/getsegbyname.c new file mode 100644 index 0000000..125cf7f --- /dev/null +++ b/gen/libsa/getsegbyname.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright 1993 NeXT, Inc. + * All rights reserved. + */ + +#import "libsa.h" + +/* + * This routine returns the segment_command structure for the named segment if + * it exist in the mach executible it is linked into. Otherwise it returns + * zero. It uses the specified mach_header pointer and just looks through the + * load commands. + */ +struct segment_command * +getsegbynamefromheader( +struct mach_header *mhp, +char *segname) +{ + struct segment_command *sgp; + long i; + + sgp = (struct segment_command *) + ((char *)mhp + sizeof(struct mach_header)); + for(i = 0; i < mhp->ncmds; i++){ + if(sgp->cmd == LC_SEGMENT) + if(strncmp(sgp->segname, segname, sizeof(sgp->segname)) == 0) + return(sgp); + sgp = (struct segment_command *)((char *)sgp + sgp->cmdsize); + } + return((struct segment_command *)0); +} diff --git a/gen/libsa/io_inline.h b/gen/libsa/io_inline.h new file mode 100644 index 0000000..3bfa75d --- /dev/null +++ b/gen/libsa/io_inline.h @@ -0,0 +1,116 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright (c) 1992 NeXT Computer, Inc. + * + * Inlines for io space access. + * + * HISTORY + * + * 20 May 1992 ? at NeXT + * Created. + */ + +#import + +#if !defined(DEFINE_INLINE_FUNCTIONS) +static +#endif +inline +unsigned char +inb( + io_addr_t port +) +{ + unsigned char data; + + asm volatile( + "inb %1,%0" + + : "=a" (data) + : "d" (port)); + + return (data); +} + +#if !defined(DEFINE_INLINE_FUNCTIONS) +static +#endif +inline +unsigned short +inw( + io_addr_t port +) +{ + unsigned short data; + + asm volatile( + "inw %1,%0" + + : "=a" (data) + : "d" (port)); + + return (data); +} + +#if !defined(DEFINE_INLINE_FUNCTIONS) +static +#endif +inline +void +outb( + io_addr_t port, + unsigned char data +) +{ + static int xxx; + + asm volatile( + "outb %2,%1; lock; incl %0" + + : "=m" (xxx) + : "d" (port), "a" (data), "0" (xxx) + : "cc"); +} + +#if !defined(DEFINE_INLINE_FUNCTIONS) +static +#endif +inline +void +outw( + io_addr_t port, + unsigned short data +) +{ + static int xxx; + + asm volatile( + "outw %2,%1; lock; incl %0" + + : "=m" (xxx) + : "d" (port), "a" (data), "0" (xxx) + : "cc"); +} + diff --git a/gen/libsa/kernBootStruct.h b/gen/libsa/kernBootStruct.h new file mode 100644 index 0000000..a685321 --- /dev/null +++ b/gen/libsa/kernBootStruct.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * kernBootStruct.h + * What the booter leaves behind for the kernel. + */ + +#import + +#import ARCH_INCLUDE(, kernBootStruct.h) + diff --git a/gen/libsa/keys.h b/gen/libsa/keys.h new file mode 100644 index 0000000..1275551 --- /dev/null +++ b/gen/libsa/keys.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* key codes for some keys */ + +#define K_UP 0x4800 +#define K_DOWN 0x5000 \ No newline at end of file diff --git a/gen/libsa/libsa.h b/gen/libsa/libsa.h new file mode 100644 index 0000000..1346fc4 --- /dev/null +++ b/gen/libsa/libsa.h @@ -0,0 +1,115 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* Exported API for standalone library */ +#import +#import +#import +#import + +#ifndef bcopy +extern char *bcopy(char *src, char *dst, int n); +#endif +extern void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); +#ifndef bzero +extern int bzero(char *b, int length); +#endif +extern void *memset(void *s, int c, size_t n); + +/* + * These are defined internally by GCC + * + * extern void *memcpy(void *dst, const void *src, size_t len); + * extern size_t strlen(const char *s); + */ + +extern int errno; +extern struct segment_command * + getsegbynamefromheader(struct mach_header *mhp, char *segname); +extern int ptol(char *str); + +/* setjmp/longjmp: + * #include + * + * extern int setjmp(jmp_buf env); + * extern void longjmp( jmp_buf env, int val); + */ + +extern int slvprintf(char *buffer, int len, const char *fmt, va_list arg); +extern int sprintf(char *s, const char *format, ...); + +extern char *strcat(char *s1, const char *s2); +extern int strcmp(const char *s1, const char *s2); +extern char *strcpy(char *s1, const char *s2); +char *strerror(int errnum); +extern int strncmp(const char *s1, const char *s2, size_t n); +extern char *strncpy(char *s1, const char *s2, size_t n); +extern long strtol( + const char *nptr, + char **endptr, + register int base +); +extern unsigned long strtoul( + const char *nptr, + char **endptr, + register int base +); +extern int atoi(const char *str); + +/* Mach */ +extern port_t task_self_; +extern kern_return_t vm_allocate( + vm_task_t target_task, + vm_address_t *address, + vm_size_t size, + boolean_t anywhere +); +extern kern_return_t vm_deallocate( + vm_task_t target_task, + vm_address_t address, + vm_size_t size +); +extern kern_return_t host_info( + host_t host, + int flavor, + host_info_t host_info, + unsigned int *host_info_count +); +extern vm_size_t vm_page_size; +extern host_t host_self(void); +extern int getpagesize(void); +extern char *mach_error_string(int errnum); + +/* Malloc */ +extern void malloc_init(char *start, int size, int nodes); +extern void *malloc(size_t size); +extern void free(void *start); +extern void *realloc(void *ptr, size_t size); + +extern void prf( + const char *fmt, + va_list ap, + void (*putfn_p)(), + void *putfn_arg +); +extern int strncasecmp(const char *s1, const char *s2, size_t n); diff --git a/gen/libsa/mach.c b/gen/libsa/mach.c new file mode 100644 index 0000000..53ef503 --- /dev/null +++ b/gen/libsa/mach.c @@ -0,0 +1,100 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* mach simulation */ + +#import "libsa.h" + +port_t task_self_; + +char *mach_error_string(int errnum) +{ + extern char *strerror(int errnum); + + return strerror(errnum); +} + +kern_return_t vm_allocate( + vm_task_t target_task, + vm_address_t *address, + vm_size_t size, + boolean_t anywhere +) +{ + *address = (vm_address_t)malloc(size); + if (*address == 0) + return KERN_FAILURE; + else { + bzero(*address, size); + return KERN_SUCCESS; + } +} + +kern_return_t vm_deallocate( + vm_task_t target_task, + vm_address_t address, + vm_size_t size +) +{ + free((void *)address); + return KERN_SUCCESS; +} + +vm_size_t vm_page_size = 8192; + +kern_return_t host_info( + host_t host, + int flavor, + host_info_t host_info, + unsigned int *host_info_count +) +{ + host_basic_info_t hi = (host_basic_info_t) host_info; + + switch(flavor) { + case HOST_BASIC_INFO: + hi->max_cpus = 1; + hi->avail_cpus = 1; +// hi->memory_size = +// (kernBootStruct->convmem + kernBootStruct->extmem) * 1024; + hi->memory_size = 0; + hi->cpu_type = CPU_TYPE_I386; + hi->cpu_subtype = CPU_SUBTYPE_486; + break; + case HOST_PROCESSOR_SLOTS: + break; + case HOST_SCHED_INFO: + break; + } + return KERN_SUCCESS; +} + +host_t host_self(void) +{ + return 0; +} + +int getpagesize(void) +{ + return vm_page_size; +} diff --git a/gen/libsa/malloc.c.00 b/gen/libsa/malloc.c.00 new file mode 100644 index 0000000..72e5ec3 --- /dev/null +++ b/gen/libsa/malloc.c.00 @@ -0,0 +1,37 @@ +/* + * Copyright 1993 NeXT, Inc. + * All rights reserved. + * + * Malloc interface to zalloc. + */ + +#import "libsa.h" + +int +malloc_init( + char *start, + int size, + int nodes +) +{ + return zinit(start,size,nodes); +} + +void *malloc(size_t size) +{ + return zalloc(size); +} + +/* This is the simplest way possible. Should fix this. */ +void *realloc(void *start, size_t newsize) +{ + void *newstart = zalloc(newsize); + bcopy(start, newstart, newsize); + zfree(start); + return newstart; +} + +void free(void *start) +{ + (void) zfree(start); +} diff --git a/gen/libsa/memcpy.c b/gen/libsa/memcpy.c new file mode 100644 index 0000000..6bb9347 --- /dev/null +++ b/gen/libsa/memcpy.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * more string operations + * + */ + +#import "libsa.h" + +#if defined(NX_CURRENT_COMPILER_RELEASE) && (NX_CURRENT_COMPILER_RELEASE < 320) +#define SIREG "e" +#else +#define SIREG "S" +#endif + +#if i386 && !defined(DONT_USE_ASM) +/* Simple forward character copy */ +void *memcpy(void *dst, const void *src, size_t len) +{ + asm("rep; movsb" + : /* no outputs */ + : "&c" (len), "D" (dst), SIREG (src) + : "ecx", "esi", "edi"); + return (void *)src; +} +#else +void *memcpy( + void *dst, + const void *src, + size_t len +) +{ + register char *src_c, *dst_c; + + src_c = (char *)src; + dst_c = (char *)dst; + + while (len-- > 0) + *dst_c++ = *src_c++; + return src; +} +#endif + +/* + * copy n bytes from src to dst. Both src and dst are virtual addresses. + */ +char *bcopy(char *src, char *dst, int n) +{ + memcpy(dst, src, n); + return 0; +} + + diff --git a/gen/libsa/memory.h b/gen/libsa/memory.h new file mode 100644 index 0000000..d753fc8 --- /dev/null +++ b/gen/libsa/memory.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* memory addresses used by booter and friends */ + +/* these are all "virtual" addresses... + * which are physical addresses plus MEMBASE. + */ + +#define MEMBASE 0x0 +#define BASE_SEG 0x0 + +/* these are virtual addresses */ + +#define BIOS_ADDR 0x00C00 // BIOS buffer +#define BIOS_LEN 0x02400 // 9k +#define BOOTER_LOAD_ADDR 0x03000 // loaded here for compat. +#define BOOTER_ADDR 0x03000 // start of booter code +#define BOOTER_LEN 0x08000 // max of 32k +#define STACK_ADDR 0x0FFF0 +#define BOOTSTRUCT_ADDR 0x11000 +#define BOOTSTRUCT_LEN 0x0F000 // it's slightly smaller +#define EISA_CONFIG_ADDR 0x20000 +#define EISA_CONFIG_LEN 0x10000 +#define RLD_ADDR 0x30000 +#define RLD_LEN 0x24000 // 140k +#define ZALLOC_ADDR 0x54000 +#define ZALLOC_LEN 0x12000 // 72k +#define MODULE_ADDR 0x66000 +#define RLD_MEM_ADDR 0x680000 +#define RLD_MEM_LEN 0x100000 // 1Mb +#define KSYM_ADDR 0x780000 +#define KSYM_LEN 0x080000 // 512k + +/* these are physical values */ + +//#define CONVENTIONAL_LEN 0xA0000 // 640k +#define EXTENDED_ADDR 0x100000 // 1024k +#define KERNEL_BOOT_ADDR 0x100000 /* load at 1Mb */ + +#define KERNEL_SYMBOL_OFFSET 0x100000 /* load at top - 1Mb */ + +#define SAIO_TABLE_POINTER (BOOTER_ADDR + SAIO_TABLE_PTR_OFFSET) +#define SAIO_TABLE_PTR_OFFSET 0x30 + +#define ptov(paddr) ((paddr) - MEMBASE) +#define vtop(vaddr) ((vaddr) + MEMBASE) + +#define MIN_EXT_MEM_KB (7 * 1024) /* 8 Mb minimum total */ diff --git a/gen/libsa/memset.c b/gen/libsa/memset.c new file mode 100644 index 0000000..2abd6cf --- /dev/null +++ b/gen/libsa/memset.c @@ -0,0 +1,151 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* Copyright (c) 1991 NeXT Computer, Inc. All rights reserved. + * + * File: libc/i386/ansi/memset.c + * Author: Bruce Martin, NeXT Computer, Inc. + * + * This file contains machine dependent code for block compares + * on NeXT i386-based products. Currently tuned for the i486. + * + * This code is loosely based on some work done by Mike DeMoney + * for the m88k. + * + * HISTORY + * 14-Dec-93 Curtis Galloway + * Modified for the booter; simplified simple_char_set. + * + * 14-Aug-92 Bruce Martin (Bruce_Martin@NeXT.COM) + * Created. + */ + +#define MIN_TO_ALIGN 32 + +/* + * Convert a void * into a unsigned int so arithmetic can be done + * (Technically, the gnu C compiler is tolerant of arithmetic + * on void *, but ansi isn't; so we do this.) + */ +#define UNS(voidp) ((unsigned int)(voidp)) + +/* + * Number of bytes addr is past an object of 'align' size. + */ +#define BYTES_PAST_ALIGNMENT(voidp, align) \ + (UNS(voidp) & (align - 1)) + +/* + * Bytes moved by an unrolled loop + */ +#define LOOP_STRIDE(type, unroll) ((unroll) * sizeof(type)) + + +/* + * Len modulo LOOP_STRIDE + */ +#define MODULO_LOOP_UNROLL(len, type, unroll) \ + ((len) & (LOOP_STRIDE(type, unroll) - 1) & ~(sizeof(type) - 1)) + + +/* + * Convert a void * + offset into char, short, int, or long long reference + * based at that address + */ +#define CHAR(voidp, offset) (*(char *)(UNS(voidp) + (offset))) +#define SHORT(voidp, offset) (*(short *)(UNS(voidp) + (offset))) +#define INT(voidp, offset) (*(int *)(UNS(voidp) + (offset))) + + + +static inline void +simple_char_set(char *dst, int val, int len) +{ + asm("rep; stosb" + : /* no outputs */ + : "&c" (len), "D" (dst), "a" (val) + : "ecx", "edi", "eax"); +} + + + +void *memset(void *, int, unsigned long); + +int bzero(void *dst, unsigned long ulen) +{ + (void) memset(dst, 0, ulen); + return 0; +} + + +void *memset(void *dst, int val, unsigned long ulen) +{ + int len = ulen; + void *orig_dst = dst; + int need_to_set; + int alignment; + + val |= (val << 8); + val |= (val << 16); + + /* Always do a forward copy */ + + if (len < MIN_TO_ALIGN) { + simple_char_set(dst, val, len); + return orig_dst; + } + + if (need_to_set = BYTES_PAST_ALIGNMENT(dst, 2 * sizeof(int))) { + need_to_set = (2 * sizeof(int)) - need_to_set; + simple_char_set(dst, val, need_to_set); + len -= need_to_set; + UNS(dst) += need_to_set; + } + + alignment = MODULO_LOOP_UNROLL(len, int, 8); + UNS(dst) += alignment - LOOP_STRIDE(int, 8); + switch (alignment) { + do { + INT(dst, 0) = val; + case 28: INT(dst, 4) = val; + case 24: INT(dst, 8) = val; + case 20: INT(dst, 12) = val; + case 16: INT(dst, 16) = val; + case 12: INT(dst, 20) = val; + case 8: INT(dst, 24) = val; + case 4: INT(dst, 28) = val; + case 0: + UNS(dst) += LOOP_STRIDE(int, 8); + len -= LOOP_STRIDE(int, 8); + } while (len >= 0); + len &= sizeof(int) - 1; + } + + switch (len) { + case 3: CHAR(dst, 2) = val; + case 2: CHAR(dst, 1) = val; + case 1: CHAR(dst, 0) = val; + } + + return orig_dst; +} diff --git a/gen/libsa/prf.c b/gen/libsa/prf.c new file mode 100644 index 0000000..a9a74e5 --- /dev/null +++ b/gen/libsa/prf.c @@ -0,0 +1,161 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Mach Operating System + * Copyright (c) 1990 Carnegie-Mellon University + * Copyright (c) 1989 Carnegie-Mellon University + * Copyright (c) 1988 Carnegie-Mellon University + * Copyright (c) 1987 Carnegie-Mellon University + * All rights reserved. The CMU software License Agreement specifies + * the terms and conditions for use and redistribution. + */ +/* + * Copyright (c) 1982, 1986 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + * + * @(#)prf.c 7.1 (Berkeley) 6/5/86 + */ + +#include + +#define SPACE 1 +#define ZERO 2 + +/* + * Scaled down version of C Library printf. + * Used to print diagnostic information directly on console tty. + * Since it is not interrupt driven, all system activities are + * suspended. + * + */ + +/* + * Printn prints a number n in base b. + * We don't use recursion to avoid deep kernel stacks. + */ +static void +printn(n, b, flag, minwidth, putfn_p, putfn_arg) + u_long n; + int b, flag, minwidth; + void (*putfn_p)(); + void *putfn_arg; +{ + char prbuf[11]; + register char *cp; + int width = 0, neg = 0; + + if (b == 10 && (int)n < 0) { + neg = 1; + n = (unsigned)(-(int)n); + } + cp = prbuf; + do { + *cp++ = "0123456789abcdef"[n%b]; + n /= b; + width++; + } while (n); + + if (neg) { + (*putfn_p)('-', putfn_arg); + width++; + } + while (width++ < minwidth) + (*putfn_p)( (flag & ZERO) ? '0' : ' ', putfn_arg); + + do + (*putfn_p)(*--cp, putfn_arg); + while (cp > prbuf); +} + +void prf( + char *fmt, + unsigned int *adx, + void (*putfn_p)(), + void *putfn_arg +) +{ + int b, c; + char *s; + int flag = 0, minwidth = 0, width = 0; + +loop: + while ((c = *fmt++) != '%') { + if(c == '\0') + return; + (*putfn_p)(c, putfn_arg); + } +again: + c = *fmt++; + switch (c) { + case 'l': + goto again; + case ' ': + flag |= SPACE; + goto again; + case '0': + if (minwidth == 0) { + /* this is a flag */ + flag |= ZERO; + goto again; + } /* fall through */ + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + minwidth *= 10; + minwidth += c - '0'; + goto again; + case 'x': case 'X': + b = 16; + goto number; + case 'd': + b = 10; + goto number; + case 'o': case 'O': + b = 8; +number: + printn((u_long)*adx, b, flag, minwidth, putfn_p, putfn_arg); + break; + case 's': + s = (char *)*adx; + while (c = *s++) { + (*putfn_p)(c, putfn_arg); + width++; + } + while (width++ < minwidth) + (*putfn_p)(' ', putfn_arg); + break; + case 'c': + (*putfn_p)((char)*adx, putfn_arg); + break; + } + adx++; + goto loop; +} diff --git a/gen/libsa/setjmp.s b/gen/libsa/setjmp.s new file mode 100644 index 0000000..90c1ae1 --- /dev/null +++ b/gen/libsa/setjmp.s @@ -0,0 +1,57 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +#include + +#define O_EDI 0 +#define O_ESI 4 +#define O_EBX 8 +#define O_EBP 12 +#define O_ESP 16 +#define O_EIP 20 + +LEAF(_setjmp, 0) +X_LEAF(_set_label, _setjmp) + movl 4(%esp), %edx // address of save area + movl %edi, O_EDI(%edx) + movl %esi, O_ESI(%edx) + movl %ebx, O_EBX(%edx) + movl %ebp, O_EBP(%edx) + movl %esp, O_ESP(%edx) + movl (%esp), %ecx // %eip (return address) + movl %ecx, O_EIP(%edx) + subl %eax, %eax // retval <- 0 + ret + +LEAF(_longjmp, 0) +X_LEAF(_jump_label, _longjmp) + movl 4(%esp), %edx // address of save area + movl O_EDI(%edx), %edi + movl O_ESI(%edx), %esi + movl O_EBX(%edx), %ebx + movl O_EBP(%edx), %ebp + movl O_ESP(%edx), %esp + movl O_EIP(%edx), %eax // %eip (return address) + movl %eax, 0(%esp) + popl %eax // ret addr != 0 + jmp *%eax // indirect diff --git a/gen/libsa/sprintf.c b/gen/libsa/sprintf.c new file mode 100644 index 0000000..6850ace --- /dev/null +++ b/gen/libsa/sprintf.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright 1993 NeXT, Inc. + * All rights reserved. + */ + +#import "libsa.h" + +struct putc_info { + char *str; + char *last_str; +}; + +static void +sputc( + int c, + struct putc_info *pi +) +{ + if (pi->last_str) + if (pi->str == pi->last_str) { + *(pi->str) = '\0'; + return; + } + *(pi->str)++ = c; +} + +/*VARARGS1*/ +int sprintf(char *str, const char *fmt, ...) +{ + va_list ap; + struct putc_info pi; + + va_start(ap, fmt); + pi.str = str; + pi.last_str = 0; + prf(fmt, ap, sputc, &pi); + *pi.str = '\0'; + va_end(ap); + return 0; +} + +/*VARARGS1*/ +int slvprintf(char *str, int len, const char *fmt, va_list ap ) +{ + struct putc_info pi; + pi.str = str; + pi.last_str = str + len - 1; + prf(fmt, ap, sputc, &pi); + *pi.str = '\0'; + return (pi.str - str); +} \ No newline at end of file diff --git a/gen/libsa/string1.c b/gen/libsa/string1.c new file mode 100644 index 0000000..6291112 --- /dev/null +++ b/gen/libsa/string1.c @@ -0,0 +1,134 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* string operations */ +#import "libsa.h" + +/*#if DONT_USE_GCC_BUILT_IN_STRLEN*/ + +#define tolower(c) ((int)((c) & ~0x20)) +#define toupper(c) ((int)((c) | 0x20)) + +int strlen(const char *s) +{ + int n; + + n = 0; + while (*s++) n++; + return(n); +} + +/*#endif*/ + +int +strcmp(const char *s1, const char *s2) +{ + while (*s1 && (*s1 == *s2)) { + s1++; + s2++; + } + return (*s1 - *s2); +} + +int strncmp(const char *s1, const char *s2, size_t len) +{ + register int n = len; + while (--n >= 0 && *s1 == *s2++) + if (*s1++ == '\0') + return(0); + return(n<0 ? 0 : *s1 - *--s2); +} + +char * +strcpy(char *s1, const char *s2) +{ + register char *ret = s1; + while (*s1++ = *s2++) + continue; + return ret; +} + +char * +strncpy(char *s1, const char *s2, size_t n) +{ + register char *ret = s1; + while (n && (*s1++ = *s2++)) + n--; + if (!n) *s1=0; + 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; + while (*s1) + s1++; + while (n-- && *s2) + *s1++ = *s2++; + *s1 = '\0'; + return ret; +} + +char *strcat(char *s1, const char *s2) +{ + return(strncat(s1, s2, strlen(s2))); +} + +#if STRNCASECMP +int strncasecmp(const char *s1, const char *s2, size_t len) +{ + register int n = len; + while (--n >= 0 && tolower(*s1) == tolower(*s2++)) + if (*s1++ == '\0') + return(0); + return(n<0 ? 0 : tolower(*s1) - tolower(*--s2)); +} +#endif + diff --git a/gen/libsa/string2.c b/gen/libsa/string2.c new file mode 100644 index 0000000..ba525c7 --- /dev/null +++ b/gen/libsa/string2.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * more string operations + * + */ + +#import "libsa.h" + + +#if i386 && !defined(DONT_USE_ASM) +void *memset(void *dst, int val, size_t len) +{ + asm("rep; stosb" + : /* no outputs */ + : "&c" (len), "D" (dst), "a" (val) + : "ecx", "esi", "eax"); + return dst; +} +/* Simple forward character copy */ +void *memcpy(void *dst, const void *src, size_t len) +{ + asm("rep; movsb" + : /* no outputs */ + : "&c" (len), "D" (dst), "e" (src) + : "ecx", "esi", "edi"); + return src; +} +#else +void *memset(void *p, int val, size_t len) +{ + register char *ptr = (char *)p; + while (len-- > 0) *ptr++ = val; + return p; +} + +void *memcpy( + void *dst, + const void *src, + size_t len +) +{ + register char *src_c, *dst_c; + + src_c = (char *)src; + dst_c = (char *)dst; + + while (len-- > 0) + *dst_c++ = *src_c++; + return src; +} +#endif + diff --git a/gen/libsa/strtol.c b/gen/libsa/strtol.c new file mode 100644 index 0000000..2cf2b23 --- /dev/null +++ b/gen/libsa/strtol.c @@ -0,0 +1,257 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* Modified by Curtis Galloway at NeXT June 1993, + * for use in the standalone library. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)strtol.c 5.4 (Berkeley) 2/23/91"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +//#include +#import "libsa.h" + +#import "ctype.h" + + +/* Fudge here -- to save space, make strtol and strtoul do the same + * conversion. If you really need that extra range on strtoul, too bad. + */ + +#define SIGNED 1 +#define UNSIGNED 0 + + +/* + * Convert a string to a long integer. + * + * Ignores `locale' stuff. Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +static long +actual_strtol( + const char *nptr, + char **endptr, + register int base, + int is_signed +) +{ + register const char *s = nptr; + register unsigned long acc; + register int c; + register unsigned long cutoff; + register int neg = 0, any, cutlim; + + /* + * Skip white space and pick up leading +/- sign if any. + * If base is 0, allow 0x for hex and 0 for octal, else + * assume decimal; if base is already 16, allow 0x. + */ + do { + c = *s++; + } while (isspace(c)); + if (is_signed && c == '-') { + neg = 1; + c = *s++; + } else 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; + + /* + * Compute the cutoff value between legal numbers and illegal + * numbers. That is the largest legal value, divided by the + * base. An input number that is greater than this value, if + * followed by a legal input character, is too big. One that + * is equal to this value may be valid or not; the limit + * between valid and invalid numbers is then based on the last + * digit. For instance, if the range for longs is + * [-2147483648..2147483647] and the input base is 10, + * cutoff will be set to 214748364 and cutlim to either + * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated + * a value > 214748364, or equal but the next digit is > 7 (or 8), + * the number is too big, and we will return a range error. + * + * Set any if any `digits' consumed; make it negative to indicate + * overflow. + */ + cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX; + cutlim = cutoff % (unsigned long)base; + cutoff /= (unsigned long)base; + 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 *= base; + acc += c; + } + } + if (any < 0) { + acc = neg ? LONG_MIN : LONG_MAX; + errno = ERANGE; + } else if (neg) + acc = -acc; + if (endptr != 0) + *endptr = any ? s - 1 : (char *)nptr; + return (acc); +} + +long +strtol( + const char *nptr, + char **endptr, + register int base +) +{ + return actual_strtol(nptr, endptr, base, SIGNED); +} + +unsigned long +strtoul( + const char *nptr, + char **endptr, + register int base +) +{ + return actual_strtol(nptr, endptr, base, UNSIGNED); +} + +#if notdef +/* + * Convert a string to an unsigned long integer. + * + * Ignores `locale' stuff. Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +unsigned long +strtoul(nptr, endptr, base) + const char *nptr; + char **endptr; + register int base; +{ + register const char *s = nptr; + register unsigned long acc; + register int c; + register unsigned long cutoff; + register int neg = 0, any, cutlim; + + /* + * See strtol for comments as to the logic used. + */ + do { + c = *s++; + } while (isspace(c)); + if (c == '-') { + neg = 1; + c = *s++; + } else 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; + cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; + cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; + 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 *= base; + acc += c; + } + } + if (any < 0) { + acc = ULONG_MAX; + errno = ERANGE; + } else if (neg) + acc = -acc; + if (endptr != 0) + *endptr = any ? s - 1 : (char *)nptr; + return (acc); +} + +#endif notdef diff --git a/gen/libsa/zalloc.c b/gen/libsa/zalloc.c new file mode 100644 index 0000000..d0dce72 --- /dev/null +++ b/gen/libsa/zalloc.c @@ -0,0 +1,246 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright 1993 NeXT Computer, Inc. + * All rights reserved. + * + * Sam's simple memory allocator. + * + */ + +#import "libsa.h" +#import "memory.h" +#import "zalloc.h" + +#define ZDEBUG 0 + +#if ZDEBUG +int zout; +#endif + +typedef struct { + char *start; + int size; +} zmem; + +static zmem *zalloced; +static zmem *zavailable; +static short availableNodes, allocedNodes, totalNodes; +static char *zalloc_base; + +static void zallocate(char *start,int size); +static void zinsert(zmem *zp, int ndx); +static void zdelete(zmem *zp, int ndx); +static void zcoalesce(void); + + +// define the block of memory that the allocator will use +void malloc_init(char *start, int size, int nodes) +{ + zalloc_base = start; + totalNodes = nodes; + zalloced = (zmem *)zalloc_base; + start += sizeof(zmem) * nodes; + zavailable = (zmem *)start; + start += sizeof(zmem) * nodes; + zavailable[0].start = start; + zavailable[0].size = size; + availableNodes = 1; + allocedNodes = 0; +} + +void * malloc(size_t size) +{ + int i; + char *ret = 0; +#if 0 + extern char _DATA__end; +#endif + if (!zalloc_base) + { + // this used to follow the bss but some bios' corrupted it... + malloc_init((char *)ZALLOC_ADDR, ZALLOC_LEN, ZALLOC_NODES); + } + + size = ((size + 0xf) & ~0xf); + + for (i=0; i size) + { + zallocate(ret = zavailable[i].start, size); + zavailable[i].start += size; + zavailable[i].size -= size; + goto done; + } + } + +done: +#if 0 +/* if (ret + size >= (char*)_sp()) _stop("stack clobbered"); */ + if (ret + size >= (char *)(ZALLOC_ADDR + ZALLOC_LEN)) + _stop("Out of memory"); +#endif + if (ret != 0) + bzero(ret, size); + return (void *)ret; +} + +void +free(void *pointer) +{ + int i, tsize, found = 0; + char *start = pointer; + + if (!start) return; + + for (i=0; i0 && (zavailable[i-1].start + zavailable[i-1].size == + start)) + { + zavailable[i-1].size += tsize; + zcoalesce(); + return; + } + + if ((start+tsize) < zavailable[i].start) + { + zinsert(zavailable, i); availableNodes++; + zavailable[i].start = start; + zavailable[i].size = tsize; + return; + } + } + + zavailable[i].start = start; + zavailable[i].size = tsize; + availableNodes++; + zcoalesce(); + return; +} + + +static void +zallocate(char *start,int size) +{ +#if ZDEBUG + zout += size; + printf(" alloc %d, total 0x%x\n",size,zout); +#endif + zalloced[allocedNodes].start = start; + zalloced[allocedNodes].size = size; + allocedNodes++; +} + +static void +zinsert(zmem *zp, int ndx) +{ + int i; + zmem *z1, *z2; + + i=totalNodes-2; + z1 = zp + i; + z2 = z1+1; + + for (; i>= ndx; i--, z1--, z2--) + { + z2->start = z1->start; + z2->size = z1->size; + } +} + +static void +zdelete(zmem *zp, int ndx) +{ + int i; + zmem *z1, *z2; + + z1 = zp + ndx; + z2 = z1+1; + + for (i=ndx; istart = z2->start; + z1->size = z2->size; + } +} + +static void +zcoalesce(void) +{ + int i; + for (i=0; initems = nitems; + cp->item_size = item_size; + return cp; +} + +/* + * Either find an item in the cache, or find where it should go. + * Returns 1 if found, 0 if not found. + * This function assumes that if you find an empty slot, you will use it; + * therefore, empty slots returned are marked valid. + */ +int cacheFind( + cache_t *cp, + int key1, + int key2, + char **ip +) +{ + item_t *iip, *min_p; + int i,j; + + for(i=j=0, iip = min_p = (item_t *)cp->storage; i < cp->nitems; i++) { + if (iip->referenced && (iip->key1 == key1) && (iip->key2 == key2)) { + *ip = iip->storage; + if (iip->referenced < 65535) + iip->referenced++; + return 1; + } + if (iip->referenced < min_p->referenced) { + min_p = iip; + j = i; + } + iip = (item_t *)((char *)iip + cp->item_size); + } + *ip = min_p->storage; + min_p->referenced = 1; + min_p->key1 = key1; + min_p->key2 = key2; + return 0; +} + +/* + * Flush the cache. + */ +void cacheFlush( + cache_t *cp +) +{ + int i; + item_t *ip; + + if (cp == 0) + return; + for(i=0, ip = (item_t *)cp->storage; i < cp->nitems; i++) { + ip->referenced = 0; + ip = (item_t *)((char *)ip + cp->item_size); + } +} diff --git a/gen/libsaio/cache.h b/gen/libsaio/cache.h new file mode 100644 index 0000000..193974f --- /dev/null +++ b/gen/libsaio/cache.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +typedef struct cache_item { + unsigned int referenced; + int key1, key2; + char storage[0]; +} item_t; + +typedef struct cache { + int nitems; + int item_size; + char storage[0]; +} cache_t; + +extern cache_t *cacheInit( + int nitems, + int item_size +); + +extern int cacheFind( + cache_t *cp, + int key1, + int key2, + char **ip +); + +extern void cacheFlush( + cache_t *cp +); diff --git a/gen/libsaio/disk.c b/gen/libsaio/disk.c new file mode 100644 index 0000000..77bbba0 --- /dev/null +++ b/gen/libsaio/disk.c @@ -0,0 +1,300 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Mach Operating System + * Copyright (c) 1990 Carnegie-Mellon University + * Copyright (c) 1989 Carnegie-Mellon University + * All rights reserved. The CMU software License Agreement specifies + * the terms and conditions for use and redistribution. + */ + +/* + * INTEL CORPORATION PROPRIETARY INFORMATION + * + * This software is supplied under the terms of a license agreement or + * nondisclosure agreement with Intel Corporation and may not be copied + * nor disclosed except in accordance with the terms of that agreement. + * + * Copyright 1988, 1989 Intel Corporation + */ + +/* + * Copyright 1993 NeXT Computer, Inc. + * All rights reserved. + */ + +#define DRIVER_PRIVATE + +#import "sys/types.h" +#import +#import +#import "libsaio.h" +#import "memory.h" + +static Biosread(int biosdev, int secno); +static read_label(char *name, int biosdev, daddr_t *boff, int partition); +void diskActivityHook(void); +extern void spinActivityIndicator(void); + +/* diskinfo unpacking */ +#define SPT(di) ((di)&0xff) +#define HEADS(di) ((((di)>>8)&0xff)+1) +#define SPC(di) (SPT(di)*HEADS(di)) +#define BPS 512 /* sector size of the device */ +#define N_CACHE_SECS (BIOS_LEN / BPS) + +#define DOS_BSIZE 512 +#define DISKLABEL 15 /* sector num of disk label */ + +char *devsw[] = { + "sd", + "hd", + "fd", + NULL +}; + +struct diskinfo { + int spt; /* sectors per track */ + int spc; /* sectors per cylinder */ +} diskinfo; + +char *b[NBUFS]; +daddr_t blknos[NBUFS]; +struct iob iob[NFILES]; +int label_secsize; +static int label_cached; + +// intbuf is the whole buffer, biosbuf is the current cached sector +static char * const intbuf = (char *)ptov(BIOS_ADDR); +char *biosbuf; + +void +devopen(name, io) + char * name; + struct iob * io; +{ + long di; + + di = get_diskinfo(io->biosdev); + + /* initialize disk parameters -- spt and spc */ + io->i_error = 0; + io->dirbuf_blkno = -1; + + diskinfo.spt = SPT(di); + diskinfo.spc = diskinfo.spt * HEADS(di); + if (read_label(name, io->biosdev, &io->i_boff, io->partition) < 0) + { + io->i_error = EIO; + } +} + +void devflush() +{ + Biosread(0,-1); +} + + +int devread(io) + struct iob *io; +{ + long sector; + int offset; + int dev; + + io->i_flgs |= F_RDDATA; + + /* assume the best */ + io->i_error = 0; + + dev = io->i_ino.i_dev; + + sector = io->i_bn * (label_secsize/DOS_BSIZE); + + for (offset = 0; offset < io->i_cc; offset += BPS) { + + io->i_error = Biosread(io->biosdev, sector); + if (io->i_error) { + return(-1); + } + + /* copy 1 sector from the internal buffer biosbuf into buf */ + bcopy(biosbuf, &io->i_ma[offset], BPS); + + sector++; + } + + io->i_flgs &= ~F_TYPEMASK; + return (io->i_cc); +} + +/* A haque: Biosread(0,-1) means flush the sector cache. + */ +static int +Biosread(int biosdev, int secno) +{ + static int xbiosdev, xcyl=-1, xhead, xsec, xnsecs; + + int rc; + int cyl, head, sec; + int spt, spc; + int tries = 0; + + if (biosdev == 0 && secno == -1) { + xcyl = -1; + label_cached = 0; + return 0; + } + spt = diskinfo.spt; + spc = diskinfo.spc; + + cyl = secno / spc; + head = (secno % spc) / spt; + sec = secno % spt; + + if (biosdev == xbiosdev && cyl == xcyl && head == xhead && + sec >= xsec && sec < (xsec + xnsecs)) + { // this sector is in intbuf cache + biosbuf = intbuf + (BPS * (sec-xsec)); + return 0; + } + + xcyl = cyl; + label_cached = 1; + xhead = head; + xsec = sec; + xbiosdev = biosdev; + xnsecs = ((sec + N_CACHE_SECS) > spt) ? (spt - sec) : N_CACHE_SECS; + biosbuf = intbuf; + + while ((rc = biosread(biosdev,cyl,head,sec, xnsecs)) && (++tries < 5)) + { +#ifndef SMALL + error(" biosread error 0x%x @ %d, C:%d H:%d S:%d\n", + rc, secno, cyl, head, sec); +#endif + sleep(1); // on disk errors, bleh! + } + diskActivityHook(); + return rc; +} + +// extern char name[]; + +#ifndef SMALL +static int +read_label( + char *name, + int biosdev, + daddr_t *boff, + int partition +) +{ + struct disk_label *dlp; + struct fdisk_part *fd; + struct disk_blk0 *blk0; + char *cp; + int n, rc; + int part_offset = 0; + static int cached_boff; + + if (label_cached) { + *boff = cached_boff; + return 0; + } + + // read sector 0 into the internal buffer "biosbuf" + if ( rc = Biosread(biosdev, 0) ) + return -1; + + // Check for a valid boot block. + blk0 = (struct disk_blk0 *)biosbuf; + if (blk0->signature == DISK_SIGNATURE) { + // Check to see if the disk has been partitioned with FDISK + // to allow DOS and ufs filesystems to exist on the same spindle. + fd = (struct fdisk_part *)blk0->parts; + for ( n = 0; n < FDISK_NPART; n++, fd++) + if (fd->systid == FDISK_NEXTNAME) + { + part_offset = fd->relsect; + break; + } + } + /* It's not an error if there is not a valid boot block. */ + + /* Read the NeXT disk label. + * Since we can't count on it fitting in the sector cache, + * we'll put it elsewhere. + */ + dlp = (struct disk_label *)malloc(sizeof(*dlp) + BPS); + for(n = 0, cp = (char *)dlp; + n < ((sizeof(*dlp) + BPS - 1) / BPS); + n++, cp += BPS) { + if (rc = Biosread(biosdev, DISKLABEL + part_offset + n)) + goto error; + bcopy(biosbuf, cp, BPS); + } + + byte_swap_disklabel_in(dlp); + + /* Check label */ + + if (dlp->dl_version != DL_V3) { + error("bad disk label magic\n"); + goto error; + } + + label_secsize = dlp->dl_secsize; + + if ((dlp->dl_part[partition].p_base) < 0) { + error("no such partition\n"); + goto error; + } + + *boff = cached_boff = dlp->dl_front + dlp->dl_part[partition].p_base; + + if (!strcmp(name,"$LBL")) strcpy(name, dlp->dl_bootfile); + + free((char *)dlp); + return 0; +error: + free((char *)dlp); + return -1; +} + +#endif SMALL + + +/* replace this function if you want to change + * the way disk activity is indicated to the user. + */ + +void +diskActivityHook(void) +{ + spinActivityIndicator(); +} + + + diff --git a/gen/libsaio/errorV.c b/gen/libsaio/errorV.c new file mode 100644 index 0000000..231c7ec --- /dev/null +++ b/gen/libsaio/errorV.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright 1993 NeXT, Inc. + * All rights reserved. + */ + +#import "libsa.h" +#import "saio_types.h" +#import "saio.h" +#import "libsaio.h" +#import "language.h" + +BOOL errors; + +int errorV(const char *format, va_list ap) +{ + char *val; + + val = 0; + errors = 1; + prf(format, ap, putchar, 0); + return 0; +} diff --git a/gen/libsaio/gets.c b/gen/libsaio/gets.c new file mode 100644 index 0000000..5fdc758 --- /dev/null +++ b/gen/libsaio/gets.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright 1993, NeXT Computer Inc. + * All rights reserved. + */ + +#import "libsaio.h" + +int gets(char *buf); + +/* + * return a string in buf iff typing is begun within timeout units + */ +int +Gets( + char *buf, + int timeout, + char *prompt, + char *message +) +{ + int ch = 0; + int next_second; + + printf("%s",prompt); + if (message) + printf("%s",message); + if (timeout) { +#if 0 + printf("["); + for (i = 0; i < timeout; i++) + putchar('-'); + printf("]\b\b"); +#endif + + for(next_second = time18() + 18; timeout; ) { + if (ch = readKeyboardStatus()) { + break; + } + if (time18() >= next_second) { + next_second += 18; + timeout--; +#if 0 + printf(" \b\b"); +#endif + } + } +#if 0 + putchar('\r'); + printf("%s",prompt); + for (i = 0; i < strlen(message) + orig_timeout + 4; i++) + putchar(' '); + putchar('\r'); + printf("%s",prompt); +#endif + + if (ch == 0) { + printf("\n"); + return 0; + } + } + return(gets(buf)); +} + +int +gets( + char *buf +) +{ + char *lp; + int c; + + lp = buf; + for (;;) { + c = getchar() & 0x7f; + if (c < ' ' && c != '\n' && c != '\b') c = 0; + if (c == 0x7f) c = '\b'; + + switch(c) { + case '\0': + continue; + case '\n': + *lp++ = '\0'; + putchar('\n'); + return 1; + case '\b': + if (lp > buf) { + lp--; + putchar('\b'); + putchar(' '); + putchar('\b'); + } + continue; + default: + *lp++ = c; + } + } +} diff --git a/gen/libsaio/localPrintf.c b/gen/libsaio/localPrintf.c new file mode 100644 index 0000000..b9b6ad8 --- /dev/null +++ b/gen/libsaio/localPrintf.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright 1993 NeXT Computer, Inc. + * All rights reserved. + */ + +#ifdef SAIO_INTERNAL_USER +#undef SAIO_INTERNAL_USER +#endif +#import "libsa.h" +#import "saio_types.h" +#import "saio.h" +#import "libsaio.h" + + +int localPrintf(const char *format, ...) +{ + va_list ap; + char *val; + + val = 0; + va_start(ap, format); + localVPrintf(format, ap); + va_end(ap); + return 0; +} + +int error(const char *format, ...) +{ + va_list ap; + va_start(ap, format); + errorV(format, ap); + va_end(ap); + return(0); +} diff --git a/gen/libsaio/localVPrintf.c b/gen/libsaio/localVPrintf.c new file mode 100644 index 0000000..e6ce692 --- /dev/null +++ b/gen/libsaio/localVPrintf.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright 1993 NeXT Computer, Inc. + * All rights reserved. + */ + +#import "libsa.h" +#import "saio_types.h" +#import "saio.h" +#import "libsaio.h" +#import "language.h" + + +int localVPrintf(const char *format, va_list ap) +{ + char *val; + + val = 0; + if (LanguageConfig) { + if (val = (char *)newStringForStringTableKey(LanguageConfig, + (char *)format)) { + format = val; + } + } + prf(format, ap, putchar, 0); + if (val) { + free(val); + } + return 0; +} diff --git a/gen/libsaio/printf.c b/gen/libsaio/printf.c new file mode 100644 index 0000000..f282f6e --- /dev/null +++ b/gen/libsaio/printf.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* Standalone I/O stubs. */ + +#import "libsa.h" +#import "saio_types.h" +#import "saio.h" +#import "libsaio.h" + +int printf(const char *format, ...) +{ + va_list ap; + va_start(ap, format); + prf(format, ap, putchar, 0); + va_end(ap); + return 0; +} + diff --git a/gen/libsaio/reallyPrint.c b/gen/libsaio/reallyPrint.c new file mode 100644 index 0000000..b47ad07 --- /dev/null +++ b/gen/libsaio/reallyPrint.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright 1993 NeXT, Inc. + * All rights reserved. + */ + +#import "libsaio.h" +#import "console.h" + +int +reallyPrint(const char *fmt, ...) +{ + va_list ap; + int tShow = showText; + + va_start(ap, fmt); + showText = 1; + prf(fmt, ap, putchar, 0); + va_end(ap); + showText = tShow; + return 0; +} + + diff --git a/gen/libsaio/stringTable.c b/gen/libsaio/stringTable.c new file mode 100644 index 0000000..66f10e9 --- /dev/null +++ b/gen/libsaio/stringTable.c @@ -0,0 +1,570 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 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. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * Copyright 1993 NeXT, Inc. + * All rights reserved. + */ + +#import "libsaio.h" +#import "kernBootStruct.h" +#import + +extern KERNBOOTSTRUCT *kernBootStruct; +extern char *Language; +extern char *LoadableFamilies; + +static void eatThru(char val, char **table_p); + +static inline int isspace(char c) +{ + return (c == ' ' || c == '\t'); +} + +/* + * Compare a string to a key with quoted characters + */ +static inline int +keyncmp(char *str, char *key, int n) +{ + int c; + while (n--) { + c = *key++; + if (c == '\\') { + switch(c = *key++) { + case 'n': + c = '\n'; + break; + case 'r': + c = '\r'; + break; + case 't': + c = '\t'; + break; + default: + break; + } + } else if (c == '\"') { + /* Premature end of key */ + return 1; + } + if (c != *str++) { + return 1; + } + } + return 0; +} + +static void eatThru(char val, char **table_p) +{ + register char *table = *table_p; + register BOOL found = NO; + + while (*table && !found) + { + if (*table == '\\') table += 2; + else + { + if (*table == val) found = YES; + table++; + } + } + *table_p = table; +} + +char * +newStringFromList( + char **list, + int *size +) +{ + char *begin = *list, *end; + char *newstr; + int newsize = *size; + + while (*begin && newsize && isspace(*begin)) { + begin++; + newsize--; + } + end = begin; + while (*end && newsize && !isspace(*end)) { + end++; + newsize--; + } + if (begin == end) + return 0; + newstr = malloc(end - begin + 1); + strncpy(newstr, begin, end - begin); + *list = end; + *size = newsize; + return newstr; +} + +/* + * compress == compress escaped characters to one character + */ +int stringLength(char *table, int compress) +{ + int ret = 0; + + while (*table) + { + if (*table == '\\') + { + table += 2; + ret += 1 + (compress ? 0 : 1); + } + else + { + if (*table == '\"') return ret; + ret++; + table++; + } + } + return ret; +} + + +// looks in table for strings of format << "key" = "value"; >> +// or << "key"; >> +BOOL getValueForStringTableKey(char *table, char *key, char **val, int *size) +{ + int keyLength; + char *tableKey; + + do + { + eatThru('\"',&table); + tableKey = table; + keyLength = strlen(key); + if (keyLength && + (stringLength(table,1) == keyLength) && + (keyncmp(key, table, keyLength) == 0)) + { + int c; + + /* found the key; now look for either + * '=' or ';' + */ + while (c = *table) { + ++table; + if (c == '\\') { + ++table; + continue; + } else if (c == '=' || c == ';') { + break; + } + } + if (c == ';') { + table = tableKey; + } else { + eatThru('\"',&table); + } + *val = table; + *size = stringLength(table,0); + return YES; + } + + eatThru(';',&table); + + } while (*table); + + return NO; +} + + +/* + * Returns a new malloc'ed string if one is found + * in the string table matching 'key'. Also translates + * \n escapes in the string. + */ +char *newStringForStringTableKey( + char *table, + char *key +) +{ + char *val, *newstr, *p; + int size; + + if (getValueForStringTableKey(table, key, &val, &size)) { + newstr = malloc(size+1); + for (p = newstr; size; size--, p++, val++) { + if ((*p = *val) == '\\') { + switch (*++val) { + case 'r': + *p = '\r'; + break; + case 'n': + *p = '\n'; + break; + case 't': + *p = '\t'; + break; + default: + *p = *val; + break; + } + size--; + } + } + *p = '\0'; + return newstr; + } else { + return 0; + } +} + +char * +newStringForKey(char *key) +{ + char *val, *newstr; + int size; + + if (getValueForKey(key, &val, &size) && size) { + newstr = malloc(size + 1); + strncpy(newstr, val, size); + return newstr; + } else { + return 0; + } +} + +/* parse a command line + * in the form: [ ...] [